--- a/hedgewars/uMisc.pas Wed Dec 17 23:01:43 2014 +0100
+++ b/hedgewars/uMisc.pas Wed Dec 17 23:41:10 2014 +0100
@@ -46,7 +46,6 @@
filename: shortstring;
width, height: LongInt;
size: QWord;
- alpha: boolean;
end;
var conversionFormat : PSDL_PixelFormat;
@@ -70,20 +69,8 @@
info_ptr: ^png_info;
f: File;
image: PScreenshot;
- bpp: Integer; // bytes per pixel
- ctype: Integer; // png color type
begin
image:= PScreenshot(screenshot);
-if image^.alpha then
- begin
- bpp:= 4;
- ctype:= PNG_COLOR_TYPE_RGBA;
- end
-else
- begin
- bpp:= 3;
- ctype:= PNG_COLOR_TYPE_RGB;
- end;
png_ptr := png_create_write_struct(png_get_libpng_ver(nil), nil, nil, nil);
if png_ptr = nil then
@@ -110,12 +97,12 @@
png_init_pascal_io(png_ptr,@f);
png_set_IHDR(png_ptr, info_ptr, image^.width, image^.height,
8, // bit depth
- ctype, PNG_INTERLACE_NONE,
+ PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr, info_ptr);
// glReadPixels and libpng number rows in different order
for i:= image^.height-1 downto 0 do
- png_write_row(png_ptr, image^.buffer + i*bpp*image^.width);
+ png_write_row(png_ptr, image^.buffer + i*4*image^.width);
png_write_end(png_ptr, info_ptr);
Close(f);
end;
@@ -143,7 +130,7 @@
0, 0, 0, 0, // width
0, 0, 0, 0, // height
1, 0, // color planes
- 24, 0, // bit depth
+ 32, 0, // bit depth
0, 0, 0, 0, // compression method (uncompressed)
0, 0, 0, 0, // image size
96, 0, 0, 0, // horizontal resolution
@@ -176,9 +163,6 @@
head[$24]:= (size shr 16) and $ff;
head[$25]:= (size shr 24) and $ff;
-if image^.alpha then
- head[$1C]:= 32;
-
{$IOCHECKS OFF}
Assign(f, image^.filename);
Rewrite(f, 1);
@@ -204,8 +188,8 @@
{$IFDEF USE_VIDEO_RECORDING}
// make image k times smaller (useful for saving thumbnails)
-procedure ReduceImage(img: PByte; width, height, k: LongInt; bpp: Integer);
- var i, j, i0, j0, w, h, r, g, b, off, ksqr: LongInt;
+procedure ReduceImage(img: PByte; width, height, k: LongInt);
+var i, j, i0, j0, w, h, r, g, b: LongInt;
begin
w:= width div k;
h:= height div k;
@@ -213,7 +197,6 @@
// rescale inplace
if k <> 1 then
begin
- ksqr:= k*k;
for i:= 0 to h-1 do
for j:= 0 to w-1 do
begin
@@ -223,21 +206,14 @@
for i0:= 0 to k-1 do
for j0:= 0 to k-1 do
begin
- off:= bpp*(width*(i*k+i0) + j*k+j0);
- inc(r, img[off]); inc(off);
- inc(g, img[off]); inc(off);
- inc(b, img[off]);
+ inc(r, img[4*(width*(i*k+i0) + j*k+j0)+0]);
+ inc(g, img[4*(width*(i*k+i0) + j*k+j0)+1]);
+ inc(b, img[4*(width*(i*k+i0) + j*k+j0)+2]);
end;
- off:= bpp*(w*i + j);
- img[off]:= r div (ksqr); inc(off);
- img[off]:= g div (ksqr); inc(off);
- img[off]:= b div (ksqr);
- // if there's an alpha channel set opacity to max
- if bpp > 3 then
- begin
- inc(off);
- img[off]:= 255;
- end;
+ img[4*(w*i + j)+0]:= r div (k*k);
+ img[4*(w*i + j)+1]:= g div (k*k);
+ img[4*(w*i + j)+2]:= b div (k*k);
+ img[4*(w*i + j)+3]:= 255;
end;
end;
end;
@@ -252,33 +228,18 @@
format: GLenum;
ext: string[4];
x,y: LongWord;
- hasA: boolean;
- bpp: Integer;
begin
-hasA:= (dump > 0);
-
-if hasA then
- bpp:= 4
-else
- bpp:= 3;
-
{$IFDEF PNG_SCREENSHOTS}
-if hasA then
- format:= GL_RGBA
-else
- format:= GL_RGB;
+format:= GL_RGBA;
ext:= '.png';
{$ELSE}
-if hasA then
- format:= GL_BGRA
-else
- format:= GL_BGR;
+format:= GL_BGRA;
ext:= '.bmp';
{$ENDIF}
if dump > 0 then
- size:= LAND_WIDTH*LAND_HEIGHT*bpp
-else size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * bpp;
+ size:= LAND_WIDTH*LAND_HEIGHT*4
+else size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * 4;
p:= GetMem(size); // will be freed in SaveScreenshot()
// memory could not be allocated
@@ -316,7 +277,7 @@
begin
glReadPixels(0, 0, cScreenWidth, cScreenHeight, format, GL_UNSIGNED_BYTE, p);
{$IFDEF USE_VIDEO_RECORDING}
- ReduceImage(p, cScreenWidth, cScreenHeight, k, bpp)
+ ReduceImage(p, cScreenWidth, cScreenHeight, k)
{$ENDIF}
end;
@@ -340,7 +301,6 @@
end;
image^.size:= size;
image^.buffer:= p;
-image^.alpha:= hasA;
SDL_CreateThread(@SaveScreenshot{$IFDEF SDL2}, 'snapshot'{$ENDIF}, image);
MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate