| @@ -248,7 +248,7 @@ unit glBitmap; | |||||
| // PNG ///////////////////////////////////////////////////////////////////////////////////////////// | // PNG ///////////////////////////////////////////////////////////////////////////////////////////// | ||||
| // activate to enable png support with the unit pngimage -> http://pngdelphi.sourceforge.net/ | // activate to enable png support with the unit pngimage -> http://pngdelphi.sourceforge.net/ | ||||
| // if you enable pngimage the libPNG will be ignored | // if you enable pngimage the libPNG will be ignored | ||||
| {.$DEFINE GLB_PNGIMAGE} | |||||
| {$DEFINE GLB_PNGIMAGE} | |||||
| // activate to use the libPNG -> http://www.libpng.org/ | // activate to use the libPNG -> http://www.libpng.org/ | ||||
| // You will need an aditional header -> http://www.opengl24.de/index.php?cat=header&file=libpng | // You will need an aditional header -> http://www.opengl24.de/index.php?cat=header&file=libpng | ||||
| @@ -260,7 +260,7 @@ unit glBitmap; | |||||
| // activate to use the libJPEG -> http://www.ijg.org/ | // activate to use the libJPEG -> http://www.ijg.org/ | ||||
| // You will need an aditional header -> http://www.opengl24.de/index.php?cat=header&file=libjpeg | // You will need an aditional header -> http://www.opengl24.de/index.php?cat=header&file=libjpeg | ||||
| {$DEFINE GLB_LIB_JPEG} | |||||
| {.$DEFINE GLB_LIB_JPEG} | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -1660,7 +1660,7 @@ var | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| constructor EglBitmapUnsupportedFormat.Create(const aFormat: TglBitmapFormat); | constructor EglBitmapUnsupportedFormat.Create(const aFormat: TglBitmapFormat); | ||||
| begin | begin | ||||
| inherited Create(GetEnumName(TypeInfo(TglBitmapFormat), Integer(aFormat))); | |||||
| inherited Create('unsupported format: ' + GetEnumName(TypeInfo(TglBitmapFormat), Integer(aFormat))); | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -5625,42 +5625,44 @@ function TglBitmap.LoadPNG(const aStream: TStream): Boolean; | |||||
| var | var | ||||
| StreamPos: Int64; | StreamPos: Int64; | ||||
| Png: TPNGObject; | Png: TPNGObject; | ||||
| Header: Array[0..7] of Byte; | |||||
| Header: String[8]; | |||||
| Row, Col, PixSize, LineSize: Integer; | Row, Col, PixSize, LineSize: Integer; | ||||
| NewImage, pSource, pDest, pAlpha: pByte; | NewImage, pSource, pDest, pAlpha: pByte; | ||||
| Format: TglBitmapInternalFormat; | |||||
| PngFormat: TglBitmapFormat; | |||||
| FormatDesc: TFormatDescriptor; | |||||
| const | const | ||||
| PngHeader: Array[0..7] of Byte = (#137, #80, #78, #71, #13, #10, #26, #10); | |||||
| PngHeader: String[8] = #137#80#78#71#13#10#26#10; | |||||
| begin | begin | ||||
| result := false; | result := false; | ||||
| StreamPos := Stream.Position; | |||||
| Stream.Read(Header[0], SizeOf(Header)); | |||||
| Stream.Position := StreamPos; | |||||
| StreamPos := aStream.Position; | |||||
| aStream.Read(Header[0], SizeOf(Header)); | |||||
| aStream.Position := StreamPos; | |||||
| {Test if the header matches} | {Test if the header matches} | ||||
| if Header = PngHeader then begin | if Header = PngHeader then begin | ||||
| Png := TPNGObject.Create; | Png := TPNGObject.Create; | ||||
| try | try | ||||
| Png.LoadFromStream(Stream); | |||||
| Png.LoadFromStream(aStream); | |||||
| case Png.Header.ColorType of | case Png.Header.ColorType of | ||||
| COLOR_GRAYSCALE: | COLOR_GRAYSCALE: | ||||
| Format := ifLuminance; | |||||
| PngFormat := tfLuminance8; | |||||
| COLOR_GRAYSCALEALPHA: | COLOR_GRAYSCALEALPHA: | ||||
| Format := ifLuminanceAlpha; | |||||
| PngFormat := tfLuminance8Alpha8; | |||||
| COLOR_RGB: | COLOR_RGB: | ||||
| Format := ifBGR8; | |||||
| PngFormat := tfBGR8; | |||||
| COLOR_RGBALPHA: | COLOR_RGBALPHA: | ||||
| Format := ifBGRA8; | |||||
| PngFormat := tfBGRA8; | |||||
| else | else | ||||
| raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.'); | raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.'); | ||||
| end; | end; | ||||
| PixSize := Trunc(FormatGetSize(Format)); | |||||
| LineSize := Integer(Png.Header.Width) * PixSize; | |||||
| FormatDesc := TFormatDescriptor.Get(PngFormat); | |||||
| PixSize := Round(FormatDesc.PixelSize); | |||||
| LineSize := FormatDesc.GetSize(Png.Header.Width, 1); | |||||
| GetMem(NewImage, LineSize * Integer(Png.Header.Height)); | GetMem(NewImage, LineSize * Integer(Png.Header.Height)); | ||||
| try | try | ||||
| @@ -5697,7 +5699,7 @@ begin | |||||
| raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.'); | raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.'); | ||||
| end; | end; | ||||
| SetDataPointer(NewImage, Format, Png.Header.Width, Png.Header.Height); | |||||
| SetDataPointer(NewImage, PngFormat, Png.Header.Width, Png.Header.Height); | |||||
| result := true; | result := true; | ||||
| except | except | ||||
| @@ -5812,32 +5814,32 @@ var | |||||
| pTemp: pByte; | pTemp: pByte; | ||||
| Temp: Byte; | Temp: Byte; | ||||
| begin | begin | ||||
| if not (ftPNG in FormatGetSupportedFiles (InternalFormat)) then | |||||
| raise EglBitmapUnsupportedInternalFormat.Create('SavePng - ' + UNSUPPORTED_INTERNAL_FORMAT); | |||||
| if not (ftPNG in FormatGetSupportedFiles (Format)) then | |||||
| raise EglBitmapUnsupportedFormat.Create(Format); | |||||
| case FInternalFormat of | |||||
| ifAlpha, ifLuminance, ifDepth8: begin | |||||
| case Format of | |||||
| tfAlpha8, tfLuminance8: begin | |||||
| ColorType := COLOR_GRAYSCALE; | ColorType := COLOR_GRAYSCALE; | ||||
| PixSize := 1; | |||||
| Alpha := false; | |||||
| PixSize := 1; | |||||
| Alpha := false; | |||||
| end; | end; | ||||
| ifLuminanceAlpha: begin | |||||
| tfLuminance8Alpha8: begin | |||||
| ColorType := COLOR_GRAYSCALEALPHA; | ColorType := COLOR_GRAYSCALEALPHA; | ||||
| PixSize := 1; | |||||
| Alpha := true; | |||||
| PixSize := 1; | |||||
| Alpha := true; | |||||
| end; | end; | ||||
| ifBGR8, ifRGB8: begin | |||||
| tfBGR8, tfRGB8: begin | |||||
| ColorType := COLOR_RGB; | ColorType := COLOR_RGB; | ||||
| PixSize := 3; | |||||
| Alpha := false; | |||||
| PixSize := 3; | |||||
| Alpha := false; | |||||
| end; | end; | ||||
| ifBGRA8, ifRGBA8: begin | |||||
| tfBGRA8, tfRGBA8: begin | |||||
| ColorType := COLOR_RGBALPHA; | ColorType := COLOR_RGBALPHA; | ||||
| PixSize := 3; | |||||
| Alpha := true | |||||
| PixSize := 3; | |||||
| Alpha := true | |||||
| end; | end; | ||||
| else | else | ||||
| raise EglBitmapUnsupportedInternalFormat.Create('SavePng - ' + UNSUPPORTED_INTERNAL_FORMAT); | |||||
| raise EglBitmapUnsupportedFormat.Create(Format); | |||||
| end; | end; | ||||
| Png := TPNGObject.CreateBlank(ColorType, 8, Width, Height); | Png := TPNGObject.CreateBlank(ColorType, 8, Width, Height); | ||||
| @@ -5857,7 +5859,7 @@ begin | |||||
| end; | end; | ||||
| // convert RGB line to BGR | // convert RGB line to BGR | ||||
| if InternalFormat in [ifRGB8, ifRGBA8] then begin | |||||
| if Format in [tfRGB8, tfRGBA8] then begin | |||||
| pTemp := png.ScanLine[Y]; | pTemp := png.ScanLine[Y]; | ||||
| for X := 0 to Width -1 do begin | for X := 0 to Width -1 do begin | ||||
| Temp := pByteArray(pTemp)^[0]; | Temp := pByteArray(pTemp)^[0]; | ||||
| @@ -5870,7 +5872,7 @@ begin | |||||
| // Save to Stream | // Save to Stream | ||||
| Png.CompressionLevel := 6; | Png.CompressionLevel := 6; | ||||
| Png.SaveToStream(Stream); | |||||
| Png.SaveToStream(aStream); | |||||
| finally | finally | ||||
| FreeAndNil(Png); | FreeAndNil(Png); | ||||
| end; | end; | ||||