DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * jdcolext.c |
| 3 | * |
| 4 | * Copyright (C) 1991-1997, Thomas G. Lane. |
| 5 | * Copyright (C) 2009, 2011, D. R. Commander. |
| 6 | * This file is part of the Independent JPEG Group's software. |
| 7 | * For conditions of distribution and use, see the accompanying README file. |
| 8 | * |
| 9 | * This file contains output colorspace conversion routines. |
| 10 | */ |
| 11 | |
| 12 | |
| 13 | /* This file is included by jdcolor.c */ |
| 14 | |
| 15 | |
| 16 | /* |
| 17 | * Convert some rows of samples to the output colorspace. |
| 18 | * |
| 19 | * Note that we change from noninterleaved, one-plane-per-component format |
| 20 | * to interleaved-pixel format. The output buffer is therefore three times |
| 21 | * as wide as the input buffer. |
| 22 | * A starting row offset is provided only for the input buffer. The caller |
| 23 | * can easily adjust the passed output_buf value to accommodate any row |
| 24 | * offset required on that side. |
| 25 | */ |
| 26 | |
| 27 | INLINE |
| 28 | LOCAL(void) |
| 29 | ycc_rgb_convert_internal (j_decompress_ptr cinfo, |
| 30 | JSAMPIMAGE input_buf, JDIMENSION input_row, |
| 31 | JSAMPARRAY output_buf, int num_rows) |
| 32 | { |
| 33 | my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
| 34 | register int y, cb, cr; |
| 35 | register JSAMPROW outptr; |
| 36 | register JSAMPROW inptr0, inptr1, inptr2; |
| 37 | register JDIMENSION col; |
| 38 | JDIMENSION num_cols = cinfo->output_width; |
| 39 | /* copy these pointers into registers if possible */ |
| 40 | register JSAMPLE * range_limit = cinfo->sample_range_limit; |
| 41 | register int * Crrtab = cconvert->Cr_r_tab; |
| 42 | register int * Cbbtab = cconvert->Cb_b_tab; |
| 43 | register INT32 * Crgtab = cconvert->Cr_g_tab; |
| 44 | register INT32 * Cbgtab = cconvert->Cb_g_tab; |
| 45 | SHIFT_TEMPS |
| 46 | |
| 47 | while (--num_rows >= 0) { |
| 48 | inptr0 = input_buf[0][input_row]; |
| 49 | inptr1 = input_buf[1][input_row]; |
| 50 | inptr2 = input_buf[2][input_row]; |
| 51 | input_row++; |
| 52 | outptr = *output_buf++; |
| 53 | for (col = 0; col < num_cols; col++) { |
| 54 | y = GETJSAMPLE(inptr0[col]); |
| 55 | cb = GETJSAMPLE(inptr1[col]); |
| 56 | cr = GETJSAMPLE(inptr2[col]); |
| 57 | /* Range-limiting is essential due to noise introduced by DCT losses. */ |
| 58 | outptr[RGB_RED] = range_limit[y + Crrtab[cr]]; |
| 59 | outptr[RGB_GREEN] = range_limit[y + |
| 60 | ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], |
| 61 | SCALEBITS))]; |
| 62 | outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]]; |
DRC | d89e01f | 2011-09-09 18:15:53 +0000 | [diff] [blame] | 63 | /* Set unused byte to 0xFF so it can be interpreted as an opaque */ |
| 64 | /* alpha channel value */ |
| 65 | #ifdef RGB_ALPHA |
| 66 | outptr[RGB_ALPHA] = 0xFF; |
| 67 | #endif |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 68 | outptr += RGB_PIXELSIZE; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | |
| 74 | /* |
| 75 | * Convert grayscale to RGB: just duplicate the graylevel three times. |
| 76 | * This is provided to support applications that don't want to cope |
| 77 | * with grayscale as a separate case. |
| 78 | */ |
| 79 | |
| 80 | INLINE |
| 81 | LOCAL(void) |
| 82 | gray_rgb_convert_internal (j_decompress_ptr cinfo, |
| 83 | JSAMPIMAGE input_buf, JDIMENSION input_row, |
| 84 | JSAMPARRAY output_buf, int num_rows) |
| 85 | { |
| 86 | register JSAMPROW inptr, outptr; |
| 87 | register JDIMENSION col; |
| 88 | JDIMENSION num_cols = cinfo->output_width; |
| 89 | |
| 90 | while (--num_rows >= 0) { |
| 91 | inptr = input_buf[0][input_row++]; |
| 92 | outptr = *output_buf++; |
| 93 | for (col = 0; col < num_cols; col++) { |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 94 | /* We can dispense with GETJSAMPLE() here */ |
| 95 | outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col]; |
DRC | d89e01f | 2011-09-09 18:15:53 +0000 | [diff] [blame] | 96 | /* Set unused byte to 0xFF so it can be interpreted as an opaque */ |
| 97 | /* alpha channel value */ |
| 98 | #ifdef RGB_ALPHA |
| 99 | outptr[RGB_ALPHA] = 0xFF; |
| 100 | #endif |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 101 | outptr += RGB_PIXELSIZE; |
| 102 | } |
| 103 | } |
| 104 | } |