cvs: gd /playground/gdbmp gd_bmp.c
[email protected] ("Scott MacVicar") Thu, 27 Mar 2008 14:36:27 -0000
| Newsgroups | php.gd.cvs |
|---|---|
| Message-ID | <cvsscottmac1206628587@cvsserver> |
scottmac Thu Mar 27 14:36:27 2008 UTC
Modified files:
/gd/playground/gdbmp gd_bmp.c
Log:
Disable compression if seek isn't available and expose the compression parameter
http://cvs.php.net/viewvc.cgi/gd/playground/gdbmp/gd_bmp.c?r1=1.11&r2=1.12&diff_format=u
Index: gd/playground/gdbmp/gd_bmp.c
diff -u gd/playground/gdbmp/gd_bmp.c:1.11 gd/playground/gdbmp/gd_bmp.c:1.12
--- gd/playground/gdbmp/gd_bmp.c:1.11 Fri Mar 14 20:53:08 2008
+++ gd/playground/gdbmp/gd_bmp.c Thu Mar 27 14:36:27 2008
@@ -12,7 +12,7 @@
----------------------------------------------------------------------------
*/
-/* $Id: gd_bmp.c,v 1.11 2008/03/14 20:53:08 pajoye Exp $ */
+/* $Id: gd_bmp.c,v 1.12 2008/03/27 14:36:27 scottmac Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -66,31 +66,35 @@
return 0;
}
-BGD_DECLARE(void *) gdImageBmpPtr(gdImagePtr im, int *size)
+BGD_DECLARE(void *) gdImageBmpPtr(gdImagePtr im, int *size, int compression)
{
void *rv;
gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
- gdImageBmpCtx(im, out);
+ gdImageBmpCtx(im, out, compression);
rv = gdDPExtractData(out, size);
out->gd_free(out);
return rv;
}
-BGD_DECLARE(void) gdImageBmp(gdImagePtr im, FILE *outFile)
+BGD_DECLARE(void) gdImageBmp(gdImagePtr im, FILE *outFile, int compression)
{
gdIOCtx *out = gdNewFileCtx(outFile);
- gdImageBmpCtx(im, out);
+ gdImageBmpCtx(im, out, compression);
out->gd_free(out);
}
-BGD_DECLARE(void) gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out)
+BGD_DECLARE(void) gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression)
{
int bitmap_size = 0, info_size, total_size, padding;
int i, row, xpos, pixel;
- int compression = 0;
int error = 0;
unsigned char *uncompressed_row = NULL, *uncompressed_row_start = NULL;
+ /* No compression if its true colour or we don't support seek */
+ if (im->trueColor || !out->seek) {
+ compression = 0;
+ }
+
bitmap_size = ((im->sx * (im->trueColor ? 24 : 8)) / 8) * im->sy;
/* 40 byte Windows v3 header */
@@ -107,11 +111,6 @@
/* bitmap header + info header + data */
total_size = 14 + info_size + bitmap_size;
- /* we need seek support at this moment in time */
- if (!out->seek) {
- return;
- }
-
/* write bmp header info */
gdPutBuf("BM", 2, out);
gdBMPPutInt(out, total_size);
@@ -125,7 +124,7 @@
gdBMPPutInt(out, im->sy); /* height */
gdBMPPutWord(out, 1); /* colour planes */
gdBMPPutWord(out, (im->trueColor ? 24 : 8)); /* bit count */
- gdBMPPutInt(out, ((!compression || im->trueColor) ? BMP_BI_RGB : BMP_BI_RLE8)); /* compression */
+ gdBMPPutInt(out, (compression ? BMP_BI_RLE8 : BMP_BI_RGB)); /* compression */
gdBMPPutInt(out, bitmap_size); /* image size */
gdBMPPutInt(out, 0); /* H resolution */
gdBMPPutInt(out, 0); /* V ressolution */