]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - image_png.c
screenshot: get rid of the 3*w*h+18 TGA buffer; instead however always capture as...
[xonotic/darkplaces.git] / image_png.c
index d194931523c751ca2fafe607d056f7d50c6fd655..b97e9c6d04dfd5bb9f5092916fd02dafc24657fe 100644 (file)
@@ -443,7 +443,7 @@ PNG_SaveImage_preflipped
 Save a preflipped PNG image to a file
 ====================
 */
-qboolean PNG_SaveImage_preflipped (const char *filename, int width, int height, unsigned char *data)
+qboolean PNG_SaveImage_preflipped (const char *filename, int width, int height, qboolean has_alpha, unsigned char *data)
 {
        unsigned int offset, linesize;
        qfile_t* file = NULL;
@@ -497,8 +497,7 @@ qboolean PNG_SaveImage_preflipped (const char *filename, int width, int height,
 
        //qpng_set_compression_level(png, Z_BEST_COMPRESSION);
        qpng_set_compression_level(png, Z_BEST_SPEED);
-       qpng_set_IHDR(png, pnginfo, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_ADAM7, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
-       //qpng_set_IHDR(png, pnginfo, width, height, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+       qpng_set_IHDR(png, pnginfo, width, height, 8, has_alpha ? PNG_COLOR_TYPE_RGB_ALPHA : PNG_COLOR_TYPE_RGB, PNG_INTERLACE_ADAM7, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
        qpng_set_filter(png, 0, PNG_NO_FILTERS);
        qpng_write_info(png, pnginfo);
        qpng_set_packing(png);
@@ -506,7 +505,7 @@ qboolean PNG_SaveImage_preflipped (const char *filename, int width, int height,
 
        passes = qpng_set_interlace_handling(png);
 
-       linesize = width * 3;
+       linesize = width * (has_alpha ? 4 : 3);
        offset = linesize * (height - 1);
        for(i = 0; i < passes; ++i)
                for(j = 0; j < height; ++j)