diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2009-09-27 21:44:29 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2009-09-27 21:44:29 +0000 |
commit | 43939e66b1d4eeb2f3799c124f3598756755005a (patch) | |
tree | 15733092de55d52421a6ea02f5a43d5f8ff24393 /lib/libpnm2.c | |
parent | 49f4336c9bba33650573ba780b70bc501b38643e (diff) | |
download | netpbm-mirror-43939e66b1d4eeb2f3799c124f3598756755005a.tar.gz netpbm-mirror-43939e66b1d4eeb2f3799c124f3598756755005a.tar.xz netpbm-mirror-43939e66b1d4eeb2f3799c124f3598756755005a.zip |
Rebase Stable series to current Advanced: 10.47.04
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@995 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libpnm2.c')
-rw-r--r-- | lib/libpnm2.c | 107 |
1 files changed, 75 insertions, 32 deletions
diff --git a/lib/libpnm2.c b/lib/libpnm2.c index aae78d52..01ffa389 100644 --- a/lib/libpnm2.c +++ b/lib/libpnm2.c @@ -15,13 +15,10 @@ #include "pnm.h" #include "ppm.h" -#include "libppm.h" #include "pgm.h" -#include "libpgm.h" #include "pbm.h" -#include "libpbm.h" void pnm_writepnminit(FILE * const fileP, @@ -55,51 +52,97 @@ pnm_writepnminit(FILE * const fileP, -void -pnm_writepnmrow(FILE * const fileP, - xel * const xelrow, - int const cols, - xelval const maxval, - int const format, - int const forceplain) { - - bool const plainFormat = forceplain || pm_plain_output; +static void +writepgmrow(FILE * const fileP, + const xel * const xelrow, + unsigned int const cols, + xelval const maxval, + int const format, + bool const plainFormat) { - switch (PNM_FORMAT_TYPE(format)) { - case PPM_TYPE: - ppm_writeppmrow(fileP, (pixel*) xelrow, cols, (pixval) maxval, - plainFormat); - break; - - case PGM_TYPE: { - gray* grayrow; + jmp_buf jmpbuf; + jmp_buf * origJmpbufP; + gray * grayrow; + + grayrow = pgm_allocrow(cols); + + if (setjmp(jmpbuf) != 0) { + pgm_freerow(grayrow); + pm_setjmpbuf(origJmpbufP); + pm_longjmp(); + } else { unsigned int col; - grayrow = pgm_allocrow(cols); - + pm_setjmpbufsave(&jmpbuf, &origJmpbufP); + for (col = 0; col < cols; ++col) grayrow[col] = PNM_GET1(xelrow[col]); - + pgm_writepgmrow(fileP, grayrow, cols, (gray) maxval, plainFormat); - pgm_freerow( grayrow ); + pm_setjmpbuf(origJmpbufP); } - break; + pgm_freerow(grayrow); +} + + - case PBM_TYPE: { - bit* bitrow; +static void +writepbmrow(FILE * const fileP, + const xel * const xelrow, + unsigned int const cols, + bool const plainFormat) { + + jmp_buf jmpbuf; + jmp_buf * origJmpbufP; + bit * bitrow; + + bitrow = pbm_allocrow(cols); + + if (setjmp(jmpbuf) != 0) { + pbm_freerow(bitrow); + pm_setjmpbuf(origJmpbufP); + pm_longjmp(); + } else { unsigned int col; - bitrow = pbm_allocrow(cols); + pm_setjmpbufsave(&jmpbuf, &origJmpbufP); for (col = 0; col < cols; ++col) bitrow[col] = PNM_GET1(xelrow[col]) == 0 ? PBM_BLACK : PBM_WHITE; - + pbm_writepbmrow(fileP, bitrow, cols, plainFormat); - pbm_freerow(bitrow); - } - break; + pm_setjmpbuf(origJmpbufP); + } + pbm_freerow(bitrow); +} + + + +void +pnm_writepnmrow(FILE * const fileP, + const xel * const xelrow, + int const cols, + xelval const maxval, + int const format, + int const forceplain) { + + bool const plainFormat = forceplain || pm_plain_output; + + switch (PNM_FORMAT_TYPE(format)) { + case PPM_TYPE: + ppm_writeppmrow(fileP, (pixel*) xelrow, cols, (pixval) maxval, + plainFormat); + break; + + case PGM_TYPE: + writepgmrow(fileP, xelrow, cols, maxval, format, plainFormat); + break; + + case PBM_TYPE: + writepbmrow(fileP, xelrow, cols, plainFormat); + break; default: pm_error("invalid format argument received by pnm_writepnmrow(): %d" |