// If you enable SDL_image all other libraries will be ignored!
{.$DEFINE GLB_SDL_IMAGE}
-// activate to enable png support with the unit pngimage. You can download it from http://pngdelphi.sourceforge.net/
+// 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}
-// 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
-{$DEFINE GLB_LIB_PNG}
+// 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
+{.$DEFINE GLB_LIB_PNG}
+// JPEG ////////////////////////////////////////////////////////////////////////////////////////////
// if you enable delphi jpegs the libJPEG will be ignored
{.$DEFINE GLB_DELPHI_JPEG}
-// activateto 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}
+// 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}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
result := result + [ftPNG];
{$ENDIF}
-(* TODO
{$IFDEF GLB_SUPPORT_JPEG_WRITE}
- if Format in [
- tfAlpha4, tfAlpha8, tfAlpha12, tfAlpha16,
- tfLuminance4, tfLuminance8, tfLuminance12, tfLuminance16,
- tfR3G3B2, tfRGB4, tfRGB5, tfRGB8, tfRGB10, tfRGB12, tfRGB16,
- tfDepth16, tfDepth24, tfDepth32]
- then
+ if aFormat in [tfAlpha8, tfLuminance8, tfRGB8, tfBGR8] then
result := result + [ftJPEG];
{$ENDIF}
- *)
end;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
try
// signature
StreamPos := aStream.Position;
- aStream.Read(signature, 8);
+ aStream.Read(signature{%H-}, 8);
aStream.Position := StreamPos;
if png_check_sig(@signature, 8) <> 0 then begin
DestBuffer: array [1..4096] of byte;
end;
+procedure glBitmap_libJPEG_error_exit(cinfo: j_common_ptr); cdecl;
+begin
+ //DUMMY
+end;
+
+
+procedure glBitmap_libJPEG_output_message(cinfo: j_common_ptr); cdecl;
+begin
+ //DUMMY
+end;
+
+
+procedure glBitmap_libJPEG_init_source(cinfo: j_decompress_ptr); cdecl;
+begin
+ //DUMMY
+end;
+
+procedure glBitmap_libJPEG_term_source(cinfo: j_decompress_ptr); cdecl;
+begin
+ //DUMMY
+end;
+
+
+procedure glBitmap_libJPEG_init_destination(cinfo: j_compress_ptr); cdecl;
+begin
+ //DUMMY
+end;
+
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function glBitmap_libJPEG_fill_input_buffer(cinfo: j_decompress_ptr): boolean; cdecl;
var
jpeg: jpeg_decompress_struct;
jpeg_err: jpeg_error_mgr;
- IntFormat: TglBitmapInternalFormat;
+ IntFormat: TglBitmapFormat;
pImage: pByte;
TempHeight, TempWidth: Integer;
pTemp: pByte;
Row: Integer;
+
+ FormatDesc: TFormatDescriptor;
begin
result := false;
try
// reading first two bytes to test file and set cursor back to begin
- StreamPos := Stream.Position;
- Stream.Read(Temp[0], 2);
- Stream.Position := StreamPos;
+ StreamPos := aStream.Position;
+ aStream.Read({%H-}Temp[0], 2);
+ aStream.Position := StreamPos;
// if Bitmap then read file.
if ((Temp[0] = $FF) and (Temp[1] = $D8)) then begin
- FillChar(jpeg, SizeOf(jpeg_decompress_struct), $00);
- FillChar(jpeg_err, SizeOf(jpeg_error_mgr), $00);
+ FillChar(jpeg{%H-}, SizeOf(jpeg_decompress_struct), $00);
+ FillChar(jpeg_err{%H-}, SizeOf(jpeg_error_mgr), $00);
// error managment
jpeg.err := jpeg_std_error(@jpeg_err);
- jpeg_err.error_exit := glBitmap_libJPEG_error_exit;
+ jpeg_err.error_exit := glBitmap_libJPEG_error_exit;
jpeg_err.output_message := glBitmap_libJPEG_output_message;
// decompression struct
pub.bytes_in_buffer := 0; // forces fill_input_buffer on first read
pub.next_input_byte := nil; // until buffer loaded
- SrcStream := Stream;
+ SrcStream := aStream;
end;
// set global decoding state
JCS_GRAYSCALE:
begin
jpeg.out_color_space := JCS_GRAYSCALE;
- IntFormat := ifLuminance;
+ IntFormat := tfLuminance8;
end;
else
jpeg.out_color_space := JCS_RGB;
- IntFormat := ifRGB8;
+ IntFormat := tfRGB8;
end;
// reading image
TempHeight := jpeg.output_height;
TempWidth := jpeg.output_width;
+ FormatDesc := TFormatDescriptor.Get(IntFormat);
+
// creating new image
- GetMem(pImage, FormatGetImageSize(glBitmapPosition(TempWidth, TempHeight), IntFormat));
+ GetMem(pImage, FormatDesc.GetSize(TempWidth, TempHeight));
try
pTemp := pImage;
for Row := 0 to TempHeight -1 do begin
jpeg_read_scanlines(@jpeg, @pTemp, 1);
- Inc(pTemp, Trunc(FormatGetSize(IntFormat) * TempWidth));
+ Inc(pTemp, FormatDesc.GetSize(TempWidth, 1));
end;
// finish decompression
{$ENDIF}
{$IFDEF GLB_SUPPORT_JPEG_WRITE}
-{$IF DEFEFINED(GLB_LIB_JPEG)}
+{$IF DEFINED(GLB_LIB_JPEG)}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap.SaveJPEG(Stream: TStream);
+procedure TglBitmap.SaveJPEG(const aStream: TStream);
var
jpeg: jpeg_compress_struct;
jpeg_err: jpeg_error_mgr;
begin
if not (ftJPEG in FormatGetSupportedFiles(Format)) then
- raise EglBitmapUnsupportedInternalFormat.Create('SaveJpg - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormat.Create(Format);
if not init_libJPEG then
raise Exception.Create('SaveJPG - unable to initialize libJPEG.');
try
- FillChar(jpeg, SizeOf(jpeg_compress_struct), $00);
- FillChar(jpeg_err, SizeOf(jpeg_error_mgr), $00);
+ FillChar(jpeg{%H-}, SizeOf(jpeg_compress_struct), $00);
+ FillChar(jpeg_err{%H-}, SizeOf(jpeg_error_mgr), $00);
// error managment
jpeg.err := jpeg_std_error(@jpeg_err);
- jpeg_err.error_exit := glBitmap_libJPEG_error_exit;
+ jpeg_err.error_exit := glBitmap_libJPEG_error_exit;
jpeg_err.output_message := glBitmap_libJPEG_output_message;
// compression struct
pub.next_output_byte := @DestBuffer[1];
pub.free_in_buffer := Length(DestBuffer);
- DestStream := Stream;
+ DestStream := aStream;
end;
// very important state
jpeg.global_state := CSTATE_START;
jpeg.image_width := Width;
jpeg.image_height := Height;
- case InternalFormat of
- ifAlpha, ifLuminance, ifDepth8: begin
+ case Format of
+ tfAlpha8, tfLuminance8: begin
jpeg.input_components := 1;
- jpeg.in_color_space := JCS_GRAYSCALE;
+ jpeg.in_color_space := JCS_GRAYSCALE;
end;
- ifRGB8, ifBGR8: begin
+ tfRGB8, tfBGR8: begin
jpeg.input_components := 3;
- jpeg.in_color_space := JCS_RGB;
+ jpeg.in_color_space := JCS_RGB;
end;
end;
jpeg_start_compress(@jpeg, true);
pTemp := Data;
- if InternalFormat = ifBGR8 then
+ if Format = tfBGR8 then
GetMem(pTemp2, fRowSize)
else
pTemp2 := pTemp;
try
for Row := 0 to jpeg.image_height -1 do begin
// prepare row
- if InternalFormat = ifBGR8 then
+ if Format = tfBGR8 then
CopyRow(pTemp2, pTemp)
else
pTemp2 := pTemp;
end;
finally
// free memory
- if InternalFormat = ifBGR8 then
+ if Format = tfBGR8 then
FreeMem(pTemp2);
end;
jpeg_finish_compress(@jpeg);