Lines Matching +full:- +full:- +full:source
5 * Copyright (C) 1991-1997, Thomas G. Lane.
7 * libjpeg-turbo Modifications:
8 * Copyright (C) 2015-2017, 2020-2021, D. R. Commander.
13 * The extended 2-byte-per-sample raw PPM/PGM formats are supported.
17 * These routines may need modification for non-Unix environments or
54 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
58 /* Private version of data source object */
67 JSAMPLE *rescale; /* => maxval-remapping array, or NULL */
95 /* Note that on a 16-bit-int machine, only values up to 64k can be read. */ in read_pbm_integer()
111 val = ch - '0'; in read_pbm_integer()
114 val += ch - '0'; in read_pbm_integer()
130 * maxval = MAXJSAMPLE, which is the normal case for 8-bit data.
136 /* This version is for reading text-format PGM files with any maxval */ in get_text_gray_row()
138 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_text_gray_row() local
139 FILE *infile = source->pub.input_file; in get_text_gray_row()
141 register JSAMPLE *rescale = source->rescale; in get_text_gray_row()
143 unsigned int maxval = source->maxval; in get_text_gray_row()
145 ptr = source->pub.buffer[0]; in get_text_gray_row()
146 for (col = cinfo->image_width; col > 0; col--) { in get_text_gray_row()
154 for (col = cinfo->image_width; col > 0; col--) { \
163 /* This version is for reading text-format PGM files with any maxval and in get_text_gray_rgb_row()
166 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_text_gray_rgb_row() local
167 FILE *infile = source->pub.input_file; in get_text_gray_rgb_row()
169 register JSAMPLE *rescale = source->rescale; in get_text_gray_rgb_row()
171 unsigned int maxval = source->maxval; in get_text_gray_rgb_row()
172 register int rindex = rgb_red[cinfo->in_color_space]; in get_text_gray_rgb_row()
173 register int gindex = rgb_green[cinfo->in_color_space]; in get_text_gray_rgb_row()
174 register int bindex = rgb_blue[cinfo->in_color_space]; in get_text_gray_rgb_row()
175 register int aindex = alpha_index[cinfo->in_color_space]; in get_text_gray_rgb_row()
176 register int ps = rgb_pixelsize[cinfo->in_color_space]; in get_text_gray_rgb_row()
178 ptr = source->pub.buffer[0]; in get_text_gray_rgb_row()
198 /* This version is for reading text-format PGM files with any maxval and in get_text_gray_cmyk_row()
201 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_text_gray_cmyk_row() local
202 FILE *infile = source->pub.input_file; in get_text_gray_cmyk_row()
204 register JSAMPLE *rescale = source->rescale; in get_text_gray_cmyk_row()
206 unsigned int maxval = source->maxval; in get_text_gray_cmyk_row()
208 ptr = source->pub.buffer[0]; in get_text_gray_cmyk_row()
210 for (col = cinfo->image_width; col > 0; col--) { in get_text_gray_cmyk_row()
216 for (col = cinfo->image_width; col > 0; col--) { in get_text_gray_cmyk_row()
227 for (col = cinfo->image_width; col > 0; col--) { \
238 /* This version is for reading text-format PPM files with any maxval */ in get_text_rgb_row()
240 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_text_rgb_row() local
241 FILE *infile = source->pub.input_file; in get_text_rgb_row()
243 register JSAMPLE *rescale = source->rescale; in get_text_rgb_row()
245 unsigned int maxval = source->maxval; in get_text_rgb_row()
246 register int rindex = rgb_red[cinfo->in_color_space]; in get_text_rgb_row()
247 register int gindex = rgb_green[cinfo->in_color_space]; in get_text_rgb_row()
248 register int bindex = rgb_blue[cinfo->in_color_space]; in get_text_rgb_row()
249 register int aindex = alpha_index[cinfo->in_color_space]; in get_text_rgb_row()
250 register int ps = rgb_pixelsize[cinfo->in_color_space]; in get_text_rgb_row()
252 ptr = source->pub.buffer[0]; in get_text_rgb_row()
272 /* This version is for reading text-format PPM files with any maxval and in get_text_rgb_cmyk_row()
275 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_text_rgb_cmyk_row() local
276 FILE *infile = source->pub.input_file; in get_text_rgb_cmyk_row()
278 register JSAMPLE *rescale = source->rescale; in get_text_rgb_cmyk_row()
280 unsigned int maxval = source->maxval; in get_text_rgb_cmyk_row()
282 ptr = source->pub.buffer[0]; in get_text_rgb_cmyk_row()
284 for (col = cinfo->image_width; col > 0; col--) { in get_text_rgb_cmyk_row()
292 for (col = cinfo->image_width; col > 0; col--) { in get_text_rgb_cmyk_row()
306 /* This version is for reading raw-byte-format PGM files with any maxval */ in get_scaled_gray_row()
308 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_scaled_gray_row() local
311 register JSAMPLE *rescale = source->rescale; in get_scaled_gray_row()
314 if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) in get_scaled_gray_row()
316 ptr = source->pub.buffer[0]; in get_scaled_gray_row()
317 bufferptr = source->iobuffer; in get_scaled_gray_row()
318 for (col = cinfo->image_width; col > 0; col--) { in get_scaled_gray_row()
327 /* This version is for reading raw-byte-format PGM files with any maxval in get_gray_rgb_row()
330 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_gray_rgb_row() local
333 register JSAMPLE *rescale = source->rescale; in get_gray_rgb_row()
335 unsigned int maxval = source->maxval; in get_gray_rgb_row()
336 register int rindex = rgb_red[cinfo->in_color_space]; in get_gray_rgb_row()
337 register int gindex = rgb_green[cinfo->in_color_space]; in get_gray_rgb_row()
338 register int bindex = rgb_blue[cinfo->in_color_space]; in get_gray_rgb_row()
339 register int aindex = alpha_index[cinfo->in_color_space]; in get_gray_rgb_row()
340 register int ps = rgb_pixelsize[cinfo->in_color_space]; in get_gray_rgb_row()
342 if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) in get_gray_rgb_row()
344 ptr = source->pub.buffer[0]; in get_gray_rgb_row()
345 bufferptr = source->iobuffer; in get_gray_rgb_row()
363 /* This version is for reading raw-byte-format PGM files with any maxval in get_gray_cmyk_row()
366 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_gray_cmyk_row() local
369 register JSAMPLE *rescale = source->rescale; in get_gray_cmyk_row()
371 unsigned int maxval = source->maxval; in get_gray_cmyk_row()
373 if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) in get_gray_cmyk_row()
375 ptr = source->pub.buffer[0]; in get_gray_cmyk_row()
376 bufferptr = source->iobuffer; in get_gray_cmyk_row()
378 for (col = cinfo->image_width; col > 0; col--) { in get_gray_cmyk_row()
384 for (col = cinfo->image_width; col > 0; col--) { in get_gray_cmyk_row()
396 /* This version is for reading raw-byte-format PPM files with any maxval */ in get_rgb_row()
398 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_rgb_row() local
401 register JSAMPLE *rescale = source->rescale; in get_rgb_row()
403 unsigned int maxval = source->maxval; in get_rgb_row()
404 register int rindex = rgb_red[cinfo->in_color_space]; in get_rgb_row()
405 register int gindex = rgb_green[cinfo->in_color_space]; in get_rgb_row()
406 register int bindex = rgb_blue[cinfo->in_color_space]; in get_rgb_row()
407 register int aindex = alpha_index[cinfo->in_color_space]; in get_rgb_row()
408 register int ps = rgb_pixelsize[cinfo->in_color_space]; in get_rgb_row()
410 if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) in get_rgb_row()
412 ptr = source->pub.buffer[0]; in get_rgb_row()
413 bufferptr = source->iobuffer; in get_rgb_row()
431 /* This version is for reading raw-byte-format PPM files with any maxval and in get_rgb_cmyk_row()
434 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_rgb_cmyk_row() local
437 register JSAMPLE *rescale = source->rescale; in get_rgb_cmyk_row()
439 unsigned int maxval = source->maxval; in get_rgb_cmyk_row()
441 if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) in get_rgb_cmyk_row()
443 ptr = source->pub.buffer[0]; in get_rgb_cmyk_row()
444 bufferptr = source->iobuffer; in get_rgb_cmyk_row()
446 for (col = cinfo->image_width; col > 0; col--) { in get_rgb_cmyk_row()
454 for (col = cinfo->image_width; col > 0; col--) { in get_rgb_cmyk_row()
468 /* This version is for reading raw-byte-format files with maxval = MAXJSAMPLE. in get_raw_row()
473 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_raw_row() local
475 if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) in get_raw_row()
483 /* This version is for reading raw-word-format PGM files with any maxval */ in get_word_gray_row()
485 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_word_gray_row() local
488 register JSAMPLE *rescale = source->rescale; in get_word_gray_row()
490 unsigned int maxval = source->maxval; in get_word_gray_row()
492 if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) in get_word_gray_row()
494 ptr = source->pub.buffer[0]; in get_word_gray_row()
495 bufferptr = source->iobuffer; in get_word_gray_row()
496 for (col = cinfo->image_width; col > 0; col--) { in get_word_gray_row()
510 /* This version is for reading raw-word-format PPM files with any maxval */ in get_word_rgb_row()
512 ppm_source_ptr source = (ppm_source_ptr)sinfo; in get_word_rgb_row() local
515 register JSAMPLE *rescale = source->rescale; in get_word_rgb_row()
517 unsigned int maxval = source->maxval; in get_word_rgb_row()
518 register int rindex = rgb_red[cinfo->in_color_space]; in get_word_rgb_row()
519 register int gindex = rgb_green[cinfo->in_color_space]; in get_word_rgb_row()
520 register int bindex = rgb_blue[cinfo->in_color_space]; in get_word_rgb_row()
521 register int aindex = alpha_index[cinfo->in_color_space]; in get_word_rgb_row()
522 register int ps = rgb_pixelsize[cinfo->in_color_space]; in get_word_rgb_row()
524 if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) in get_word_rgb_row()
526 ptr = source->pub.buffer[0]; in get_word_rgb_row()
527 bufferptr = source->iobuffer; in get_word_rgb_row()
528 for (col = cinfo->image_width; col > 0; col--) { in get_word_rgb_row()
560 ppm_source_ptr source = (ppm_source_ptr)sinfo; local
565 if (getc(source->pub.input_file) != 'P')
568 c = getc(source->pub.input_file); /* subformat discriminator character */
572 case '2': /* it's a text-format PGM file */
573 case '3': /* it's a text-format PPM file */
574 case '5': /* it's a raw-format PGM file */
575 case '6': /* it's a raw-format PPM file */
583 w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
584 h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
585 maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
590 if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
594 cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */
595 cinfo->image_width = (JDIMENSION)w;
596 cinfo->image_height = (JDIMENSION)h;
597 source->maxval = maxval;
605 case '2': /* it's a text-format PGM file */
606 if (cinfo->in_color_space == JCS_UNKNOWN)
607 cinfo->in_color_space = JCS_GRAYSCALE;
609 if (cinfo->in_color_space == JCS_GRAYSCALE)
610 source->pub.get_pixel_rows = get_text_gray_row;
611 else if (IsExtRGB(cinfo->in_color_space))
612 source->pub.get_pixel_rows = get_text_gray_rgb_row;
613 else if (cinfo->in_color_space == JCS_CMYK)
614 source->pub.get_pixel_rows = get_text_gray_cmyk_row;
620 case '3': /* it's a text-format PPM file */
621 if (cinfo->in_color_space == JCS_UNKNOWN)
622 cinfo->in_color_space = JCS_EXT_RGB;
624 if (IsExtRGB(cinfo->in_color_space))
625 source->pub.get_pixel_rows = get_text_rgb_row;
626 else if (cinfo->in_color_space == JCS_CMYK)
627 source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
633 case '5': /* it's a raw-format PGM file */
634 if (cinfo->in_color_space == JCS_UNKNOWN)
635 cinfo->in_color_space = JCS_GRAYSCALE;
638 if (cinfo->in_color_space == JCS_GRAYSCALE)
639 source->pub.get_pixel_rows = get_word_gray_row;
643 cinfo->in_color_space == JCS_GRAYSCALE) {
644 source->pub.get_pixel_rows = get_raw_row;
648 if (cinfo->in_color_space == JCS_GRAYSCALE)
649 source->pub.get_pixel_rows = get_scaled_gray_row;
650 else if (IsExtRGB(cinfo->in_color_space))
651 source->pub.get_pixel_rows = get_gray_rgb_row;
652 else if (cinfo->in_color_space == JCS_CMYK)
653 source->pub.get_pixel_rows = get_gray_cmyk_row;
659 case '6': /* it's a raw-format PPM file */
660 if (cinfo->in_color_space == JCS_UNKNOWN)
661 cinfo->in_color_space = JCS_EXT_RGB;
664 if (IsExtRGB(cinfo->in_color_space))
665 source->pub.get_pixel_rows = get_word_rgb_row;
670 (cinfo->in_color_space == JCS_EXT_RGB ||
671 cinfo->in_color_space == JCS_RGB)) {
673 cinfo->in_color_space == JCS_EXT_RGB) {
675 source->pub.get_pixel_rows = get_raw_row;
679 if (IsExtRGB(cinfo->in_color_space))
680 source->pub.get_pixel_rows = get_rgb_row;
681 else if (cinfo->in_color_space == JCS_CMYK)
682 source->pub.get_pixel_rows = get_rgb_cmyk_row;
689 if (IsExtRGB(cinfo->in_color_space))
690 cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
691 else if (cinfo->in_color_space == JCS_GRAYSCALE)
692 cinfo->input_components = 1;
693 else if (cinfo->in_color_space == JCS_CMYK)
694 cinfo->input_components = 4;
699 source->buffer_width = (size_t)w * 3 *
702 source->buffer_width = (size_t)w *
704 source->iobuffer = (U_CHAR *)
705 (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
706 source->buffer_width);
711 /* For unscaled raw-input case, we can just map it onto the I/O buffer. */
713 source->pixrow = (JSAMPROW)source->iobuffer;
714 source->pub.buffer = &source->pixrow;
715 source->pub.buffer_height = 1;
718 source->pub.buffer = (*cinfo->mem->alloc_sarray)
720 (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
721 source->pub.buffer_height = 1;
728 /* On 16-bit-int machines we have to be careful of maxval = 65535 */
729 source->rescale = (JSAMPLE *)
730 (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
733 MEMZERO(source->rescale, (size_t)(((long)MAX(maxval, 255) + 1L) *
738 source->rescale[val] = (JSAMPLE)((val * MAXJSAMPLE + half_maxval) /
763 ppm_source_ptr source; local
766 source = (ppm_source_ptr)
767 (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
770 source->pub.start_input = start_input_ppm;
771 source->pub.finish_input = finish_input_ppm;
773 source->pub.max_pixels = 0;
776 return (cjpeg_source_ptr)source;