hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * jccolext.c |
| 3 | * |
noel@chromium.org | 3395bcc | 2014-04-14 06:56:00 +0000 | [diff] [blame] | 4 | * This file was part of the Independent JPEG Group's software: |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 5 | * Copyright (C) 1991-1996, Thomas G. Lane. |
noel@chromium.org | 3395bcc | 2014-04-14 06:56:00 +0000 | [diff] [blame] | 6 | * libjpeg-turbo Modifications: |
Tom Hudson | 0d47d2d | 2016-05-04 13:22:56 -0400 | [diff] [blame] | 7 | * Copyright (C) 2009-2012, 2015, D. R. Commander. |
| 8 | * For conditions of distribution and use, see the accompanying README.ijg |
| 9 | * file. |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 10 | * |
| 11 | * This file contains input colorspace conversion routines. |
| 12 | */ |
| 13 | |
| 14 | |
| 15 | /* This file is included by jccolor.c */ |
| 16 | |
| 17 | |
| 18 | /* |
| 19 | * Convert some rows of samples to the JPEG colorspace. |
| 20 | * |
| 21 | * Note that we change from the application's interleaved-pixel format |
| 22 | * to our internal noninterleaved, one-plane-per-component format. |
| 23 | * The input buffer is therefore three times as wide as the output buffer. |
| 24 | * |
| 25 | * A starting row offset is provided only for the output buffer. The caller |
| 26 | * can easily adjust the passed input_buf value to accommodate any row |
| 27 | * offset required on that side. |
| 28 | */ |
| 29 | |
| 30 | INLINE |
| 31 | LOCAL(void) |
Chris Blume | cca8c4d | 2019-03-01 01:09:50 -0800 | [diff] [blame] | 32 | rgb_ycc_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf, |
| 33 | JSAMPIMAGE output_buf, JDIMENSION output_row, |
| 34 | int num_rows) |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 35 | { |
Chris Blume | cca8c4d | 2019-03-01 01:09:50 -0800 | [diff] [blame] | 36 | my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert; |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 37 | register int r, g, b; |
Chris Blume | cca8c4d | 2019-03-01 01:09:50 -0800 | [diff] [blame] | 38 | register JLONG *ctab = cconvert->rgb_ycc_tab; |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 39 | register JSAMPROW inptr; |
| 40 | register JSAMPROW outptr0, outptr1, outptr2; |
| 41 | register JDIMENSION col; |
| 42 | JDIMENSION num_cols = cinfo->image_width; |
| 43 | |
| 44 | while (--num_rows >= 0) { |
| 45 | inptr = *input_buf++; |
| 46 | outptr0 = output_buf[0][output_row]; |
| 47 | outptr1 = output_buf[1][output_row]; |
| 48 | outptr2 = output_buf[2][output_row]; |
| 49 | output_row++; |
| 50 | for (col = 0; col < num_cols; col++) { |
Jonathan Wright | bbb8282 | 2020-11-25 13:36:43 +0000 | [diff] [blame] | 51 | r = inptr[RGB_RED]; |
| 52 | g = inptr[RGB_GREEN]; |
| 53 | b = inptr[RGB_BLUE]; |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 54 | inptr += RGB_PIXELSIZE; |
| 55 | /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations |
| 56 | * must be too; we do not need an explicit range-limiting operation. |
| 57 | * Hence the value being shifted is never negative, and we don't |
| 58 | * need the general RIGHT_SHIFT macro. |
| 59 | */ |
| 60 | /* Y */ |
Chris Blume | cca8c4d | 2019-03-01 01:09:50 -0800 | [diff] [blame] | 61 | outptr0[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] + |
| 62 | ctab[b + B_Y_OFF]) >> SCALEBITS); |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 63 | /* Cb */ |
Chris Blume | cca8c4d | 2019-03-01 01:09:50 -0800 | [diff] [blame] | 64 | outptr1[col] = (JSAMPLE)((ctab[r + R_CB_OFF] + ctab[g + G_CB_OFF] + |
| 65 | ctab[b + B_CB_OFF]) >> SCALEBITS); |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 66 | /* Cr */ |
Chris Blume | cca8c4d | 2019-03-01 01:09:50 -0800 | [diff] [blame] | 67 | outptr2[col] = (JSAMPLE)((ctab[r + R_CR_OFF] + ctab[g + G_CR_OFF] + |
| 68 | ctab[b + B_CR_OFF]) >> SCALEBITS); |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | |
| 74 | /**************** Cases other than RGB -> YCbCr **************/ |
| 75 | |
| 76 | |
| 77 | /* |
| 78 | * Convert some rows of samples to the JPEG colorspace. |
| 79 | * This version handles RGB->grayscale conversion, which is the same |
| 80 | * as the RGB->Y portion of RGB->YCbCr. |
| 81 | * We assume rgb_ycc_start has been called (we only use the Y tables). |
| 82 | */ |
| 83 | |
| 84 | INLINE |
| 85 | LOCAL(void) |
Chris Blume | cca8c4d | 2019-03-01 01:09:50 -0800 | [diff] [blame] | 86 | rgb_gray_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf, |
| 87 | JSAMPIMAGE output_buf, JDIMENSION output_row, |
| 88 | int num_rows) |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 89 | { |
Chris Blume | cca8c4d | 2019-03-01 01:09:50 -0800 | [diff] [blame] | 90 | my_cconvert_ptr cconvert = (my_cconvert_ptr)cinfo->cconvert; |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 91 | register int r, g, b; |
Chris Blume | cca8c4d | 2019-03-01 01:09:50 -0800 | [diff] [blame] | 92 | register JLONG *ctab = cconvert->rgb_ycc_tab; |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 93 | register JSAMPROW inptr; |
| 94 | register JSAMPROW outptr; |
| 95 | register JDIMENSION col; |
| 96 | JDIMENSION num_cols = cinfo->image_width; |
| 97 | |
| 98 | while (--num_rows >= 0) { |
| 99 | inptr = *input_buf++; |
| 100 | outptr = output_buf[0][output_row]; |
| 101 | output_row++; |
| 102 | for (col = 0; col < num_cols; col++) { |
Jonathan Wright | bbb8282 | 2020-11-25 13:36:43 +0000 | [diff] [blame] | 103 | r = inptr[RGB_RED]; |
| 104 | g = inptr[RGB_GREEN]; |
| 105 | b = inptr[RGB_BLUE]; |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 106 | inptr += RGB_PIXELSIZE; |
| 107 | /* Y */ |
Chris Blume | cca8c4d | 2019-03-01 01:09:50 -0800 | [diff] [blame] | 108 | outptr[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] + |
| 109 | ctab[b + B_Y_OFF]) >> SCALEBITS); |
hbono@chromium.org | c6beb74 | 2011-11-29 05:16:26 +0000 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | } |
hbono@chromium.org | df5ffdd | 2012-05-11 07:46:03 +0000 | [diff] [blame] | 113 | |
| 114 | |
| 115 | /* |
| 116 | * Convert some rows of samples to the JPEG colorspace. |
| 117 | * This version handles extended RGB->plain RGB conversion |
| 118 | */ |
| 119 | |
| 120 | INLINE |
| 121 | LOCAL(void) |
Chris Blume | cca8c4d | 2019-03-01 01:09:50 -0800 | [diff] [blame] | 122 | rgb_rgb_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf, |
| 123 | JSAMPIMAGE output_buf, JDIMENSION output_row, |
| 124 | int num_rows) |
hbono@chromium.org | df5ffdd | 2012-05-11 07:46:03 +0000 | [diff] [blame] | 125 | { |
| 126 | register JSAMPROW inptr; |
| 127 | register JSAMPROW outptr0, outptr1, outptr2; |
| 128 | register JDIMENSION col; |
| 129 | JDIMENSION num_cols = cinfo->image_width; |
| 130 | |
| 131 | while (--num_rows >= 0) { |
| 132 | inptr = *input_buf++; |
| 133 | outptr0 = output_buf[0][output_row]; |
| 134 | outptr1 = output_buf[1][output_row]; |
| 135 | outptr2 = output_buf[2][output_row]; |
| 136 | output_row++; |
| 137 | for (col = 0; col < num_cols; col++) { |
Jonathan Wright | bbb8282 | 2020-11-25 13:36:43 +0000 | [diff] [blame] | 138 | outptr0[col] = inptr[RGB_RED]; |
| 139 | outptr1[col] = inptr[RGB_GREEN]; |
| 140 | outptr2[col] = inptr[RGB_BLUE]; |
hbono@chromium.org | df5ffdd | 2012-05-11 07:46:03 +0000 | [diff] [blame] | 141 | inptr += RGB_PIXELSIZE; |
| 142 | } |
| 143 | } |
| 144 | } |