// 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
// 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}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor EglBitmapUnsupportedFormat.Create(const aFormat: TglBitmapFormat);
begin
- inherited Create(GetEnumName(TypeInfo(TglBitmapFormat), Integer(aFormat)));
+ inherited Create('unsupported format: ' + GetEnumName(TypeInfo(TglBitmapFormat), Integer(aFormat)));
end;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
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
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);
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];
// Save to Stream
Png.CompressionLevel := 6;
- Png.SaveToStream(Stream);
+ Png.SaveToStream(aStream);
finally
FreeAndNil(Png);
end;