Thread View: alt.graphics.pixutils
1 messages
1 total messages
Started by David Clunie
Sat, 23 Jul 1994 17:37
PATCH: IJG jpegv4 12 bit mode & pgm/ppm files
Author: David Clunie
Date: Sat, 23 Jul 1994 17:37
Date: Sat, 23 Jul 1994 17:37
1007 lines
32966 bytes
32966 bytes
Patch to use 12 bit mode and handle pgm/ppm files. Will use proposed new
extended raw 16 bit pgm/ppm files if desired.
Works fine with v4 and v4a of the Independent JPEG Groups code.
Use "cd jpegv4; patch -p1 <thismessage".
diff -r -c jpegv4a/README.pbm12bits jpegv4a.12/README.pbm12bits
*** jpegv4a/README.pbm12bits Sat Jul 23 20:10:13 1994
--- jpegv4a.12/README.pbm12bits Sat Jul 23 20:02:39 1994
***************
*** 0 ****
--- 1,91 ----
+ Sat Jul 23 19:02:07 GMT+0300 1994
+
+ Doing 8 bits, 12 bits, 16 bits and the PGM/PPM format.
+
+ The standard distribution has limited support for the PGM/PPM format:
+
+ - it will read raw (8 bit) or text files (any maxval) and scale
+ the data to the current data precision (usually 8).
+
+ - it will write raw 8 bit files only (though passed through the
+ colormaps if quantized) and if the precision is greater than
+ 8 bits only the low 8 bits would be used, if it weren't for the
+ fact that there is a pre-processor generated compile error
+ when BITS_IN_JSAMPLE is not 8.
+
+ In otherwords, though one can compile the library with 12 bits of precision
+ and use the standard "jrdppm.c" to read 12 bit data, there is no way to
+ write it out again.
+
+ This patch addresses these issues, and in addition supports the use of an
+ extension to the PGM/PPM format that allows >8 <16 bit values to be read
+ or written in raw form (little endian two byte word) based on the value
+ of maxval in the header ... if it is <=255 use a byte, if it is >255 but
+ <= 65535, use a word. Though nonstandard, there is another simple patch
+ floating around to patch the pbmplus and netpbm toolkits to handle such
+ files. These raw binary files save enormous amounts of space compared
+ with their text equivalents and make PGM/PPM a potentially useful file
+ format for handling such images.
+
+ The patched version has the following characteristics:
+
+ - it can read any text, normal 8 bit and extended 16 bit PGM/PPM
+ regardless of compile time options, and scales the data to the
+ data precision.
+
+ - if compiled with EIGHT_BIT_SAMPLES, it will write normal 8 bit
+ raw PGM/PPM files, unless PPM_WRITETEXT is defined, in which
+ case it will always write text files (pretty useless option).
+
+ - if compiled with TWELVE_BIT_SAMPLES, it will write text format
+ PGM/PPM files, unless PPM_WRITERAWWORDS is defined, in which
+ case it will write 16 bit raw extended PGM/PPM files - this is
+ the setting I use.
+
+ Note that the jwrppm.c and jrdppm.c routines are actually a little more
+ complicated and prepared for the day when 8 or 12 bits can be selected
+ at runtime rather than compile time, and they will behave properly
+ bases on the data_precision set in the cinfo structure. For now they just
+ behave the easy way.
+
+ Note that because the input is automatically scaled, you can actually
+ feed 8 bit files into a 12 bit "cjpeg|djpeg" and get 12 bits out, or
+ feed 12 bit data into an 8 bit "cjpeg|djpeg" and get 8 bits out !
+
+ On old versions of the source, one had to set the "-o" flag to cjpeg when
+ using 12 bit precision, as there are no default Huffman tables for 12 bit
+ mode, but you didn't know until you get a "Corrupted data in JPEG file"
+ message from djpeg! This is now set automatically in more recent versions
+ when a precision other than 8 is set.
+
+ Also if you do define TWELVE_BIT_SAMPLES, remember to undefine
+ TARGA_SUPPORTED and RLE_SUPPORTED as neither of these can handle 12 bits
+ and bitch if they have to. Intrestingly the gif routines have a little
+ shift in there to take care of data precisions > 8 ! In fact ...
+
+ cjpeg12 < test.grey.12.raw.pgm | djpeg12 -gif >test.gif
+
+ works just fine, amazingly enough.
+
+ Once you have versions for 12 bits compiled, and if you have defined
+ PPM_WRITERAWWORDS at compile time, and have updated your pbmplus library
+ but not your X viewer to handle the "extended 16 bit raw" format, one
+ can do things like this ...
+
+ cjpeg12 < test.grey.12.raw.pgm | djpeg12 | pnmnoraw | xv -
+
+ and actually see an image ! (Although you will have to mess with the
+ color editor of xv to window the image if your data is all squashed
+ down the bottom of the dynamic range like MRI data usually is).
+
+ You don't HAVE to use the extended format ... if you want your images
+ to be compatible and transportable (at least until the known universe
+ fully adopts this wonderful new format) you can always leave out
+ PPM_WRITERAWWORDS, still use the 12 bit mode and produce huge, but
+ functional text files ... well it works, and is better than nothing.
+
+ Finally thanks to whoever wrote the JPEG stuff to handle 12 bits in the
+ first place even though hardly anyone wants it ... those of us who do
+ are very grateful !
+
+ David A. Clunie (dclunie@flash.us.com)
diff -r -c jpegv4a/jconfig.h jpegv4a.12/jconfig.h
*** jpegv4a/jconfig.h Fri Apr 23 04:32:38 1993
--- jpegv4a.12/jconfig.h Sat Jul 23 18:50:11 1994
***************
*** 200,206 ****
#define GIF_SUPPORTED /* GIF image file format */
/* #define RLE_SUPPORTED */ /* RLE image file format (by default, no) */
#define PPM_SUPPORTED /* PPM/PGM image file format */
! #define TARGA_SUPPORTED /* Targa image file format */
#undef TIFF_SUPPORTED /* TIFF image file format (not yet impl.) */
/* more capability options later, no doubt */
--- 200,207 ----
#define GIF_SUPPORTED /* GIF image file format */
/* #define RLE_SUPPORTED */ /* RLE image file format (by default, no) */
#define PPM_SUPPORTED /* PPM/PGM image file format */
! #define PPM_WRITERAWWORDS /* If 12 bits, write extended raw word format */
! #undef TARGA_SUPPORTED /* Targa image file format */
#undef TIFF_SUPPORTED /* TIFF image file format (not yet impl.) */
/* more capability options later, no doubt */
***************
*** 221,228 ****
* you'll have to supply different default Huffman tables.
*/
! #define EIGHT_BIT_SAMPLES
! #undef TWELVE_BIT_SAMPLES
#undef SIXTEEN_BIT_SAMPLES
--- 222,229 ----
* you'll have to supply different default Huffman tables.
*/
! #undef EIGHT_BIT_SAMPLES
! #define TWELVE_BIT_SAMPLES
#undef SIXTEEN_BIT_SAMPLES
diff -r -c jpegv4a/jrdppm.c jpegv4a.12/jrdppm.c
*** jpegv4a/jrdppm.c Fri Apr 23 04:32:36 1993
--- jpegv4a.12/jrdppm.c Sat Jul 23 19:15:21 1994
***************
*** 119,124 ****
--- 119,138 ----
}
+ LOCAL unsigned int
+ read_raw_integer (compress_info_ptr cinfo)
+ /* Read a little-endian binary 16 bit value from the PPM file */
+ {
+ register unsigned int ch1;
+ register unsigned int ch2;
+ register unsigned int val;
+
+ ch1 = getc(cinfo->input_file);
+ ch2 = getc(cinfo->input_file);
+ val = (ch2<<8)|ch1;
+ return val;
+ }
+
/*
* Read one row of pixels.
*
***************
*** 334,339 ****
--- 348,417 ----
#endif /* USE_GETC_INPUT */
+ METHODDEF void
+ get_scaled_word_gray_row (compress_info_ptr cinfo, JSAMPARRAY pixel_row)
+ /* This version is for reading raw-format word PGM files with scaling */
+ {
+ register JSAMPROW ptr0;
+ register long col;
+
+ ptr0 = pixel_row[0];
+ for (col = cinfo->image_width; col > 0; col--) {
+ *ptr0++ = rescale[read_raw_integer(cinfo)];
+ }
+ }
+
+
+ METHODDEF void
+ get_scaled_word_rgb_row (compress_info_ptr cinfo, JSAMPARRAY pixel_row)
+ /* This version is for reading raw-format word PPM files with scaling */
+ {
+ register JSAMPROW ptr0, ptr1, ptr2;
+ register long col;
+
+ ptr0 = pixel_row[0];
+ ptr1 = pixel_row[1];
+ ptr2 = pixel_row[2];
+ for (col = cinfo->image_width; col > 0; col--) {
+ *ptr0++ = rescale[read_raw_integer(cinfo)];
+ *ptr1++ = rescale[read_raw_integer(cinfo)];
+ *ptr2++ = rescale[read_raw_integer(cinfo)];
+ }
+ }
+
+
+ METHODDEF void
+ get_raw_word_gray_row (compress_info_ptr cinfo, JSAMPARRAY pixel_row)
+ /* This version is for reading raw-format word PGM files without scaling */
+ {
+ register JSAMPROW ptr0;
+ register long col;
+
+ ptr0 = pixel_row[0];
+ for (col = cinfo->image_width; col > 0; col--) {
+ *ptr0++ = (JSAMPLE) read_raw_integer(cinfo);
+ }
+ }
+
+
+ METHODDEF void
+ get_raw_word_rgb_row (compress_info_ptr cinfo, JSAMPARRAY pixel_row)
+ /* This version is for reading raw-format word PPM files without scaling */
+ {
+ register JSAMPROW ptr0, ptr1, ptr2;
+ register long col;
+
+ ptr0 = pixel_row[0];
+ ptr1 = pixel_row[1];
+ ptr2 = pixel_row[2];
+ for (col = cinfo->image_width; col > 0; col--) {
+ *ptr0++ = (JSAMPLE) read_raw_integer(cinfo);
+ *ptr1++ = (JSAMPLE) read_raw_integer(cinfo);
+ *ptr2++ = (JSAMPLE) read_raw_integer(cinfo);
+ }
+ }
+
+
/*
* Read the file header; return image size and component count.
*/
***************
*** 343,351 ****
{
int c;
unsigned int w, h, maxval;
if (getc(cinfo->input_file) != 'P')
! ERREXIT(cinfo->emethods, "Not a PPM file");
c = getc(cinfo->input_file); /* save format discriminator for a sec */
--- 421,430 ----
{
int c;
unsigned int w, h, maxval;
+ int scaling;
if (getc(cinfo->input_file) != 'P')
! ERREXIT(cinfo->emethods, "Not a PGM or PPM file");
c = getc(cinfo->input_file); /* save format discriminator for a sec */
***************
*** 354,361 ****
maxval = read_pbm_integer(cinfo);
if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
! ERREXIT(cinfo->emethods, "Not a PPM file");
switch (c) {
case '2': /* it's a text-format PGM file */
cinfo->methods->get_input_row = get_text_gray_row;
--- 433,459 ----
maxval = read_pbm_integer(cinfo);
if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
! ERREXIT(cinfo->emethods, "Not a PGM or PPM file");
+ #ifdef MULTIPLEPRECISIONSCANCOEXIST /* Nice fantasy */
+ if (maxval > MAXJSAMPLE) {
+ scaling=1;
+ cinfo->data_precision = BITS_IN_JSAMPLE;
+ } else if (maxval <= 255) {
+ scaling=0;
+ cinfo->data_precision = 8;
+ } else if (maxval <= 4095) {
+ scaling=0;
+ cinfo->data_precision = 12;
+ } else {
+ cinfo->data_precision = BITS_IN_JSAMPLE; /* optimistic or what ? */
+ }
+ #else /*MULTIPLEPRECISIONSCANCOEXIST*/
+ cinfo->data_precision = BITS_IN_JSAMPLE;
+ if (maxval != MAXJSAMPLE) scaling=1;
+ else scaling=0;
+ #endif /*MULTIPLEPRECISIONSCANCOEXIST*/
+
switch (c) {
case '2': /* it's a text-format PGM file */
cinfo->methods->get_input_row = get_text_gray_row;
***************
*** 372,414 ****
break;
case '5': /* it's a raw-format PGM file */
! if (maxval == MAXJSAMPLE)
! cinfo->methods->get_input_row = get_raw_gray_row;
! else
! cinfo->methods->get_input_row = get_scaled_gray_row;
! cinfo->input_components = 1;
! cinfo->in_color_space = CS_GRAYSCALE;
#ifndef USE_GETC_INPUT
! /* allocate space for row buffer: 1 byte/pixel */
! row_buffer = (U_CHAR *) (*cinfo->emethods->alloc_small)
((size_t) (SIZEOF(U_CHAR) * (long) w));
#endif
TRACEMS2(cinfo->emethods, 1, "%ux%u PGM image", w, h);
break;
case '6': /* it's a raw-format PPM file */
! if (maxval == MAXJSAMPLE)
! cinfo->methods->get_input_row = get_raw_rgb_row;
! else
! cinfo->methods->get_input_row = get_scaled_rgb_row;
! cinfo->input_components = 3;
! cinfo->in_color_space = CS_RGB;
#ifndef USE_GETC_INPUT
! /* allocate space for row buffer: 3 bytes/pixel */
! row_buffer = (U_CHAR *) (*cinfo->emethods->alloc_small)
((size_t) (3 * SIZEOF(U_CHAR) * (long) w));
#endif
TRACEMS2(cinfo->emethods, 1, "%ux%u PPM image", w, h);
break;
default:
! ERREXIT(cinfo->emethods, "Not a PPM file");
break;
}
/* Compute the rescaling array if necessary */
/* This saves per-pixel calculation */
! if (maxval == MAXJSAMPLE)
rescale = NULL; /* no rescaling required */
else {
INT32 val, half_maxval;
--- 470,528 ----
break;
case '5': /* it's a raw-format PGM file */
! if (maxval <= 255)
! {
#ifndef USE_GETC_INPUT
! /* allocate space for row buffer: 1 byte/pixel */
! row_buffer = (U_CHAR *) (*cinfo->emethods->alloc_small)
((size_t) (SIZEOF(U_CHAR) * (long) w));
#endif
+ if (!scaling)
+ cinfo->methods->get_input_row = get_raw_gray_row;
+ else
+ cinfo->methods->get_input_row = get_scaled_gray_row;
+ } else {
+ if (!scaling)
+ cinfo->methods->get_input_row = get_raw_word_gray_row;
+ else
+ cinfo->methods->get_input_row = get_scaled_word_gray_row;
+ }
+ cinfo->input_components = 1;
+ cinfo->in_color_space = CS_GRAYSCALE;
TRACEMS2(cinfo->emethods, 1, "%ux%u PGM image", w, h);
break;
case '6': /* it's a raw-format PPM file */
! if (maxval <= 255)
! {
#ifndef USE_GETC_INPUT
! /* allocate space for row buffer: 3 bytes/pixel */
! row_buffer = (U_CHAR *) (*cinfo->emethods->alloc_small)
((size_t) (3 * SIZEOF(U_CHAR) * (long) w));
#endif
+ if (!scaling)
+ cinfo->methods->get_input_row = get_raw_rgb_row;
+ else
+ cinfo->methods->get_input_row = get_scaled_rgb_row;
+ } else {
+ if (!scaling)
+ cinfo->methods->get_input_row = get_raw_word_rgb_row;
+ else
+ cinfo->methods->get_input_row = get_scaled_word_rgb_row;
+ }
+ cinfo->input_components = 3;
+ cinfo->in_color_space = CS_RGB;
TRACEMS2(cinfo->emethods, 1, "%ux%u PPM image", w, h);
break;
default:
! ERREXIT(cinfo->emethods, "Not a PGM or PPM file");
break;
}
/* Compute the rescaling array if necessary */
/* This saves per-pixel calculation */
! if (!scaling)
rescale = NULL; /* no rescaling required */
else {
INT32 val, half_maxval;
***************
*** 425,431 ****
cinfo->image_width = w;
cinfo->image_height = h;
- cinfo->data_precision = BITS_IN_JSAMPLE;
}
--- 539,544 ----
diff -r -c jpegv4a/jwrppm.c jpegv4a.12/jwrppm.c
*** jpegv4a/jwrppm.c Fri Apr 23 04:32:37 1993
--- jpegv4a.12/jwrppm.c Sat Jul 23 20:12:08 1994
***************
*** 19,36 ****
#ifdef PPM_SUPPORTED
-
/*
- * Haven't yet got around to making this work with text-format output,
- * hence cannot handle pixels wider than 8 bits.
- */
-
- #ifndef EIGHT_BIT_SAMPLES
- Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
- #endif
-
-
- /*
* On most systems, writing individual bytes with putc() is drastically less
* efficient than buffering a row at a time for fwrite(). But we must
* allocate the row buffer in near data space on PCs, because we are assuming
--- 19,25 ----
***************
*** 53,79 ****
METHODDEF void
output_init (decompress_info_ptr cinfo)
{
! if (cinfo->out_color_space == CS_GRAYSCALE) {
/* emit header for raw PGM format */
fprintf(cinfo->output_file, "P5\n%ld %ld\n%d\n",
! cinfo->image_width, cinfo->image_height, 255);
! #ifndef USE_PUTC_OUTPUT
! /* allocate space for row buffer: 1 byte/pixel */
! row_buffer = (char *) (*cinfo->emethods->alloc_small)
! ((size_t) (SIZEOF(char) * cinfo->image_width));
! #endif
! } else if (cinfo->out_color_space == CS_RGB) {
/* emit header for raw PPM format */
fprintf(cinfo->output_file, "P6\n%ld %ld\n%d\n",
! cinfo->image_width, cinfo->image_height, 255);
#ifndef USE_PUTC_OUTPUT
! /* allocate space for row buffer: 3 bytes/pixel */
! row_buffer = (char *) (*cinfo->emethods->alloc_small)
((size_t) (3 * SIZEOF(char) * cinfo->image_width));
! #endif
! } else {
! ERREXIT(cinfo->emethods, "PPM output must be grayscale or RGB");
! }
}
--- 42,118 ----
METHODDEF void
output_init (decompress_info_ptr cinfo)
{
! unsigned maxval;
!
! /* don't need to check MAXJSAMPLE etc. because couldn't get this far */
! /* with any other value of cinfo->data_precision than 8 if only 8 bits */
!
! if (cinfo->data_precision == 8) {
! maxval=255;
! } else if (cinfo->data_precision == 12) {
! maxval=4095;
! } else {
! ERREXIT(cinfo->emethods, "PPM output - only 8 or 12 bits supported");
! }
!
! #ifdef PPM_WRITETEXT
! if (cinfo->out_color_space == CS_GRAYSCALE)
! /* emit header for text PGM format */
! fprintf(cinfo->output_file, "P2\n%ld %ld\n%d\n",
! cinfo->image_width, cinfo->image_height, maxval);
! else if (cinfo->out_color_space == CS_RGB)
! /* emit header for text PPM format */
! fprintf(cinfo->output_file, "P3\n%ld %ld\n%d\n",
! cinfo->image_width, cinfo->image_height, maxval);
! #else /*PPM_WRITETEXT*/
! if (cinfo->out_color_space == CS_GRAYSCALE)
! #ifdef PPM_WRITERAWWORDS
/* emit header for raw PGM format */
fprintf(cinfo->output_file, "P5\n%ld %ld\n%d\n",
! cinfo->image_width, cinfo->image_height, maxval);
! #else /*PPM_WRITERAWWORDS*/
! if (cinfo->data_precision == 8)
! /* emit header for raw PGM format */
! fprintf(cinfo->output_file, "P5\n%ld %ld\n%d\n",
! cinfo->image_width, cinfo->image_height, maxval);
! else
! /* emit header for text PGM format */
! fprintf(cinfo->output_file, "P2\n%ld %ld\n%d\n",
! cinfo->image_width, cinfo->image_height, maxval);
! #endif /*PPM_WRITERAWWORDS*/
! else if (cinfo->out_color_space == CS_RGB)
! #ifdef PPM_WRITERAWWORDS
/* emit header for raw PPM format */
fprintf(cinfo->output_file, "P6\n%ld %ld\n%d\n",
! cinfo->image_width, cinfo->image_height, maxval);
! #else /*PPM_WRITERAWWORDS*/
! if (cinfo->data_precision == 8)
! /* emit header for raw PPM format */
! fprintf(cinfo->output_file, "P6\n%ld %ld\n%d\n",
! cinfo->image_width, cinfo->image_height, maxval);
! else
! /* emit header for text PPM format */
! fprintf(cinfo->output_file, "P3\n%ld %ld\n%d\n",
! cinfo->image_width, cinfo->image_height, maxval);
! #endif /*PPM_WRITERAWWORDS*/
! #endif /*PPM_WRITETEXT*/
! else
! ERREXIT(cinfo->emethods, "PPM output must be grayscale or RGB");
!
! #ifndef PPM_WRITETEXT
#ifndef USE_PUTC_OUTPUT
! if (cinfo->data_precision == 8) {
! if (cinfo->out_color_space == CS_GRAYSCALE)
! /* allocate space for row buffer: 1 byte/pixel */
! row_buffer = (char *) (*cinfo->emethods->alloc_small)
! ((size_t) (SIZEOF(char) * cinfo->image_width));
! else
! /* allocate space for row buffer: 3 bytes/pixel */
! row_buffer = (char *) (*cinfo->emethods->alloc_small)
((size_t) (3 * SIZEOF(char) * cinfo->image_width));
! }
! #endif /*USE_PUTC_OUTPUT*/
! #endif /*PPM_WRITETEXT*/
}
***************
*** 81,90 ****
* Write some pixel data.
*/
#ifdef USE_PUTC_OUTPUT
METHODDEF void
! put_pixel_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
register FILE * outfile = cinfo->output_file;
--- 120,227 ----
* Write some pixel data.
*/
+ METHODDEF void
+ put_rgb_text_rows (decompress_info_ptr cinfo, int num_rows,
+ JSAMPIMAGE pixel_data)
+ {
+ register FILE * outfile = cinfo->output_file;
+ register JSAMPROW ptr0, ptr1, ptr2;
+ register long col;
+ long width = cinfo->image_width;
+ int row;
+
+ for (row = 0; row < num_rows; row++) {
+ ptr0 = pixel_data[0][row];
+ ptr1 = pixel_data[1][row];
+ ptr2 = pixel_data[2][row];
+ for (col = width; col > 0; col--) {
+ fprintf(outfile,"%u\n",(unsigned)GETJSAMPLE(*ptr0));
+ ptr0++;
+ fprintf(outfile,"%u\n",(unsigned)GETJSAMPLE(*ptr1));
+ ptr1++;
+ fprintf(outfile,"%u\n",(unsigned)GETJSAMPLE(*ptr2));
+ ptr2++;
+ }
+ }
+ }
+
+ METHODDEF void
+ put_gray_text_rows (decompress_info_ptr cinfo, int num_rows,
+ JSAMPIMAGE pixel_data)
+ {
+ register FILE * outfile = cinfo->output_file;
+ register JSAMPROW ptr0;
+ register long col;
+ long width = cinfo->image_width;
+ int row;
+
+ for (row = 0; row < num_rows; row++) {
+ ptr0 = pixel_data[0][row];
+ for (col = width; col > 0; col--) {
+ fprintf(outfile,"%u\n",(unsigned)GETJSAMPLE(*ptr0));
+ ptr0++;
+ }
+ }
+ }
+
+ METHODDEF void
+ put_rgb_raw_word_rows (decompress_info_ptr cinfo, int num_rows,
+ JSAMPIMAGE pixel_data)
+ {
+ register FILE * outfile = cinfo->output_file;
+ register JSAMPROW ptr0, ptr1, ptr2;
+ register long col;
+ long width = cinfo->image_width;
+ int row;
+
+ for (row = 0; row < num_rows; row++) {
+ ptr0 = pixel_data[0][row];
+ ptr1 = pixel_data[1][row];
+ ptr2 = pixel_data[2][row];
+ for (col = width; col > 0; col--) {
+ JSAMPLE value;
+ value=GETJSAMPLE(*ptr0);
+ putc(value&0xff, outfile);
+ putc((value>>8)&0xff, outfile);
+ ptr0++;
+ value=GETJSAMPLE(*ptr1);
+ putc(value&0xff, outfile);
+ putc((value>>8)&0xff, outfile);
+ ptr1++;
+ value=GETJSAMPLE(*ptr2);
+ putc(value&0xff, outfile);
+ putc((value>>8)&0xff, outfile);
+ ptr2++;
+ }
+ }
+ }
+
+ METHODDEF void
+ put_gray_raw_word_rows (decompress_info_ptr cinfo, int num_rows,
+ JSAMPIMAGE pixel_data)
+ {
+ register FILE * outfile = cinfo->output_file;
+ register JSAMPROW ptr0;
+ register long col;
+ long width = cinfo->image_width;
+ int row;
+
+ for (row = 0; row < num_rows; row++) {
+ ptr0 = pixel_data[0][row];
+ for (col = width; col > 0; col--) {
+ JSAMPLE value;
+ value=GETJSAMPLE(*ptr0);
+ putc(value&0xff, outfile);
+ putc((value>>8)&0xff, outfile);
+ ptr0++;
+ }
+ }
+ }
+
#ifdef USE_PUTC_OUTPUT
METHODDEF void
! put_rgb_raw_byte_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
register FILE * outfile = cinfo->output_file;
***************
*** 109,115 ****
}
METHODDEF void
! put_gray_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
register FILE * outfile = cinfo->output_file;
--- 246,252 ----
}
METHODDEF void
! put_gray_raw_byte_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
register FILE * outfile = cinfo->output_file;
***************
*** 130,136 ****
#else /* use row buffering */
METHODDEF void
! put_pixel_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
FILE * outfile = cinfo->output_file;
--- 267,273 ----
#else /* use row buffering */
METHODDEF void
! put_rgb_raw_byte_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
FILE * outfile = cinfo->output_file;
***************
*** 155,161 ****
}
METHODDEF void
! put_gray_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
FILE * outfile = cinfo->output_file;
--- 292,298 ----
}
METHODDEF void
! put_gray_raw_byte_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
FILE * outfile = cinfo->output_file;
***************
*** 182,191 ****
* Write some pixel data when color quantization is in effect.
*/
#ifdef USE_PUTC_OUTPUT
METHODDEF void
! put_demapped_rgb (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
register FILE * outfile = cinfo->output_file;
--- 319,430 ----
* Write some pixel data when color quantization is in effect.
*/
+ METHODDEF void
+ put_demapped_rgb_text_rows (decompress_info_ptr cinfo, int num_rows,
+ JSAMPIMAGE pixel_data)
+ {
+ register FILE * outfile = cinfo->output_file;
+ register JSAMPROW ptr;
+ register JSAMPROW color_map0 = cinfo->colormap[0];
+ register JSAMPROW color_map1 = cinfo->colormap[1];
+ register JSAMPROW color_map2 = cinfo->colormap[2];
+ register int pixval;
+ register long col;
+ long width = cinfo->image_width;
+ int row;
+
+ for (row = 0; row < num_rows; row++) {
+ ptr = pixel_data[0][row];
+ for (col = width; col > 0; col--) {
+ pixval = GETJSAMPLE(*ptr++);
+ fprintf(outfile,"%u\n",(unsigned)GETJSAMPLE(color_map0[pixval]));
+ fprintf(outfile,"%u\n",(unsigned)GETJSAMPLE(color_map1[pixval]));
+ fprintf(outfile,"%u\n",(unsigned)GETJSAMPLE(color_map2[pixval]));
+ }
+ }
+ }
+
+ METHODDEF void
+ put_demapped_gray_text_rows (decompress_info_ptr cinfo, int num_rows,
+ JSAMPIMAGE pixel_data)
+ {
+ register FILE * outfile = cinfo->output_file;
+ register JSAMPROW ptr;
+ register JSAMPROW color_map0 = cinfo->colormap[0];
+ register int pixval;
+ register long col;
+ long width = cinfo->image_width;
+ int row;
+
+ for (row = 0; row < num_rows; row++) {
+ ptr = pixel_data[0][row];
+ for (col = width; col > 0; col--) {
+ pixval = GETJSAMPLE(*ptr++);
+ fprintf(outfile,"%u\n",(unsigned)GETJSAMPLE(color_map0[pixval]));
+ }
+ }
+ }
+
+ METHODDEF void
+ put_demapped_rgb_raw_word_rows (decompress_info_ptr cinfo, int num_rows,
+ JSAMPIMAGE pixel_data)
+ {
+ register FILE * outfile = cinfo->output_file;
+ register JSAMPROW ptr;
+ register JSAMPROW color_map0 = cinfo->colormap[0];
+ register JSAMPROW color_map1 = cinfo->colormap[1];
+ register JSAMPROW color_map2 = cinfo->colormap[2];
+ register int pixval;
+ register long col;
+ long width = cinfo->image_width;
+ int row;
+
+ for (row = 0; row < num_rows; row++) {
+ ptr = pixel_data[0][row];
+ for (col = width; col > 0; col--) {
+ JSAMPLE value;
+ pixval = GETJSAMPLE(*ptr++);
+ value=GETJSAMPLE(color_map0[pixval]);
+ putc(value&0xff, outfile);
+ putc((value>>8)&0xff, outfile);
+ value=GETJSAMPLE(color_map1[pixval]);
+ putc(value&0xff, outfile);
+ putc((value>>8)&0xff, outfile);
+ value=GETJSAMPLE(color_map2[pixval]);
+ putc(value&0xff, outfile);
+ putc((value>>8)&0xff, outfile);
+ }
+ }
+ }
+
+ METHODDEF void
+ put_demapped_gray_raw_word_rows (decompress_info_ptr cinfo, int num_rows,
+ JSAMPIMAGE pixel_data)
+ {
+ register FILE * outfile = cinfo->output_file;
+ register JSAMPROW ptr;
+ register JSAMPROW color_map0 = cinfo->colormap[0];
+ register int pixval;
+ register long col;
+ long width = cinfo->image_width;
+ int row;
+
+ for (row = 0; row < num_rows; row++) {
+ ptr = pixel_data[0][row];
+ for (col = width; col > 0; col--) {
+ JSAMPLE value;
+ pixval = GETJSAMPLE(*ptr++);
+ value=GETJSAMPLE(color_map0[pixval]);
+ putc(value&0xff, outfile);
+ putc((value>>8)&0xff, outfile);
+ }
+ }
+ }
+
#ifdef USE_PUTC_OUTPUT
METHODDEF void
! put_demapped_rgb_raw_byte_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
register FILE * outfile = cinfo->output_file;
***************
*** 210,216 ****
}
METHODDEF void
! put_demapped_gray (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
register FILE * outfile = cinfo->output_file;
--- 449,455 ----
}
METHODDEF void
! put_demapped_gray_raw_byte_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
register FILE * outfile = cinfo->output_file;
***************
*** 233,239 ****
#else /* use row buffering */
METHODDEF void
! put_demapped_rgb (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
FILE * outfile = cinfo->output_file;
--- 472,478 ----
#else /* use row buffering */
METHODDEF void
! put_demapped_rgb_raw_byte_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
FILE * outfile = cinfo->output_file;
***************
*** 261,267 ****
}
METHODDEF void
! put_demapped_gray (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
FILE * outfile = cinfo->output_file;
--- 500,506 ----
}
METHODDEF void
! put_demapped_gray_raw_byte_rows (decompress_info_ptr cinfo, int num_rows,
JSAMPIMAGE pixel_data)
{
FILE * outfile = cinfo->output_file;
***************
*** 295,304 ****
METHODDEF void
put_color_map (decompress_info_ptr cinfo, int num_colors, JSAMPARRAY colormap)
{
! if (cinfo->out_color_space == CS_RGB)
! cinfo->methods->put_pixel_rows = put_demapped_rgb;
! else
! cinfo->methods->put_pixel_rows = put_demapped_gray;
}
--- 534,568 ----
METHODDEF void
put_color_map (decompress_info_ptr cinfo, int num_colors, JSAMPARRAY colormap)
{
! if (cinfo->out_color_space == CS_RGB) {
! #ifdef PPM_WRITETEXT
! cinfo->methods->put_pixel_rows = put_demapped_rgb_text_rows;
! #else /*PPM_WRITETEXT*/
! if (cinfo->data_precision == 8) {
! cinfo->methods->put_pixel_rows = put_demapped_rgb_raw_byte_rows;
! } else {
! #ifdef PPM_WRITERAWWORDS
! cinfo->methods->put_pixel_rows = put_demapped_rgb_raw_word_rows;
! #else /*PPM_WRITERAWWORDS*/
! cinfo->methods->put_pixel_rows = put_demapped_rgb_text_rows;
! #endif /*PPM_WRITERAWWORDS*/
! }
! #endif /*PPM_WRITETEXT*/
! } else {
! #ifdef PPM_WRITETEXT
! cinfo->methods->put_pixel_rows = put_demapped_gray_text_rows;
! #else /*PPM_WRITETEXT*/
! if (cinfo->data_precision == 8) {
! cinfo->methods->put_pixel_rows = put_demapped_gray_raw_byte_rows;
! } else {
! #ifdef PPM_WRITERAWWORDS
! cinfo->methods->put_pixel_rows = put_demapped_gray_raw_word_rows;
! #else /*PPM_WRITERAWWORDS*/
! cinfo->methods->put_pixel_rows = put_demapped_gray_text_rows;
! #endif /*PPM_WRITERAWWORDS*/
! }
! #endif /*PPM_WRITETEXT*/
! }
}
***************
*** 327,337 ****
{
cinfo->methods->output_init = output_init;
cinfo->methods->put_color_map = put_color_map;
! if (cinfo->out_color_space == CS_RGB)
! cinfo->methods->put_pixel_rows = put_pixel_rows;
! else
! cinfo->methods->put_pixel_rows = put_gray_rows;
cinfo->methods->output_term = output_term;
}
#endif /* PPM_SUPPORTED */
--- 591,631 ----
{
cinfo->methods->output_init = output_init;
cinfo->methods->put_color_map = put_color_map;
!
! if (cinfo->out_color_space == CS_RGB) {
! #ifdef PPM_WRITETEXT
! cinfo->methods->put_pixel_rows = put_rgb_text_rows;
! #else /*PPM_WRITETEXT*/
! if (cinfo->data_precision == 8) {
! cinfo->methods->put_pixel_rows = put_rgb_raw_byte_rows;
! } else {
! #ifdef PPM_WRITERAWWORDS
! cinfo->methods->put_pixel_rows = put_rgb_raw_word_rows;
! #else /*PPM_WRITERAWWORDS*/
! cinfo->methods->put_pixel_rows = put_rgb_text_rows;
! #endif /*PPM_WRITERAWWORDS*/
! }
! #endif /*PPM_WRITETEXT*/
! } else {
! #ifdef PPM_WRITETEXT
! cinfo->methods->put_pixel_rows = put_gray_text_rows;
! #else /*PPM_WRITETEXT*/
! if (cinfo->data_precision == 8) {
! cinfo->methods->put_pixel_rows = put_gray_raw_byte_rows;
! } else {
! #ifdef PPM_WRITERAWWORDS
! cinfo->methods->put_pixel_rows = put_gray_raw_word_rows;
! #else /*PPM_WRITERAWWORDS*/
! cinfo->methods->put_pixel_rows = put_gray_text_rows;
! #endif /*PPM_WRITERAWWORDS*/
! }
! #endif /*PPM_WRITETEXT*/
! }
!
cinfo->methods->output_term = output_term;
}
#endif /* PPM_SUPPORTED */
+
+
+
---
David A. Clunie (dclunie@flash.us.com)
In sunny Riyadh, Saudi Arabia.
"I must see your DICOM 3 conformance statement before I buy."
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads