|
|
@@ -248,7 +248,7 @@ unit glBitmap; |
|
|
|
// PNG ///////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
// activate to enable png support with the unit pngimage -> http://pngdelphi.sourceforge.net/ |
|
|
|
// if you enable pngimage the libPNG will be ignored |
|
|
|
{.$DEFINE GLB_PNGIMAGE} |
|
|
|
{$DEFINE GLB_PNGIMAGE} |
|
|
|
|
|
|
|
// 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 |
|
|
@@ -260,7 +260,7 @@ unit glBitmap; |
|
|
|
|
|
|
|
// 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 |
|
|
|
{$DEFINE GLB_LIB_JPEG} |
|
|
|
{.$DEFINE GLB_LIB_JPEG} |
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
@@ -1660,7 +1660,7 @@ var |
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
constructor EglBitmapUnsupportedFormat.Create(const aFormat: TglBitmapFormat); |
|
|
|
begin |
|
|
|
inherited Create(GetEnumName(TypeInfo(TglBitmapFormat), Integer(aFormat))); |
|
|
|
inherited Create('unsupported format: ' + GetEnumName(TypeInfo(TglBitmapFormat), Integer(aFormat))); |
|
|
|
end; |
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
@@ -5625,42 +5625,44 @@ function TglBitmap.LoadPNG(const aStream: TStream): Boolean; |
|
|
|
var |
|
|
|
StreamPos: Int64; |
|
|
|
Png: TPNGObject; |
|
|
|
Header: Array[0..7] of Byte; |
|
|
|
Header: String[8]; |
|
|
|
Row, Col, PixSize, LineSize: Integer; |
|
|
|
NewImage, pSource, pDest, pAlpha: pByte; |
|
|
|
Format: TglBitmapInternalFormat; |
|
|
|
PngFormat: TglBitmapFormat; |
|
|
|
FormatDesc: TFormatDescriptor; |
|
|
|
|
|
|
|
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 |
|
|
|
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} |
|
|
|
if Header = PngHeader then begin |
|
|
|
Png := TPNGObject.Create; |
|
|
|
try |
|
|
|
Png.LoadFromStream(Stream); |
|
|
|
Png.LoadFromStream(aStream); |
|
|
|
|
|
|
|
case Png.Header.ColorType of |
|
|
|
COLOR_GRAYSCALE: |
|
|
|
Format := ifLuminance; |
|
|
|
PngFormat := tfLuminance8; |
|
|
|
COLOR_GRAYSCALEALPHA: |
|
|
|
Format := ifLuminanceAlpha; |
|
|
|
PngFormat := tfLuminance8Alpha8; |
|
|
|
COLOR_RGB: |
|
|
|
Format := ifBGR8; |
|
|
|
PngFormat := tfBGR8; |
|
|
|
COLOR_RGBALPHA: |
|
|
|
Format := ifBGRA8; |
|
|
|
PngFormat := tfBGRA8; |
|
|
|
else |
|
|
|
raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.'); |
|
|
|
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)); |
|
|
|
try |
|
|
@@ -5697,7 +5699,7 @@ begin |
|
|
|
raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.'); |
|
|
|
end; |
|
|
|
|
|
|
|
SetDataPointer(NewImage, Format, Png.Header.Width, Png.Header.Height); |
|
|
|
SetDataPointer(NewImage, PngFormat, Png.Header.Width, Png.Header.Height); |
|
|
|
|
|
|
|
result := true; |
|
|
|
except |
|
|
@@ -5812,32 +5814,32 @@ var |
|
|
|
pTemp: pByte; |
|
|
|
Temp: Byte; |
|
|
|
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; |
|
|
|
PixSize := 1; |
|
|
|
Alpha := false; |
|
|
|
PixSize := 1; |
|
|
|
Alpha := false; |
|
|
|
end; |
|
|
|
ifLuminanceAlpha: begin |
|
|
|
tfLuminance8Alpha8: begin |
|
|
|
ColorType := COLOR_GRAYSCALEALPHA; |
|
|
|
PixSize := 1; |
|
|
|
Alpha := true; |
|
|
|
PixSize := 1; |
|
|
|
Alpha := true; |
|
|
|
end; |
|
|
|
ifBGR8, ifRGB8: begin |
|
|
|
tfBGR8, tfRGB8: begin |
|
|
|
ColorType := COLOR_RGB; |
|
|
|
PixSize := 3; |
|
|
|
Alpha := false; |
|
|
|
PixSize := 3; |
|
|
|
Alpha := false; |
|
|
|
end; |
|
|
|
ifBGRA8, ifRGBA8: begin |
|
|
|
tfBGRA8, tfRGBA8: begin |
|
|
|
ColorType := COLOR_RGBALPHA; |
|
|
|
PixSize := 3; |
|
|
|
Alpha := true |
|
|
|
PixSize := 3; |
|
|
|
Alpha := true |
|
|
|
end; |
|
|
|
else |
|
|
|
raise EglBitmapUnsupportedInternalFormat.Create('SavePng - ' + UNSUPPORTED_INTERNAL_FORMAT); |
|
|
|
raise EglBitmapUnsupportedFormat.Create(Format); |
|
|
|
end; |
|
|
|
|
|
|
|
Png := TPNGObject.CreateBlank(ColorType, 8, Width, Height); |
|
|
@@ -5857,7 +5859,7 @@ begin |
|
|
|
end; |
|
|
|
|
|
|
|
// convert RGB line to BGR |
|
|
|
if InternalFormat in [ifRGB8, ifRGBA8] then begin |
|
|
|
if Format in [tfRGB8, tfRGBA8] then begin |
|
|
|
pTemp := png.ScanLine[Y]; |
|
|
|
for X := 0 to Width -1 do begin |
|
|
|
Temp := pByteArray(pTemp)^[0]; |
|
|
@@ -5870,7 +5872,7 @@ begin |
|
|
|
|
|
|
|
// Save to Stream |
|
|
|
Png.CompressionLevel := 6; |
|
|
|
Png.SaveToStream(Stream); |
|
|
|
Png.SaveToStream(aStream); |
|
|
|
finally |
|
|
|
FreeAndNil(Png); |
|
|
|
end; |
|
|
|