projects
/
LazOpenGLCore.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
3abbe3a
)
* added pngimage Support
author
Bergmann89
<bergmann89@muo-game.de>
Sat, 16 Nov 2013 21:42:31 +0000
(22:42 +0100)
committer
Bergmann89
<bergmann89@muo-game.de>
Sat, 16 Nov 2013 21:42:31 +0000
(22:42 +0100)
glBitmap.pas
patch
|
blob
|
history
diff --git
a/glBitmap.pas
b/glBitmap.pas
index
32ee575
..
f745956
100644
(file)
--- a/
glBitmap.pas
+++ b/
glBitmap.pas
@@
-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
// 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 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
// 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
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor EglBitmapUnsupportedFormat.Create(const aFormat: TglBitmapFormat);
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
StreamPos: Int64;
Png: TPNGObject;
var
StreamPos: Int64;
Png: TPNGObject;
- Header:
Array[0..7] of Byte
;
+ Header:
String[8]
;
Row, Col, PixSize, LineSize: Integer;
NewImage, pSource, pDest, pAlpha: pByte;
Row, Col, PixSize, LineSize: Integer;
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
result := false;
begin
result := false;
- StreamPos := Stream.Position;
- Stream.Read(Header[0], SizeOf(Header));
- Stream.Position := StreamPos;
+ StreamPos :=
a
Stream.Position;
+
a
Stream.Read(Header[0], SizeOf(Header));
+
a
Stream.Position := StreamPos;
{Test if the header matches}
if Header = PngHeader then begin
Png := TPNGObject.Create;
try
{Test if the header matches}
if Header = PngHeader then begin
Png := TPNGObject.Create;
try
- Png.LoadFromStream(Stream);
+ Png.LoadFromStream(
a
Stream);
case Png.Header.ColorType of
COLOR_GRAYSCALE:
case Png.Header.ColorType of
COLOR_GRAYSCALE:
-
Format := ifLuminance
;
+
PngFormat := tfLuminance8
;
COLOR_GRAYSCALEALPHA:
COLOR_GRAYSCALEALPHA:
-
Format := ifLuminanceAlpha
;
+
PngFormat := tfLuminance8Alpha8
;
COLOR_RGB:
COLOR_RGB:
-
Format := i
fBGR8;
+
PngFormat := t
fBGR8;
COLOR_RGBALPHA:
COLOR_RGBALPHA:
-
Format := i
fBGRA8;
+
PngFormat := t
fBGRA8;
else
raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.');
end;
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
GetMem(NewImage, LineSize * Integer(Png.Header.Height));
try
@@
-5697,7
+5699,7
@@
begin
raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.');
end;
raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.');
end;
- SetDataPointer(NewImage, Format, Png.Header.Width, Png.Header.Height);
+ SetDataPointer(NewImage,
Png
Format, Png.Header.Width, Png.Header.Height);
result := true;
except
result := true;
except
@@
-5812,32
+5814,32
@@
var
pTemp: pByte;
Temp: Byte;
begin
pTemp: pByte;
Temp: Byte;
begin
- if not (ftPNG in FormatGetSupportedFiles (
Internal
Format)) then
- raise EglBitmapUnsupported
InternalFormat.Create('SavePng - ' + UNSUPPORTED_INTERNAL_FORMAT
);
+ if not (ftPNG in FormatGetSupportedFiles (Format)) then
+ raise EglBitmapUnsupported
Format.Create(Format
);
- case F
InternalF
ormat of
-
ifAlpha, ifLuminance, ifDepth
8: begin
+ case Format of
+
tfAlpha8, tfLuminance
8: 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, i
fRGB8: begin
+
tfBGR8, t
fRGB8: begin
ColorType := COLOR_RGB;
ColorType := COLOR_RGB;
- PixSize := 3;
- Alpha := false;
+ PixSize
:= 3;
+ Alpha
:= false;
end;
end;
-
ifBGRA8, i
fRGBA8: begin
+
tfBGRA8, t
fRGBA8: begin
ColorType := COLOR_RGBALPHA;
ColorType := COLOR_RGBALPHA;
- PixSize := 3;
- Alpha := true
+ PixSize
:= 3;
+ Alpha
:= true
end;
else
end;
else
- raise EglBitmapUnsupported
InternalFormat.Create('SavePng - ' + UNSUPPORTED_INTERNAL_FORMAT
);
+ raise EglBitmapUnsupported
Format.Create(Format
);
end;
Png := TPNGObject.CreateBlank(ColorType, 8, Width, Height);
end;
Png := TPNGObject.CreateBlank(ColorType, 8, Width, Height);
@@
-5857,7
+5859,7
@@
begin
end;
// convert RGB line to BGR
end;
// convert RGB line to BGR
- if
InternalFormat in [ifRGB8, i
fRGBA8] then begin
+ if
Format in [tfRGB8, t
fRGBA8] then begin
pTemp := png.ScanLine[Y];
for X := 0 to Width -1 do begin
Temp := pByteArray(pTemp)^[0];
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;
// Save to Stream
Png.CompressionLevel := 6;
- Png.SaveToStream(Stream);
+ Png.SaveToStream(
a
Stream);
finally
FreeAndNil(Png);
end;
finally
FreeAndNil(Png);
end;