Commits

Anonymous committed 8cd6354

Disable compression if seek isn't available and expose the compression parameter

Comments (0)

Files changed (1)

 	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 */
 	/* 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);
 	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 */