1 : /*
2 : * jccolext.c
3 : *
4 : * Copyright (C) 1991-1996, 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 input colorspace conversion routines.
10 : */
11 :
12 :
13 : /* This file is included by jccolor.c */
14 :
15 :
16 : /*
17 : * Convert some rows of samples to the JPEG colorspace.
18 : *
19 : * Note that we change from the application's interleaved-pixel format
20 : * to our internal noninterleaved, one-plane-per-component format.
21 : * The input buffer is therefore three times as wide as the output buffer.
22 : *
23 : * A starting row offset is provided only for the output buffer. The caller
24 : * can easily adjust the passed input_buf value to accommodate any row
25 : * offset required on that side.
26 : */
27 :
28 : INLINE
29 : LOCAL(void)
30 0 : rgb_ycc_convert_internal (j_compress_ptr cinfo,
31 : JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
32 : JDIMENSION output_row, int num_rows)
33 : {
34 0 : my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
35 : register int r, g, b;
36 0 : register INT32 * ctab = cconvert->rgb_ycc_tab;
37 : register JSAMPROW inptr;
38 : register JSAMPROW outptr0, outptr1, outptr2;
39 : register JDIMENSION col;
40 0 : JDIMENSION num_cols = cinfo->image_width;
41 :
42 0 : while (--num_rows >= 0) {
43 0 : inptr = *input_buf++;
44 0 : outptr0 = output_buf[0][output_row];
45 0 : outptr1 = output_buf[1][output_row];
46 0 : outptr2 = output_buf[2][output_row];
47 0 : output_row++;
48 0 : for (col = 0; col < num_cols; col++) {
49 0 : r = GETJSAMPLE(inptr[RGB_RED]);
50 0 : g = GETJSAMPLE(inptr[RGB_GREEN]);
51 0 : b = GETJSAMPLE(inptr[RGB_BLUE]);
52 0 : inptr += RGB_PIXELSIZE;
53 : /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
54 : * must be too; we do not need an explicit range-limiting operation.
55 : * Hence the value being shifted is never negative, and we don't
56 : * need the general RIGHT_SHIFT macro.
57 : */
58 : /* Y */
59 0 : outptr0[col] = (JSAMPLE)
60 0 : ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
61 0 : >> SCALEBITS);
62 : /* Cb */
63 0 : outptr1[col] = (JSAMPLE)
64 0 : ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
65 0 : >> SCALEBITS);
66 : /* Cr */
67 0 : outptr2[col] = (JSAMPLE)
68 0 : ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
69 0 : >> SCALEBITS);
70 : }
71 : }
72 0 : }
73 :
74 :
75 : /**************** Cases other than RGB -> YCbCr **************/
76 :
77 :
78 : /*
79 : * Convert some rows of samples to the JPEG colorspace.
80 : * This version handles RGB->grayscale conversion, which is the same
81 : * as the RGB->Y portion of RGB->YCbCr.
82 : * We assume rgb_ycc_start has been called (we only use the Y tables).
83 : */
84 :
85 : INLINE
86 : LOCAL(void)
87 0 : rgb_gray_convert_internal (j_compress_ptr cinfo,
88 : JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
89 : JDIMENSION output_row, int num_rows)
90 : {
91 0 : my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
92 : register int r, g, b;
93 0 : register INT32 * ctab = cconvert->rgb_ycc_tab;
94 : register JSAMPROW inptr;
95 : register JSAMPROW outptr;
96 : register JDIMENSION col;
97 0 : JDIMENSION num_cols = cinfo->image_width;
98 :
99 0 : while (--num_rows >= 0) {
100 0 : inptr = *input_buf++;
101 0 : outptr = output_buf[0][output_row];
102 0 : output_row++;
103 0 : for (col = 0; col < num_cols; col++) {
104 0 : r = GETJSAMPLE(inptr[RGB_RED]);
105 0 : g = GETJSAMPLE(inptr[RGB_GREEN]);
106 0 : b = GETJSAMPLE(inptr[RGB_BLUE]);
107 0 : inptr += RGB_PIXELSIZE;
108 : /* Y */
109 0 : outptr[col] = (JSAMPLE)
110 0 : ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
111 0 : >> SCALEBITS);
112 : }
113 : }
114 0 : }
|