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