Package: netpbm
Version: 10.0-11
Severity: wishlist
Tags: patch
ppmtobmp doesn't support 16 bpp output. This patch rectifies that.
diff -ur netpbm-free-10.0/ppm/ppmtobmp.1
netpbm-free-10.0-16bppbpm/ppm/ppmtobmp.1
--- netpbm-free-10.0/ppm/ppmtobmp.1 2003-08-12 11:23:03.000000000 -0700
+++ netpbm-free-10.0-16bppbpm/ppm/ppmtobmp.1 2007-06-11 18:22:53.000000000
-0700
@@ -27,7 +27,7 @@
.TP
.B \-bpp
This determines how many bits per pixel you want the BMP file to contain.
-Only 1, 4, 8, and 24 are possible. By default,
+Only 1, 4, 8, 16, and 24 are possible. By default,
.B ppmtobmp
chooses the smallest number with which it can represent all the colors
in the input image. If you specify a number too small to represent all
diff -ur netpbm-free-10.0/ppm/ppmtobmp.c
netpbm-free-10.0-16bppbpm/ppm/ppmtobmp.c
--- netpbm-free-10.0/ppm/ppmtobmp.c 2007-06-11 18:27:25.000000000 -0700
+++ netpbm-free-10.0-16bppbpm/ppm/ppmtobmp.c 2007-06-11 18:46:25.000000000
-0700
@@ -135,9 +135,9 @@
cmdline_p->class = C_WIN;
- if (bpp != -1 && bpp != 1 && bpp != 4 && bpp != 8 && bpp != 24)
+ if (bpp != -1 && bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp !=
24)
pm_error("Invalid --bpp value specified. The only values valid\n"
- "in the BMP format are 1, 4, 8, and 24 bits per pixel");
+ "in the BMP format are 1, 4, 8, 16, and 24 bits per pixel");
cmdline_p->bits_per_pixel = bpp;
}
@@ -373,7 +373,7 @@
* returns the number of bytes written, or -1 on error.
*/
static int
-BMPwriterow_truecolor(FILE *fp, const pixel *row, const unsigned long cols) {
+BMPwriterow_truecolor(FILE *fp, int bpp, const pixel *row, const unsigned long
cols) {
/*----------------------------------------------------------------------------
Write a row of a truecolor BMP image to the file 'fp'. The row is
'row', which is 'cols' columns long.
@@ -382,9 +382,9 @@
On error, issue error message and exit program.
-----------------------------------------------------------------------------*/
- /* This only works for 24 bits per pixel. To implement this for the
+ /* This only works for 16/24 bits per pixel. To implement this for the
general case (which is only hypothetical -- this program doesn't
- write any truecolor images except 24 bit and apparently no one
+ write any truecolor images except 16/24 bit and apparently no one
else does either), you would move this function into
BMPwriterow_pallette, which writes arbitrary bit strings. But
that would be a lot slower and less robust.
@@ -394,11 +394,24 @@
int col;
nbyte = 0; /* initial value */
- for (col = 0; col < cols; col++) {
- PutByte(fp, PPM_GETB(row[col]));
- PutByte(fp, PPM_GETG(row[col]));
- PutByte(fp, PPM_GETR(row[col]));
- nbyte += 3;
+ if (bpp == 16) {
+ unsigned short r, g, b, val;
+ for (col = 0; col < cols; col++) {
+ b = ((unsigned) PPM_GETB(row[col])) >> 3;
+ g = ((unsigned) PPM_GETG(row[col])) >> 3;
+ r = ((unsigned) PPM_GETR(row[col])) >> 3;
+ val = (b << 0) | (g << 5) | (r << 10);
+ PutByte(fp, val & 0xff);
+ PutByte(fp, val >> 8);
+ nbyte += 2;
+ }
+ } else {
+ for (col = 0; col < cols; col++) {
+ PutByte(fp, PPM_GETB(row[col]));
+ PutByte(fp, PPM_GETG(row[col]));
+ PutByte(fp, PPM_GETR(row[col]));
+ nbyte += 3;
+ }
}
/*
@@ -441,7 +454,7 @@
rc = BMPwriterow_pallette(fp, pixels[y], cx,
cBitCount, cht);
else
- rc = BMPwriterow_truecolor(fp, pixels[y], cx);
+ rc = BMPwriterow_truecolor(fp, cBitCount, pixels[y], cx);
if(rc == -1)
{
@@ -506,6 +519,7 @@
((bpp <= 1) ? 1 : \
(bpp <= 4) ? 4 : \
(bpp <= 8) ? 8 : \
+ (bpp <= 16) ? 16 : \
24)
@@ -547,7 +561,7 @@
colors_p);
if (chv == NULL) {
pm_message("More than %d colors found", MAXCOLORS);
- *minimum_bpp_p = 24;
+ *minimum_bpp_p = 16;
*cht_p = NULL;
} else {
*minimum_bpp_p = adjust_minimum_bpp(pm_maxvaltobits(*colors_p-1));
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]