diff options
author | Matthias Clasen <matthiasc@src.gnome.org> | 2006-03-03 17:19:27 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2006-03-03 17:19:27 +0000 |
commit | 9907ebb2ce5854819efec570b0924bdd378a53f4 (patch) | |
tree | 9fc012cb47329bb1a34eb0d87aa1b1dcb26175ca /gdk-pixbuf/io-pnm.c | |
parent | 87ff791dcbceed6c08d8490f802c0e7456d41508 (diff) | |
download | gtk+-9907ebb2ce5854819efec570b0924bdd378a53f4.tar.gz |
Support 16bit pnms
Diffstat (limited to 'gdk-pixbuf/io-pnm.c')
-rw-r--r-- | gdk-pixbuf/io-pnm.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/gdk-pixbuf/io-pnm.c b/gdk-pixbuf/io-pnm.c index 81225740ad..3af9794c25 100644 --- a/gdk-pixbuf/io-pnm.c +++ b/gdk-pixbuf/io-pnm.c @@ -392,13 +392,6 @@ pnm_read_header (PnmLoaderContext *context) return PNM_FATAL_ERR; } - if (context->maxval > 255) { - g_set_error (context->error, - GDK_PIXBUF_ERROR, - GDK_PIXBUF_ERROR_CORRUPT_IMAGE, - _("Cannot handle PNM files with maximum color values greater than 255")); - return PNM_FATAL_ERR; - } } break; default: @@ -438,6 +431,8 @@ pnm_read_raw_scanline (PnmLoaderContext *context) _("Raw PNM image type is invalid")); return PNM_FATAL_ERR; } + if(context->maxval>255) + numpix/=2; numpix = MIN (numpix, context->width - context->output_col); @@ -466,6 +461,8 @@ pnm_read_raw_scanline (PnmLoaderContext *context) _("Raw PNM image type is invalid")); return PNM_FATAL_ERR; } + if(context->maxval>255) + numbytes*=2; switch (context->type) { case PNM_FORMAT_PBM_RAW: @@ -479,6 +476,17 @@ pnm_read_raw_scanline (PnmLoaderContext *context) if (context->maxval == 255) { /* special-case optimization */ memcpy (dest, inbuf->byte, numbytes); + } else if(context->maxval == 65535) { + /* optimized version of the next case */ + for(i=0; i < numbytes ; i+=2) { + *dest++=inbuf->byte[i]; + } + } else if(context->maxval > 255) { + /* scale down to 256 colors */ + for(i=0; i < numbytes ; i+=2) { + guint v=inbuf->byte[i]*256+inbuf->byte[i+1]; + *dest++=v*255/context->maxval; + } } else { for (i = 0; i < numbytes; i++) { guchar *byte = inbuf->byte + i; @@ -591,7 +599,7 @@ pnm_read_ascii_scanline (PnmLoaderContext *context) break; case PNM_FORMAT_PGM: case PNM_FORMAT_PPM: - /* scale the color to an 8-bit color depth */ + /* scale the color up or down to an 8-bit color depth */ if (value > context->maxval) *dptr++ = 255; else |