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