diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-11-27 07:35:43 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-11-27 07:35:43 +0000 |
commit | 9f6b126f9bbea66c65080f30bd2fef5c2aed1adc (patch) | |
tree | 742dbae893fbcd61d14efd3035a716d2f1e53deb /other | |
parent | 1dab1a5dca83e051708729802e0814d29097b44b (diff) | |
download | netpbm-mirror-9f6b126f9bbea66c65080f30bd2fef5c2aed1adc.tar.gz netpbm-mirror-9f6b126f9bbea66c65080f30bd2fef5c2aed1adc.tar.xz netpbm-mirror-9f6b126f9bbea66c65080f30bd2fef5c2aed1adc.zip |
pamx: fix bug: incorrect display of one-plane input image
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@148 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'other')
-rw-r--r-- | other/pamx/pamx.c | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/other/pamx/pamx.c b/other/pamx/pamx.c index 8a64fec4..c6503d5e 100644 --- a/other/pamx/pamx.c +++ b/other/pamx/pamx.c @@ -175,35 +175,32 @@ errorHandler(Display * const disp, -static void -fillRow1(struct pam * const pamP, - tuple * const tuplerow, - unsigned char ** const pP) { - - unsigned int col; - - for (col = 0; col < pamP->width; ++col) { - unsigned int plane; - for (plane = 0; plane < pamP->depth; ++plane) - *(*pP)++ = - pnm_scalesample(tuplerow[col][0], pamP->maxval, 255); - } -} - - +enum usableDepth {DEPTH_1, DEPTH_3}; static void -fillRow3(struct pam * const pamP, - tuple * const tuplerow, - unsigned char ** const pP) { +fillRow(struct pam * const pamP, + tuple * const tuplerow, + enum usableDepth const depth, + unsigned char ** const pP) { +/*---------------------------------------------------------------------------- + Add one row to the 24-bit truecolor image data at *pP, and advance + *pP just past that row. + Use either the first plane or the first 3 planes of tuplerow[] + for its contents, according to 'depth'. +-----------------------------------------------------------------------------*/ unsigned int col; for (col = 0; col < pamP->width; ++col) { + /* Truecolor image data has 3 bytes per pixel, one each for + red, green, and blue. + */ unsigned int plane; - for (plane = 0; plane < pamP->depth; ++plane) + for (plane = 0; plane < 3; ++plane) { + unsigned int const tuplePlane = depth == DEPTH_3 ? plane : 0; *(*pP)++ = - pnm_scalesample(tuplerow[col][plane], pamP->maxval, 255); + pnm_scalesample(tuplerow[col][tuplePlane], pamP->maxval, 255); + } } } @@ -218,7 +215,7 @@ loadPamImage(FILE * const ifP, unsigned int row; tuple * tuplerow; unsigned char * p; - enum {DEPTH_1, DEPTH_3} depth; + enum usableDepth depth; pnm_readpaminit(ifP, &pam, PAM_STRUCT_SIZE(tuple_type)); @@ -238,12 +235,17 @@ loadPamImage(FILE * const ifP, for (row = 0; row < pam.height; ++row) { pnm_readpamrow(&pam, tuplerow); + /* This semantically wasteful code allows a dumb compiler + optimizer to recognize that the depth is constant and + therefore not generate code that checks the depth every + time it processes a sample. + */ switch (depth) { case DEPTH_3: - fillRow3(&pam, tuplerow, &p); + fillRow(&pam, tuplerow, DEPTH_3, &p); break; case DEPTH_1: - fillRow1(&pam, tuplerow, &p); + fillRow(&pam, tuplerow, DEPTH_1, &p); break; } } |