Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * jdmerge.c |
michael@0 | 3 | * |
michael@0 | 4 | * This file was part of the Independent JPEG Group's software: |
michael@0 | 5 | * Copyright (C) 1994-1996, Thomas G. Lane. |
michael@0 | 6 | * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
michael@0 | 7 | * libjpeg-turbo Modifications: |
michael@0 | 8 | * Copyright (C) 2009, 2011, D. R. Commander. |
michael@0 | 9 | * For conditions of distribution and use, see the accompanying README file. |
michael@0 | 10 | * |
michael@0 | 11 | * This file contains code for merged upsampling/color conversion. |
michael@0 | 12 | * |
michael@0 | 13 | * This file combines functions from jdsample.c and jdcolor.c; |
michael@0 | 14 | * read those files first to understand what's going on. |
michael@0 | 15 | * |
michael@0 | 16 | * When the chroma components are to be upsampled by simple replication |
michael@0 | 17 | * (ie, box filtering), we can save some work in color conversion by |
michael@0 | 18 | * calculating all the output pixels corresponding to a pair of chroma |
michael@0 | 19 | * samples at one time. In the conversion equations |
michael@0 | 20 | * R = Y + K1 * Cr |
michael@0 | 21 | * G = Y + K2 * Cb + K3 * Cr |
michael@0 | 22 | * B = Y + K4 * Cb |
michael@0 | 23 | * only the Y term varies among the group of pixels corresponding to a pair |
michael@0 | 24 | * of chroma samples, so the rest of the terms can be calculated just once. |
michael@0 | 25 | * At typical sampling ratios, this eliminates half or three-quarters of the |
michael@0 | 26 | * multiplications needed for color conversion. |
michael@0 | 27 | * |
michael@0 | 28 | * This file currently provides implementations for the following cases: |
michael@0 | 29 | * YCbCr => RGB color conversion only. |
michael@0 | 30 | * Sampling ratios of 2h1v or 2h2v. |
michael@0 | 31 | * No scaling needed at upsample time. |
michael@0 | 32 | * Corner-aligned (non-CCIR601) sampling alignment. |
michael@0 | 33 | * Other special cases could be added, but in most applications these are |
michael@0 | 34 | * the only common cases. (For uncommon cases we fall back on the more |
michael@0 | 35 | * general code in jdsample.c and jdcolor.c.) |
michael@0 | 36 | */ |
michael@0 | 37 | |
michael@0 | 38 | #define JPEG_INTERNALS |
michael@0 | 39 | #include "jinclude.h" |
michael@0 | 40 | #include "jpeglib.h" |
michael@0 | 41 | #include "jsimd.h" |
michael@0 | 42 | #include "config.h" |
michael@0 | 43 | |
michael@0 | 44 | #ifdef UPSAMPLE_MERGING_SUPPORTED |
michael@0 | 45 | |
michael@0 | 46 | |
michael@0 | 47 | /* Private subobject */ |
michael@0 | 48 | |
michael@0 | 49 | typedef struct { |
michael@0 | 50 | struct jpeg_upsampler pub; /* public fields */ |
michael@0 | 51 | |
michael@0 | 52 | /* Pointer to routine to do actual upsampling/conversion of one row group */ |
michael@0 | 53 | JMETHOD(void, upmethod, (j_decompress_ptr cinfo, |
michael@0 | 54 | JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, |
michael@0 | 55 | JSAMPARRAY output_buf)); |
michael@0 | 56 | |
michael@0 | 57 | /* Private state for YCC->RGB conversion */ |
michael@0 | 58 | int * Cr_r_tab; /* => table for Cr to R conversion */ |
michael@0 | 59 | int * Cb_b_tab; /* => table for Cb to B conversion */ |
michael@0 | 60 | INT32 * Cr_g_tab; /* => table for Cr to G conversion */ |
michael@0 | 61 | INT32 * Cb_g_tab; /* => table for Cb to G conversion */ |
michael@0 | 62 | |
michael@0 | 63 | /* For 2:1 vertical sampling, we produce two output rows at a time. |
michael@0 | 64 | * We need a "spare" row buffer to hold the second output row if the |
michael@0 | 65 | * application provides just a one-row buffer; we also use the spare |
michael@0 | 66 | * to discard the dummy last row if the image height is odd. |
michael@0 | 67 | */ |
michael@0 | 68 | JSAMPROW spare_row; |
michael@0 | 69 | boolean spare_full; /* T if spare buffer is occupied */ |
michael@0 | 70 | |
michael@0 | 71 | JDIMENSION out_row_width; /* samples per output row */ |
michael@0 | 72 | JDIMENSION rows_to_go; /* counts rows remaining in image */ |
michael@0 | 73 | } my_upsampler; |
michael@0 | 74 | |
michael@0 | 75 | typedef my_upsampler * my_upsample_ptr; |
michael@0 | 76 | |
michael@0 | 77 | #define SCALEBITS 16 /* speediest right-shift on some machines */ |
michael@0 | 78 | #define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) |
michael@0 | 79 | #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) |
michael@0 | 80 | |
michael@0 | 81 | |
michael@0 | 82 | /* Include inline routines for colorspace extensions */ |
michael@0 | 83 | |
michael@0 | 84 | #include "jdmrgext.c" |
michael@0 | 85 | #undef RGB_RED |
michael@0 | 86 | #undef RGB_GREEN |
michael@0 | 87 | #undef RGB_BLUE |
michael@0 | 88 | #undef RGB_PIXELSIZE |
michael@0 | 89 | |
michael@0 | 90 | #define RGB_RED EXT_RGB_RED |
michael@0 | 91 | #define RGB_GREEN EXT_RGB_GREEN |
michael@0 | 92 | #define RGB_BLUE EXT_RGB_BLUE |
michael@0 | 93 | #define RGB_PIXELSIZE EXT_RGB_PIXELSIZE |
michael@0 | 94 | #define h2v1_merged_upsample_internal extrgb_h2v1_merged_upsample_internal |
michael@0 | 95 | #define h2v2_merged_upsample_internal extrgb_h2v2_merged_upsample_internal |
michael@0 | 96 | #include "jdmrgext.c" |
michael@0 | 97 | #undef RGB_RED |
michael@0 | 98 | #undef RGB_GREEN |
michael@0 | 99 | #undef RGB_BLUE |
michael@0 | 100 | #undef RGB_PIXELSIZE |
michael@0 | 101 | #undef h2v1_merged_upsample_internal |
michael@0 | 102 | #undef h2v2_merged_upsample_internal |
michael@0 | 103 | |
michael@0 | 104 | #define RGB_RED EXT_RGBX_RED |
michael@0 | 105 | #define RGB_GREEN EXT_RGBX_GREEN |
michael@0 | 106 | #define RGB_BLUE EXT_RGBX_BLUE |
michael@0 | 107 | #define RGB_ALPHA 3 |
michael@0 | 108 | #define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE |
michael@0 | 109 | #define h2v1_merged_upsample_internal extrgbx_h2v1_merged_upsample_internal |
michael@0 | 110 | #define h2v2_merged_upsample_internal extrgbx_h2v2_merged_upsample_internal |
michael@0 | 111 | #include "jdmrgext.c" |
michael@0 | 112 | #undef RGB_RED |
michael@0 | 113 | #undef RGB_GREEN |
michael@0 | 114 | #undef RGB_BLUE |
michael@0 | 115 | #undef RGB_ALPHA |
michael@0 | 116 | #undef RGB_PIXELSIZE |
michael@0 | 117 | #undef h2v1_merged_upsample_internal |
michael@0 | 118 | #undef h2v2_merged_upsample_internal |
michael@0 | 119 | |
michael@0 | 120 | #define RGB_RED EXT_BGR_RED |
michael@0 | 121 | #define RGB_GREEN EXT_BGR_GREEN |
michael@0 | 122 | #define RGB_BLUE EXT_BGR_BLUE |
michael@0 | 123 | #define RGB_PIXELSIZE EXT_BGR_PIXELSIZE |
michael@0 | 124 | #define h2v1_merged_upsample_internal extbgr_h2v1_merged_upsample_internal |
michael@0 | 125 | #define h2v2_merged_upsample_internal extbgr_h2v2_merged_upsample_internal |
michael@0 | 126 | #include "jdmrgext.c" |
michael@0 | 127 | #undef RGB_RED |
michael@0 | 128 | #undef RGB_GREEN |
michael@0 | 129 | #undef RGB_BLUE |
michael@0 | 130 | #undef RGB_PIXELSIZE |
michael@0 | 131 | #undef h2v1_merged_upsample_internal |
michael@0 | 132 | #undef h2v2_merged_upsample_internal |
michael@0 | 133 | |
michael@0 | 134 | #define RGB_RED EXT_BGRX_RED |
michael@0 | 135 | #define RGB_GREEN EXT_BGRX_GREEN |
michael@0 | 136 | #define RGB_BLUE EXT_BGRX_BLUE |
michael@0 | 137 | #define RGB_ALPHA 3 |
michael@0 | 138 | #define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE |
michael@0 | 139 | #define h2v1_merged_upsample_internal extbgrx_h2v1_merged_upsample_internal |
michael@0 | 140 | #define h2v2_merged_upsample_internal extbgrx_h2v2_merged_upsample_internal |
michael@0 | 141 | #include "jdmrgext.c" |
michael@0 | 142 | #undef RGB_RED |
michael@0 | 143 | #undef RGB_GREEN |
michael@0 | 144 | #undef RGB_BLUE |
michael@0 | 145 | #undef RGB_ALPHA |
michael@0 | 146 | #undef RGB_PIXELSIZE |
michael@0 | 147 | #undef h2v1_merged_upsample_internal |
michael@0 | 148 | #undef h2v2_merged_upsample_internal |
michael@0 | 149 | |
michael@0 | 150 | #define RGB_RED EXT_XBGR_RED |
michael@0 | 151 | #define RGB_GREEN EXT_XBGR_GREEN |
michael@0 | 152 | #define RGB_BLUE EXT_XBGR_BLUE |
michael@0 | 153 | #define RGB_ALPHA 0 |
michael@0 | 154 | #define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE |
michael@0 | 155 | #define h2v1_merged_upsample_internal extxbgr_h2v1_merged_upsample_internal |
michael@0 | 156 | #define h2v2_merged_upsample_internal extxbgr_h2v2_merged_upsample_internal |
michael@0 | 157 | #include "jdmrgext.c" |
michael@0 | 158 | #undef RGB_RED |
michael@0 | 159 | #undef RGB_GREEN |
michael@0 | 160 | #undef RGB_BLUE |
michael@0 | 161 | #undef RGB_ALPHA |
michael@0 | 162 | #undef RGB_PIXELSIZE |
michael@0 | 163 | #undef h2v1_merged_upsample_internal |
michael@0 | 164 | #undef h2v2_merged_upsample_internal |
michael@0 | 165 | |
michael@0 | 166 | #define RGB_RED EXT_XRGB_RED |
michael@0 | 167 | #define RGB_GREEN EXT_XRGB_GREEN |
michael@0 | 168 | #define RGB_BLUE EXT_XRGB_BLUE |
michael@0 | 169 | #define RGB_ALPHA 0 |
michael@0 | 170 | #define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE |
michael@0 | 171 | #define h2v1_merged_upsample_internal extxrgb_h2v1_merged_upsample_internal |
michael@0 | 172 | #define h2v2_merged_upsample_internal extxrgb_h2v2_merged_upsample_internal |
michael@0 | 173 | #include "jdmrgext.c" |
michael@0 | 174 | #undef RGB_RED |
michael@0 | 175 | #undef RGB_GREEN |
michael@0 | 176 | #undef RGB_BLUE |
michael@0 | 177 | #undef RGB_ALPHA |
michael@0 | 178 | #undef RGB_PIXELSIZE |
michael@0 | 179 | #undef h2v1_merged_upsample_internal |
michael@0 | 180 | #undef h2v2_merged_upsample_internal |
michael@0 | 181 | |
michael@0 | 182 | |
michael@0 | 183 | /* |
michael@0 | 184 | * Initialize tables for YCC->RGB colorspace conversion. |
michael@0 | 185 | * This is taken directly from jdcolor.c; see that file for more info. |
michael@0 | 186 | */ |
michael@0 | 187 | |
michael@0 | 188 | LOCAL(void) |
michael@0 | 189 | build_ycc_rgb_table (j_decompress_ptr cinfo) |
michael@0 | 190 | { |
michael@0 | 191 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
michael@0 | 192 | int i; |
michael@0 | 193 | INT32 x; |
michael@0 | 194 | SHIFT_TEMPS |
michael@0 | 195 | |
michael@0 | 196 | upsample->Cr_r_tab = (int *) |
michael@0 | 197 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
michael@0 | 198 | (MAXJSAMPLE+1) * SIZEOF(int)); |
michael@0 | 199 | upsample->Cb_b_tab = (int *) |
michael@0 | 200 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
michael@0 | 201 | (MAXJSAMPLE+1) * SIZEOF(int)); |
michael@0 | 202 | upsample->Cr_g_tab = (INT32 *) |
michael@0 | 203 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
michael@0 | 204 | (MAXJSAMPLE+1) * SIZEOF(INT32)); |
michael@0 | 205 | upsample->Cb_g_tab = (INT32 *) |
michael@0 | 206 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
michael@0 | 207 | (MAXJSAMPLE+1) * SIZEOF(INT32)); |
michael@0 | 208 | |
michael@0 | 209 | for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { |
michael@0 | 210 | /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ |
michael@0 | 211 | /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ |
michael@0 | 212 | /* Cr=>R value is nearest int to 1.40200 * x */ |
michael@0 | 213 | upsample->Cr_r_tab[i] = (int) |
michael@0 | 214 | RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); |
michael@0 | 215 | /* Cb=>B value is nearest int to 1.77200 * x */ |
michael@0 | 216 | upsample->Cb_b_tab[i] = (int) |
michael@0 | 217 | RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); |
michael@0 | 218 | /* Cr=>G value is scaled-up -0.71414 * x */ |
michael@0 | 219 | upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x; |
michael@0 | 220 | /* Cb=>G value is scaled-up -0.34414 * x */ |
michael@0 | 221 | /* We also add in ONE_HALF so that need not do it in inner loop */ |
michael@0 | 222 | upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; |
michael@0 | 223 | } |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | |
michael@0 | 227 | /* |
michael@0 | 228 | * Initialize for an upsampling pass. |
michael@0 | 229 | */ |
michael@0 | 230 | |
michael@0 | 231 | METHODDEF(void) |
michael@0 | 232 | start_pass_merged_upsample (j_decompress_ptr cinfo) |
michael@0 | 233 | { |
michael@0 | 234 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
michael@0 | 235 | |
michael@0 | 236 | /* Mark the spare buffer empty */ |
michael@0 | 237 | upsample->spare_full = FALSE; |
michael@0 | 238 | /* Initialize total-height counter for detecting bottom of image */ |
michael@0 | 239 | upsample->rows_to_go = cinfo->output_height; |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | |
michael@0 | 243 | /* |
michael@0 | 244 | * Control routine to do upsampling (and color conversion). |
michael@0 | 245 | * |
michael@0 | 246 | * The control routine just handles the row buffering considerations. |
michael@0 | 247 | */ |
michael@0 | 248 | |
michael@0 | 249 | METHODDEF(void) |
michael@0 | 250 | merged_2v_upsample (j_decompress_ptr cinfo, |
michael@0 | 251 | JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, |
michael@0 | 252 | JDIMENSION in_row_groups_avail, |
michael@0 | 253 | JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, |
michael@0 | 254 | JDIMENSION out_rows_avail) |
michael@0 | 255 | /* 2:1 vertical sampling case: may need a spare row. */ |
michael@0 | 256 | { |
michael@0 | 257 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
michael@0 | 258 | JSAMPROW work_ptrs[2]; |
michael@0 | 259 | JDIMENSION num_rows; /* number of rows returned to caller */ |
michael@0 | 260 | |
michael@0 | 261 | if (upsample->spare_full) { |
michael@0 | 262 | /* If we have a spare row saved from a previous cycle, just return it. */ |
michael@0 | 263 | jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0, |
michael@0 | 264 | 1, upsample->out_row_width); |
michael@0 | 265 | num_rows = 1; |
michael@0 | 266 | upsample->spare_full = FALSE; |
michael@0 | 267 | } else { |
michael@0 | 268 | /* Figure number of rows to return to caller. */ |
michael@0 | 269 | num_rows = 2; |
michael@0 | 270 | /* Not more than the distance to the end of the image. */ |
michael@0 | 271 | if (num_rows > upsample->rows_to_go) |
michael@0 | 272 | num_rows = upsample->rows_to_go; |
michael@0 | 273 | /* And not more than what the client can accept: */ |
michael@0 | 274 | out_rows_avail -= *out_row_ctr; |
michael@0 | 275 | if (num_rows > out_rows_avail) |
michael@0 | 276 | num_rows = out_rows_avail; |
michael@0 | 277 | /* Create output pointer array for upsampler. */ |
michael@0 | 278 | work_ptrs[0] = output_buf[*out_row_ctr]; |
michael@0 | 279 | if (num_rows > 1) { |
michael@0 | 280 | work_ptrs[1] = output_buf[*out_row_ctr + 1]; |
michael@0 | 281 | } else { |
michael@0 | 282 | work_ptrs[1] = upsample->spare_row; |
michael@0 | 283 | upsample->spare_full = TRUE; |
michael@0 | 284 | } |
michael@0 | 285 | /* Now do the upsampling. */ |
michael@0 | 286 | (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs); |
michael@0 | 287 | } |
michael@0 | 288 | |
michael@0 | 289 | /* Adjust counts */ |
michael@0 | 290 | *out_row_ctr += num_rows; |
michael@0 | 291 | upsample->rows_to_go -= num_rows; |
michael@0 | 292 | /* When the buffer is emptied, declare this input row group consumed */ |
michael@0 | 293 | if (! upsample->spare_full) |
michael@0 | 294 | (*in_row_group_ctr)++; |
michael@0 | 295 | } |
michael@0 | 296 | |
michael@0 | 297 | |
michael@0 | 298 | METHODDEF(void) |
michael@0 | 299 | merged_1v_upsample (j_decompress_ptr cinfo, |
michael@0 | 300 | JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, |
michael@0 | 301 | JDIMENSION in_row_groups_avail, |
michael@0 | 302 | JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, |
michael@0 | 303 | JDIMENSION out_rows_avail) |
michael@0 | 304 | /* 1:1 vertical sampling case: much easier, never need a spare row. */ |
michael@0 | 305 | { |
michael@0 | 306 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
michael@0 | 307 | |
michael@0 | 308 | /* Just do the upsampling. */ |
michael@0 | 309 | (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, |
michael@0 | 310 | output_buf + *out_row_ctr); |
michael@0 | 311 | /* Adjust counts */ |
michael@0 | 312 | (*out_row_ctr)++; |
michael@0 | 313 | (*in_row_group_ctr)++; |
michael@0 | 314 | } |
michael@0 | 315 | |
michael@0 | 316 | |
michael@0 | 317 | /* |
michael@0 | 318 | * These are the routines invoked by the control routines to do |
michael@0 | 319 | * the actual upsampling/conversion. One row group is processed per call. |
michael@0 | 320 | * |
michael@0 | 321 | * Note: since we may be writing directly into application-supplied buffers, |
michael@0 | 322 | * we have to be honest about the output width; we can't assume the buffer |
michael@0 | 323 | * has been rounded up to an even width. |
michael@0 | 324 | */ |
michael@0 | 325 | |
michael@0 | 326 | |
michael@0 | 327 | /* |
michael@0 | 328 | * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. |
michael@0 | 329 | */ |
michael@0 | 330 | |
michael@0 | 331 | METHODDEF(void) |
michael@0 | 332 | h2v1_merged_upsample (j_decompress_ptr cinfo, |
michael@0 | 333 | JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, |
michael@0 | 334 | JSAMPARRAY output_buf) |
michael@0 | 335 | { |
michael@0 | 336 | switch (cinfo->out_color_space) { |
michael@0 | 337 | case JCS_EXT_RGB: |
michael@0 | 338 | extrgb_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 339 | output_buf); |
michael@0 | 340 | break; |
michael@0 | 341 | case JCS_EXT_RGBX: |
michael@0 | 342 | case JCS_EXT_RGBA: |
michael@0 | 343 | extrgbx_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 344 | output_buf); |
michael@0 | 345 | break; |
michael@0 | 346 | case JCS_EXT_BGR: |
michael@0 | 347 | extbgr_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 348 | output_buf); |
michael@0 | 349 | break; |
michael@0 | 350 | case JCS_EXT_BGRX: |
michael@0 | 351 | case JCS_EXT_BGRA: |
michael@0 | 352 | extbgrx_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 353 | output_buf); |
michael@0 | 354 | break; |
michael@0 | 355 | case JCS_EXT_XBGR: |
michael@0 | 356 | case JCS_EXT_ABGR: |
michael@0 | 357 | extxbgr_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 358 | output_buf); |
michael@0 | 359 | break; |
michael@0 | 360 | case JCS_EXT_XRGB: |
michael@0 | 361 | case JCS_EXT_ARGB: |
michael@0 | 362 | extxrgb_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 363 | output_buf); |
michael@0 | 364 | break; |
michael@0 | 365 | default: |
michael@0 | 366 | h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 367 | output_buf); |
michael@0 | 368 | break; |
michael@0 | 369 | } |
michael@0 | 370 | } |
michael@0 | 371 | |
michael@0 | 372 | |
michael@0 | 373 | /* |
michael@0 | 374 | * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. |
michael@0 | 375 | */ |
michael@0 | 376 | |
michael@0 | 377 | METHODDEF(void) |
michael@0 | 378 | h2v2_merged_upsample (j_decompress_ptr cinfo, |
michael@0 | 379 | JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, |
michael@0 | 380 | JSAMPARRAY output_buf) |
michael@0 | 381 | { |
michael@0 | 382 | switch (cinfo->out_color_space) { |
michael@0 | 383 | case JCS_EXT_RGB: |
michael@0 | 384 | extrgb_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 385 | output_buf); |
michael@0 | 386 | break; |
michael@0 | 387 | case JCS_EXT_RGBX: |
michael@0 | 388 | case JCS_EXT_RGBA: |
michael@0 | 389 | extrgbx_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 390 | output_buf); |
michael@0 | 391 | break; |
michael@0 | 392 | case JCS_EXT_BGR: |
michael@0 | 393 | extbgr_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 394 | output_buf); |
michael@0 | 395 | break; |
michael@0 | 396 | case JCS_EXT_BGRX: |
michael@0 | 397 | case JCS_EXT_BGRA: |
michael@0 | 398 | extbgrx_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 399 | output_buf); |
michael@0 | 400 | break; |
michael@0 | 401 | case JCS_EXT_XBGR: |
michael@0 | 402 | case JCS_EXT_ABGR: |
michael@0 | 403 | extxbgr_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 404 | output_buf); |
michael@0 | 405 | break; |
michael@0 | 406 | case JCS_EXT_XRGB: |
michael@0 | 407 | case JCS_EXT_ARGB: |
michael@0 | 408 | extxrgb_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 409 | output_buf); |
michael@0 | 410 | break; |
michael@0 | 411 | default: |
michael@0 | 412 | h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr, |
michael@0 | 413 | output_buf); |
michael@0 | 414 | break; |
michael@0 | 415 | } |
michael@0 | 416 | } |
michael@0 | 417 | |
michael@0 | 418 | |
michael@0 | 419 | /* |
michael@0 | 420 | * Module initialization routine for merged upsampling/color conversion. |
michael@0 | 421 | * |
michael@0 | 422 | * NB: this is called under the conditions determined by use_merged_upsample() |
michael@0 | 423 | * in jdmaster.c. That routine MUST correspond to the actual capabilities |
michael@0 | 424 | * of this module; no safety checks are made here. |
michael@0 | 425 | */ |
michael@0 | 426 | |
michael@0 | 427 | GLOBAL(void) |
michael@0 | 428 | jinit_merged_upsampler (j_decompress_ptr cinfo) |
michael@0 | 429 | { |
michael@0 | 430 | my_upsample_ptr upsample; |
michael@0 | 431 | |
michael@0 | 432 | upsample = (my_upsample_ptr) |
michael@0 | 433 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
michael@0 | 434 | SIZEOF(my_upsampler)); |
michael@0 | 435 | cinfo->upsample = (struct jpeg_upsampler *) upsample; |
michael@0 | 436 | upsample->pub.start_pass = start_pass_merged_upsample; |
michael@0 | 437 | upsample->pub.need_context_rows = FALSE; |
michael@0 | 438 | |
michael@0 | 439 | upsample->out_row_width = cinfo->output_width * cinfo->out_color_components; |
michael@0 | 440 | |
michael@0 | 441 | if (cinfo->max_v_samp_factor == 2) { |
michael@0 | 442 | upsample->pub.upsample = merged_2v_upsample; |
michael@0 | 443 | if (jsimd_can_h2v2_merged_upsample()) |
michael@0 | 444 | upsample->upmethod = jsimd_h2v2_merged_upsample; |
michael@0 | 445 | else |
michael@0 | 446 | upsample->upmethod = h2v2_merged_upsample; |
michael@0 | 447 | /* Allocate a spare row buffer */ |
michael@0 | 448 | upsample->spare_row = (JSAMPROW) |
michael@0 | 449 | (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
michael@0 | 450 | (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE))); |
michael@0 | 451 | } else { |
michael@0 | 452 | upsample->pub.upsample = merged_1v_upsample; |
michael@0 | 453 | if (jsimd_can_h2v1_merged_upsample()) |
michael@0 | 454 | upsample->upmethod = jsimd_h2v1_merged_upsample; |
michael@0 | 455 | else |
michael@0 | 456 | upsample->upmethod = h2v1_merged_upsample; |
michael@0 | 457 | /* No spare row needed */ |
michael@0 | 458 | upsample->spare_row = NULL; |
michael@0 | 459 | } |
michael@0 | 460 | |
michael@0 | 461 | build_ycc_rgb_table(cinfo); |
michael@0 | 462 | } |
michael@0 | 463 | |
michael@0 | 464 | #endif /* UPSAMPLE_MERGING_SUPPORTED */ |