diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libpnm3.c | 26 | ||||
-rw-r--r-- | lib/pnm.h | 3 |
2 files changed, 24 insertions, 5 deletions
diff --git a/lib/libpnm3.c b/lib/libpnm3.c index c7951546..4df8041c 100644 --- a/lib/libpnm3.c +++ b/lib/libpnm3.c @@ -337,12 +337,30 @@ pnm_promoteformatrow( xel* xelrow, int cols, xelval maxval, int format, xelval n pixel -xeltopixel(xel const inputxel) { +pnm_xeltopixel(xel const inputxel, + int const format) { pixel outputpixel; - PPM_ASSIGN(outputpixel, - PNM_GET1(inputxel), PNM_GET1(inputxel), PNM_GET1(inputxel)); + switch (PNM_FORMAT_TYPE(format)) { + case PPM_TYPE: + PPM_ASSIGN(outputpixel, + PPM_GETR(inputxel), + PPM_GETG(inputxel), + PPM_GETB(inputxel)); + break; + case PGM_TYPE: + case PBM_TYPE: + PPM_ASSIGN(outputpixel, + PNM_GET1(inputxel), + PNM_GET1(inputxel), + PNM_GET1(inputxel)); + break; + default: + pm_error("Invalid format code %d passed to pnm_xeltopixel()", + format); + } + return outputpixel; } @@ -381,7 +399,7 @@ pnm_parsecolorxel(const char * const colorName, colorName); break; default: - pm_error("Invalid format code %d passed to pnm_parsecolor()", + pm_error("Invalid format code %d passed to pnm_parsecolorxel()", format); } diff --git a/lib/pnm.h b/lib/pnm.h index 354eacf9..94d4ff85 100644 --- a/lib/pnm.h +++ b/lib/pnm.h @@ -124,7 +124,8 @@ pnm_promoteformatrow(xel* xelrow, int cols, xelval maxval, int format, xelval newmaxval, int newformat); pixel -xeltopixel(xel const inputxel); +pnm_xeltopixel(xel const inputxel, + int const format); xel pnm_parsecolorxel(const char * const colorName, |