Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed
includes/jdsample.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 | * jdsample.c |
shoaib_ahmed | 0:791a779d6220 | 3 | * |
shoaib_ahmed | 0:791a779d6220 | 4 | * Copyright (C) 1991-1996, Thomas G. Lane. |
shoaib_ahmed | 0:791a779d6220 | 5 | * Modified 2002-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 upsampling routines. |
shoaib_ahmed | 0:791a779d6220 | 10 | * |
shoaib_ahmed | 0:791a779d6220 | 11 | * Upsampling input data is counted in "row groups". A row group |
shoaib_ahmed | 0:791a779d6220 | 12 | * is defined to be (v_samp_factor * DCT_v_scaled_size / min_DCT_v_scaled_size) |
shoaib_ahmed | 0:791a779d6220 | 13 | * sample rows of each component. Upsampling will normally produce |
shoaib_ahmed | 0:791a779d6220 | 14 | * max_v_samp_factor pixel rows from each row group (but this could vary |
shoaib_ahmed | 0:791a779d6220 | 15 | * if the upsampler is applying a scale factor of its own). |
shoaib_ahmed | 0:791a779d6220 | 16 | * |
shoaib_ahmed | 0:791a779d6220 | 17 | * An excellent reference for image resampling is |
shoaib_ahmed | 0:791a779d6220 | 18 | * Digital Image Warping, George Wolberg, 1990. |
shoaib_ahmed | 0:791a779d6220 | 19 | * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. |
shoaib_ahmed | 0:791a779d6220 | 20 | */ |
shoaib_ahmed | 0:791a779d6220 | 21 | |
shoaib_ahmed | 0:791a779d6220 | 22 | #define JPEG_INTERNALS |
shoaib_ahmed | 0:791a779d6220 | 23 | #include "jinclude.h" |
shoaib_ahmed | 0:791a779d6220 | 24 | #include "jpeglib.h" |
shoaib_ahmed | 0:791a779d6220 | 25 | |
shoaib_ahmed | 0:791a779d6220 | 26 | |
shoaib_ahmed | 0:791a779d6220 | 27 | /* Pointer to routine to upsample a single component */ |
shoaib_ahmed | 0:791a779d6220 | 28 | typedef JMETHOD(void, upsample1_ptr, |
shoaib_ahmed | 0:791a779d6220 | 29 | (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
shoaib_ahmed | 0:791a779d6220 | 30 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); |
shoaib_ahmed | 0:791a779d6220 | 31 | |
shoaib_ahmed | 0:791a779d6220 | 32 | /* Private subobject */ |
shoaib_ahmed | 0:791a779d6220 | 33 | |
shoaib_ahmed | 0:791a779d6220 | 34 | typedef struct { |
shoaib_ahmed | 0:791a779d6220 | 35 | struct jpeg_upsampler pub; /* public fields */ |
shoaib_ahmed | 0:791a779d6220 | 36 | |
shoaib_ahmed | 0:791a779d6220 | 37 | /* Color conversion buffer. When using separate upsampling and color |
shoaib_ahmed | 0:791a779d6220 | 38 | * conversion steps, this buffer holds one upsampled row group until it |
shoaib_ahmed | 0:791a779d6220 | 39 | * has been color converted and output. |
shoaib_ahmed | 0:791a779d6220 | 40 | * Note: we do not allocate any storage for component(s) which are full-size, |
shoaib_ahmed | 0:791a779d6220 | 41 | * ie do not need rescaling. The corresponding entry of color_buf[] is |
shoaib_ahmed | 0:791a779d6220 | 42 | * simply set to point to the input data array, thereby avoiding copying. |
shoaib_ahmed | 0:791a779d6220 | 43 | */ |
shoaib_ahmed | 0:791a779d6220 | 44 | JSAMPARRAY color_buf[MAX_COMPONENTS]; |
shoaib_ahmed | 0:791a779d6220 | 45 | |
shoaib_ahmed | 0:791a779d6220 | 46 | /* Per-component upsampling method pointers */ |
shoaib_ahmed | 0:791a779d6220 | 47 | upsample1_ptr methods[MAX_COMPONENTS]; |
shoaib_ahmed | 0:791a779d6220 | 48 | |
shoaib_ahmed | 0:791a779d6220 | 49 | int next_row_out; /* counts rows emitted from color_buf */ |
shoaib_ahmed | 0:791a779d6220 | 50 | JDIMENSION rows_to_go; /* counts rows remaining in image */ |
shoaib_ahmed | 0:791a779d6220 | 51 | |
shoaib_ahmed | 0:791a779d6220 | 52 | /* Height of an input row group for each component. */ |
shoaib_ahmed | 0:791a779d6220 | 53 | int rowgroup_height[MAX_COMPONENTS]; |
shoaib_ahmed | 0:791a779d6220 | 54 | |
shoaib_ahmed | 0:791a779d6220 | 55 | /* These arrays save pixel expansion factors so that int_expand need not |
shoaib_ahmed | 0:791a779d6220 | 56 | * recompute them each time. They are unused for other upsampling methods. |
shoaib_ahmed | 0:791a779d6220 | 57 | */ |
shoaib_ahmed | 0:791a779d6220 | 58 | UINT8 h_expand[MAX_COMPONENTS]; |
shoaib_ahmed | 0:791a779d6220 | 59 | UINT8 v_expand[MAX_COMPONENTS]; |
shoaib_ahmed | 0:791a779d6220 | 60 | } my_upsampler; |
shoaib_ahmed | 0:791a779d6220 | 61 | |
shoaib_ahmed | 0:791a779d6220 | 62 | typedef my_upsampler * my_upsample_ptr; |
shoaib_ahmed | 0:791a779d6220 | 63 | |
shoaib_ahmed | 0:791a779d6220 | 64 | |
shoaib_ahmed | 0:791a779d6220 | 65 | /* |
shoaib_ahmed | 0:791a779d6220 | 66 | * Initialize for an upsampling pass. |
shoaib_ahmed | 0:791a779d6220 | 67 | */ |
shoaib_ahmed | 0:791a779d6220 | 68 | |
shoaib_ahmed | 0:791a779d6220 | 69 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 70 | start_pass_upsample (j_decompress_ptr cinfo) |
shoaib_ahmed | 0:791a779d6220 | 71 | { |
shoaib_ahmed | 0:791a779d6220 | 72 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
shoaib_ahmed | 0:791a779d6220 | 73 | |
shoaib_ahmed | 0:791a779d6220 | 74 | /* Mark the conversion buffer empty */ |
shoaib_ahmed | 0:791a779d6220 | 75 | upsample->next_row_out = cinfo->max_v_samp_factor; |
shoaib_ahmed | 0:791a779d6220 | 76 | /* Initialize total-height counter for detecting bottom of image */ |
shoaib_ahmed | 0:791a779d6220 | 77 | upsample->rows_to_go = cinfo->output_height; |
shoaib_ahmed | 0:791a779d6220 | 78 | } |
shoaib_ahmed | 0:791a779d6220 | 79 | |
shoaib_ahmed | 0:791a779d6220 | 80 | |
shoaib_ahmed | 0:791a779d6220 | 81 | /* |
shoaib_ahmed | 0:791a779d6220 | 82 | * Control routine to do upsampling (and color conversion). |
shoaib_ahmed | 0:791a779d6220 | 83 | * |
shoaib_ahmed | 0:791a779d6220 | 84 | * In this version we upsample each component independently. |
shoaib_ahmed | 0:791a779d6220 | 85 | * We upsample one row group into the conversion buffer, then apply |
shoaib_ahmed | 0:791a779d6220 | 86 | * color conversion a row at a time. |
shoaib_ahmed | 0:791a779d6220 | 87 | */ |
shoaib_ahmed | 0:791a779d6220 | 88 | |
shoaib_ahmed | 0:791a779d6220 | 89 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 90 | sep_upsample (j_decompress_ptr cinfo, |
shoaib_ahmed | 0:791a779d6220 | 91 | JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, |
shoaib_ahmed | 0:791a779d6220 | 92 | JDIMENSION in_row_groups_avail, |
shoaib_ahmed | 0:791a779d6220 | 93 | JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, |
shoaib_ahmed | 0:791a779d6220 | 94 | JDIMENSION out_rows_avail) |
shoaib_ahmed | 0:791a779d6220 | 95 | { |
shoaib_ahmed | 0:791a779d6220 | 96 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
shoaib_ahmed | 0:791a779d6220 | 97 | int ci; |
shoaib_ahmed | 0:791a779d6220 | 98 | jpeg_component_info * compptr; |
shoaib_ahmed | 0:791a779d6220 | 99 | JDIMENSION num_rows; |
shoaib_ahmed | 0:791a779d6220 | 100 | |
shoaib_ahmed | 0:791a779d6220 | 101 | /* Fill the conversion buffer, if it's empty */ |
shoaib_ahmed | 0:791a779d6220 | 102 | if (upsample->next_row_out >= cinfo->max_v_samp_factor) { |
shoaib_ahmed | 0:791a779d6220 | 103 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
shoaib_ahmed | 0:791a779d6220 | 104 | ci++, compptr++) { |
shoaib_ahmed | 0:791a779d6220 | 105 | /* Invoke per-component upsample method. Notice we pass a POINTER |
shoaib_ahmed | 0:791a779d6220 | 106 | * to color_buf[ci], so that fullsize_upsample can change it. |
shoaib_ahmed | 0:791a779d6220 | 107 | */ |
shoaib_ahmed | 0:791a779d6220 | 108 | (*upsample->methods[ci]) (cinfo, compptr, |
shoaib_ahmed | 0:791a779d6220 | 109 | input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]), |
shoaib_ahmed | 0:791a779d6220 | 110 | upsample->color_buf + ci); |
shoaib_ahmed | 0:791a779d6220 | 111 | } |
shoaib_ahmed | 0:791a779d6220 | 112 | upsample->next_row_out = 0; |
shoaib_ahmed | 0:791a779d6220 | 113 | } |
shoaib_ahmed | 0:791a779d6220 | 114 | |
shoaib_ahmed | 0:791a779d6220 | 115 | /* Color-convert and emit rows */ |
shoaib_ahmed | 0:791a779d6220 | 116 | |
shoaib_ahmed | 0:791a779d6220 | 117 | /* How many we have in the buffer: */ |
shoaib_ahmed | 0:791a779d6220 | 118 | num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out); |
shoaib_ahmed | 0:791a779d6220 | 119 | /* Not more than the distance to the end of the image. Need this test |
shoaib_ahmed | 0:791a779d6220 | 120 | * in case the image height is not a multiple of max_v_samp_factor: |
shoaib_ahmed | 0:791a779d6220 | 121 | */ |
shoaib_ahmed | 0:791a779d6220 | 122 | if (num_rows > upsample->rows_to_go) |
shoaib_ahmed | 0:791a779d6220 | 123 | num_rows = upsample->rows_to_go; |
shoaib_ahmed | 0:791a779d6220 | 124 | /* And not more than what the client can accept: */ |
shoaib_ahmed | 0:791a779d6220 | 125 | out_rows_avail -= *out_row_ctr; |
shoaib_ahmed | 0:791a779d6220 | 126 | if (num_rows > out_rows_avail) |
shoaib_ahmed | 0:791a779d6220 | 127 | num_rows = out_rows_avail; |
shoaib_ahmed | 0:791a779d6220 | 128 | |
shoaib_ahmed | 0:791a779d6220 | 129 | (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf, |
shoaib_ahmed | 0:791a779d6220 | 130 | (JDIMENSION) upsample->next_row_out, |
shoaib_ahmed | 0:791a779d6220 | 131 | output_buf + *out_row_ctr, |
shoaib_ahmed | 0:791a779d6220 | 132 | (int) num_rows); |
shoaib_ahmed | 0:791a779d6220 | 133 | |
shoaib_ahmed | 0:791a779d6220 | 134 | /* Adjust counts */ |
shoaib_ahmed | 0:791a779d6220 | 135 | *out_row_ctr += num_rows; |
shoaib_ahmed | 0:791a779d6220 | 136 | upsample->rows_to_go -= num_rows; |
shoaib_ahmed | 0:791a779d6220 | 137 | upsample->next_row_out += num_rows; |
shoaib_ahmed | 0:791a779d6220 | 138 | /* When the buffer is emptied, declare this input row group consumed */ |
shoaib_ahmed | 0:791a779d6220 | 139 | if (upsample->next_row_out >= cinfo->max_v_samp_factor) |
shoaib_ahmed | 0:791a779d6220 | 140 | (*in_row_group_ctr)++; |
shoaib_ahmed | 0:791a779d6220 | 141 | } |
shoaib_ahmed | 0:791a779d6220 | 142 | |
shoaib_ahmed | 0:791a779d6220 | 143 | |
shoaib_ahmed | 0:791a779d6220 | 144 | /* |
shoaib_ahmed | 0:791a779d6220 | 145 | * These are the routines invoked by sep_upsample to upsample pixel values |
shoaib_ahmed | 0:791a779d6220 | 146 | * of a single component. One row group is processed per call. |
shoaib_ahmed | 0:791a779d6220 | 147 | */ |
shoaib_ahmed | 0:791a779d6220 | 148 | |
shoaib_ahmed | 0:791a779d6220 | 149 | |
shoaib_ahmed | 0:791a779d6220 | 150 | /* |
shoaib_ahmed | 0:791a779d6220 | 151 | * For full-size components, we just make color_buf[ci] point at the |
shoaib_ahmed | 0:791a779d6220 | 152 | * input buffer, and thus avoid copying any data. Note that this is |
shoaib_ahmed | 0:791a779d6220 | 153 | * safe only because sep_upsample doesn't declare the input row group |
shoaib_ahmed | 0:791a779d6220 | 154 | * "consumed" until we are done color converting and emitting it. |
shoaib_ahmed | 0:791a779d6220 | 155 | */ |
shoaib_ahmed | 0:791a779d6220 | 156 | |
shoaib_ahmed | 0:791a779d6220 | 157 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 158 | fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
shoaib_ahmed | 0:791a779d6220 | 159 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) |
shoaib_ahmed | 0:791a779d6220 | 160 | { |
shoaib_ahmed | 0:791a779d6220 | 161 | *output_data_ptr = input_data; |
shoaib_ahmed | 0:791a779d6220 | 162 | } |
shoaib_ahmed | 0:791a779d6220 | 163 | |
shoaib_ahmed | 0:791a779d6220 | 164 | |
shoaib_ahmed | 0:791a779d6220 | 165 | /* |
shoaib_ahmed | 0:791a779d6220 | 166 | * This is a no-op version used for "uninteresting" components. |
shoaib_ahmed | 0:791a779d6220 | 167 | * These components will not be referenced by color conversion. |
shoaib_ahmed | 0:791a779d6220 | 168 | */ |
shoaib_ahmed | 0:791a779d6220 | 169 | |
shoaib_ahmed | 0:791a779d6220 | 170 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 171 | noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
shoaib_ahmed | 0:791a779d6220 | 172 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) |
shoaib_ahmed | 0:791a779d6220 | 173 | { |
shoaib_ahmed | 0:791a779d6220 | 174 | *output_data_ptr = NULL; /* safety check */ |
shoaib_ahmed | 0:791a779d6220 | 175 | } |
shoaib_ahmed | 0:791a779d6220 | 176 | |
shoaib_ahmed | 0:791a779d6220 | 177 | |
shoaib_ahmed | 0:791a779d6220 | 178 | /* |
shoaib_ahmed | 0:791a779d6220 | 179 | * This version handles any integral sampling ratios. |
shoaib_ahmed | 0:791a779d6220 | 180 | * This is not used for typical JPEG files, so it need not be fast. |
shoaib_ahmed | 0:791a779d6220 | 181 | * Nor, for that matter, is it particularly accurate: the algorithm is |
shoaib_ahmed | 0:791a779d6220 | 182 | * simple replication of the input pixel onto the corresponding output |
shoaib_ahmed | 0:791a779d6220 | 183 | * pixels. The hi-falutin sampling literature refers to this as a |
shoaib_ahmed | 0:791a779d6220 | 184 | * "box filter". A box filter tends to introduce visible artifacts, |
shoaib_ahmed | 0:791a779d6220 | 185 | * so if you are actually going to use 3:1 or 4:1 sampling ratios |
shoaib_ahmed | 0:791a779d6220 | 186 | * you would be well advised to improve this code. |
shoaib_ahmed | 0:791a779d6220 | 187 | */ |
shoaib_ahmed | 0:791a779d6220 | 188 | |
shoaib_ahmed | 0:791a779d6220 | 189 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 190 | int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
shoaib_ahmed | 0:791a779d6220 | 191 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) |
shoaib_ahmed | 0:791a779d6220 | 192 | { |
shoaib_ahmed | 0:791a779d6220 | 193 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
shoaib_ahmed | 0:791a779d6220 | 194 | JSAMPARRAY output_data = *output_data_ptr; |
shoaib_ahmed | 0:791a779d6220 | 195 | register JSAMPROW inptr, outptr; |
shoaib_ahmed | 0:791a779d6220 | 196 | register JSAMPLE invalue; |
shoaib_ahmed | 0:791a779d6220 | 197 | register int h; |
shoaib_ahmed | 0:791a779d6220 | 198 | JSAMPROW outend; |
shoaib_ahmed | 0:791a779d6220 | 199 | int h_expand, v_expand; |
shoaib_ahmed | 0:791a779d6220 | 200 | int inrow, outrow; |
shoaib_ahmed | 0:791a779d6220 | 201 | |
shoaib_ahmed | 0:791a779d6220 | 202 | h_expand = upsample->h_expand[compptr->component_index]; |
shoaib_ahmed | 0:791a779d6220 | 203 | v_expand = upsample->v_expand[compptr->component_index]; |
shoaib_ahmed | 0:791a779d6220 | 204 | |
shoaib_ahmed | 0:791a779d6220 | 205 | inrow = outrow = 0; |
shoaib_ahmed | 0:791a779d6220 | 206 | while (outrow < cinfo->max_v_samp_factor) { |
shoaib_ahmed | 0:791a779d6220 | 207 | /* Generate one output row with proper horizontal expansion */ |
shoaib_ahmed | 0:791a779d6220 | 208 | inptr = input_data[inrow]; |
shoaib_ahmed | 0:791a779d6220 | 209 | outptr = output_data[outrow]; |
shoaib_ahmed | 0:791a779d6220 | 210 | outend = outptr + cinfo->output_width; |
shoaib_ahmed | 0:791a779d6220 | 211 | while (outptr < outend) { |
shoaib_ahmed | 0:791a779d6220 | 212 | invalue = *inptr++; /* don't need GETJSAMPLE() here */ |
shoaib_ahmed | 0:791a779d6220 | 213 | for (h = h_expand; h > 0; h--) { |
shoaib_ahmed | 0:791a779d6220 | 214 | *outptr++ = invalue; |
shoaib_ahmed | 0:791a779d6220 | 215 | } |
shoaib_ahmed | 0:791a779d6220 | 216 | } |
shoaib_ahmed | 0:791a779d6220 | 217 | /* Generate any additional output rows by duplicating the first one */ |
shoaib_ahmed | 0:791a779d6220 | 218 | if (v_expand > 1) { |
shoaib_ahmed | 0:791a779d6220 | 219 | jcopy_sample_rows(output_data, outrow, output_data, outrow+1, |
shoaib_ahmed | 0:791a779d6220 | 220 | v_expand-1, cinfo->output_width); |
shoaib_ahmed | 0:791a779d6220 | 221 | } |
shoaib_ahmed | 0:791a779d6220 | 222 | inrow++; |
shoaib_ahmed | 0:791a779d6220 | 223 | outrow += v_expand; |
shoaib_ahmed | 0:791a779d6220 | 224 | } |
shoaib_ahmed | 0:791a779d6220 | 225 | } |
shoaib_ahmed | 0:791a779d6220 | 226 | |
shoaib_ahmed | 0:791a779d6220 | 227 | |
shoaib_ahmed | 0:791a779d6220 | 228 | /* |
shoaib_ahmed | 0:791a779d6220 | 229 | * Fast processing for the common case of 2:1 horizontal and 1:1 vertical. |
shoaib_ahmed | 0:791a779d6220 | 230 | * It's still a box filter. |
shoaib_ahmed | 0:791a779d6220 | 231 | */ |
shoaib_ahmed | 0:791a779d6220 | 232 | |
shoaib_ahmed | 0:791a779d6220 | 233 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 234 | h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
shoaib_ahmed | 0:791a779d6220 | 235 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) |
shoaib_ahmed | 0:791a779d6220 | 236 | { |
shoaib_ahmed | 0:791a779d6220 | 237 | JSAMPARRAY output_data = *output_data_ptr; |
shoaib_ahmed | 0:791a779d6220 | 238 | register JSAMPROW inptr, outptr; |
shoaib_ahmed | 0:791a779d6220 | 239 | register JSAMPLE invalue; |
shoaib_ahmed | 0:791a779d6220 | 240 | JSAMPROW outend; |
shoaib_ahmed | 0:791a779d6220 | 241 | int outrow; |
shoaib_ahmed | 0:791a779d6220 | 242 | |
shoaib_ahmed | 0:791a779d6220 | 243 | for (outrow = 0; outrow < cinfo->max_v_samp_factor; outrow++) { |
shoaib_ahmed | 0:791a779d6220 | 244 | inptr = input_data[outrow]; |
shoaib_ahmed | 0:791a779d6220 | 245 | outptr = output_data[outrow]; |
shoaib_ahmed | 0:791a779d6220 | 246 | outend = outptr + cinfo->output_width; |
shoaib_ahmed | 0:791a779d6220 | 247 | while (outptr < outend) { |
shoaib_ahmed | 0:791a779d6220 | 248 | invalue = *inptr++; /* don't need GETJSAMPLE() here */ |
shoaib_ahmed | 0:791a779d6220 | 249 | *outptr++ = invalue; |
shoaib_ahmed | 0:791a779d6220 | 250 | *outptr++ = invalue; |
shoaib_ahmed | 0:791a779d6220 | 251 | } |
shoaib_ahmed | 0:791a779d6220 | 252 | } |
shoaib_ahmed | 0:791a779d6220 | 253 | } |
shoaib_ahmed | 0:791a779d6220 | 254 | |
shoaib_ahmed | 0:791a779d6220 | 255 | |
shoaib_ahmed | 0:791a779d6220 | 256 | /* |
shoaib_ahmed | 0:791a779d6220 | 257 | * Fast processing for the common case of 2:1 horizontal and 2:1 vertical. |
shoaib_ahmed | 0:791a779d6220 | 258 | * It's still a box filter. |
shoaib_ahmed | 0:791a779d6220 | 259 | */ |
shoaib_ahmed | 0:791a779d6220 | 260 | |
shoaib_ahmed | 0:791a779d6220 | 261 | METHODDEF(void) |
shoaib_ahmed | 0:791a779d6220 | 262 | h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
shoaib_ahmed | 0:791a779d6220 | 263 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) |
shoaib_ahmed | 0:791a779d6220 | 264 | { |
shoaib_ahmed | 0:791a779d6220 | 265 | JSAMPARRAY output_data = *output_data_ptr; |
shoaib_ahmed | 0:791a779d6220 | 266 | register JSAMPROW inptr, outptr; |
shoaib_ahmed | 0:791a779d6220 | 267 | register JSAMPLE invalue; |
shoaib_ahmed | 0:791a779d6220 | 268 | JSAMPROW outend; |
shoaib_ahmed | 0:791a779d6220 | 269 | int inrow, outrow; |
shoaib_ahmed | 0:791a779d6220 | 270 | |
shoaib_ahmed | 0:791a779d6220 | 271 | inrow = outrow = 0; |
shoaib_ahmed | 0:791a779d6220 | 272 | while (outrow < cinfo->max_v_samp_factor) { |
shoaib_ahmed | 0:791a779d6220 | 273 | inptr = input_data[inrow]; |
shoaib_ahmed | 0:791a779d6220 | 274 | outptr = output_data[outrow]; |
shoaib_ahmed | 0:791a779d6220 | 275 | outend = outptr + cinfo->output_width; |
shoaib_ahmed | 0:791a779d6220 | 276 | while (outptr < outend) { |
shoaib_ahmed | 0:791a779d6220 | 277 | invalue = *inptr++; /* don't need GETJSAMPLE() here */ |
shoaib_ahmed | 0:791a779d6220 | 278 | *outptr++ = invalue; |
shoaib_ahmed | 0:791a779d6220 | 279 | *outptr++ = invalue; |
shoaib_ahmed | 0:791a779d6220 | 280 | } |
shoaib_ahmed | 0:791a779d6220 | 281 | jcopy_sample_rows(output_data, outrow, output_data, outrow+1, |
shoaib_ahmed | 0:791a779d6220 | 282 | 1, cinfo->output_width); |
shoaib_ahmed | 0:791a779d6220 | 283 | inrow++; |
shoaib_ahmed | 0:791a779d6220 | 284 | outrow += 2; |
shoaib_ahmed | 0:791a779d6220 | 285 | } |
shoaib_ahmed | 0:791a779d6220 | 286 | } |
shoaib_ahmed | 0:791a779d6220 | 287 | |
shoaib_ahmed | 0:791a779d6220 | 288 | |
shoaib_ahmed | 0:791a779d6220 | 289 | /* |
shoaib_ahmed | 0:791a779d6220 | 290 | * Module initialization routine for upsampling. |
shoaib_ahmed | 0:791a779d6220 | 291 | */ |
shoaib_ahmed | 0:791a779d6220 | 292 | |
shoaib_ahmed | 0:791a779d6220 | 293 | GLOBAL(void) |
shoaib_ahmed | 0:791a779d6220 | 294 | jinit_upsampler (j_decompress_ptr cinfo) |
shoaib_ahmed | 0:791a779d6220 | 295 | { |
shoaib_ahmed | 0:791a779d6220 | 296 | my_upsample_ptr upsample; |
shoaib_ahmed | 0:791a779d6220 | 297 | int ci; |
shoaib_ahmed | 0:791a779d6220 | 298 | jpeg_component_info * compptr; |
shoaib_ahmed | 0:791a779d6220 | 299 | int h_in_group, v_in_group, h_out_group, v_out_group; |
shoaib_ahmed | 0:791a779d6220 | 300 | |
shoaib_ahmed | 0:791a779d6220 | 301 | upsample = (my_upsample_ptr) |
shoaib_ahmed | 0:791a779d6220 | 302 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
shoaib_ahmed | 0:791a779d6220 | 303 | SIZEOF(my_upsampler)); |
shoaib_ahmed | 0:791a779d6220 | 304 | cinfo->upsample = &upsample->pub; |
shoaib_ahmed | 0:791a779d6220 | 305 | upsample->pub.start_pass = start_pass_upsample; |
shoaib_ahmed | 0:791a779d6220 | 306 | upsample->pub.upsample = sep_upsample; |
shoaib_ahmed | 0:791a779d6220 | 307 | upsample->pub.need_context_rows = FALSE; /* until we find out differently */ |
shoaib_ahmed | 0:791a779d6220 | 308 | |
shoaib_ahmed | 0:791a779d6220 | 309 | if (cinfo->CCIR601_sampling) /* this isn't supported */ |
shoaib_ahmed | 0:791a779d6220 | 310 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); |
shoaib_ahmed | 0:791a779d6220 | 311 | |
shoaib_ahmed | 0:791a779d6220 | 312 | /* Verify we can handle the sampling factors, select per-component methods, |
shoaib_ahmed | 0:791a779d6220 | 313 | * and create storage as needed. |
shoaib_ahmed | 0:791a779d6220 | 314 | */ |
shoaib_ahmed | 0:791a779d6220 | 315 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
shoaib_ahmed | 0:791a779d6220 | 316 | ci++, compptr++) { |
shoaib_ahmed | 0:791a779d6220 | 317 | /* Compute size of an "input group" after IDCT scaling. This many samples |
shoaib_ahmed | 0:791a779d6220 | 318 | * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. |
shoaib_ahmed | 0:791a779d6220 | 319 | */ |
shoaib_ahmed | 0:791a779d6220 | 320 | h_in_group = (compptr->h_samp_factor * compptr->DCT_h_scaled_size) / |
shoaib_ahmed | 0:791a779d6220 | 321 | cinfo->min_DCT_h_scaled_size; |
shoaib_ahmed | 0:791a779d6220 | 322 | v_in_group = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / |
shoaib_ahmed | 0:791a779d6220 | 323 | cinfo->min_DCT_v_scaled_size; |
shoaib_ahmed | 0:791a779d6220 | 324 | h_out_group = cinfo->max_h_samp_factor; |
shoaib_ahmed | 0:791a779d6220 | 325 | v_out_group = cinfo->max_v_samp_factor; |
shoaib_ahmed | 0:791a779d6220 | 326 | upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ |
shoaib_ahmed | 0:791a779d6220 | 327 | if (! compptr->component_needed) { |
shoaib_ahmed | 0:791a779d6220 | 328 | /* Don't bother to upsample an uninteresting component. */ |
shoaib_ahmed | 0:791a779d6220 | 329 | upsample->methods[ci] = noop_upsample; |
shoaib_ahmed | 0:791a779d6220 | 330 | continue; /* don't need to allocate buffer */ |
shoaib_ahmed | 0:791a779d6220 | 331 | } |
shoaib_ahmed | 0:791a779d6220 | 332 | if (h_in_group == h_out_group && v_in_group == v_out_group) { |
shoaib_ahmed | 0:791a779d6220 | 333 | /* Fullsize components can be processed without any work. */ |
shoaib_ahmed | 0:791a779d6220 | 334 | upsample->methods[ci] = fullsize_upsample; |
shoaib_ahmed | 0:791a779d6220 | 335 | continue; /* don't need to allocate buffer */ |
shoaib_ahmed | 0:791a779d6220 | 336 | } |
shoaib_ahmed | 0:791a779d6220 | 337 | if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) { |
shoaib_ahmed | 0:791a779d6220 | 338 | /* Special case for 2h1v upsampling */ |
shoaib_ahmed | 0:791a779d6220 | 339 | upsample->methods[ci] = h2v1_upsample; |
shoaib_ahmed | 0:791a779d6220 | 340 | } else if (h_in_group * 2 == h_out_group && |
shoaib_ahmed | 0:791a779d6220 | 341 | v_in_group * 2 == v_out_group) { |
shoaib_ahmed | 0:791a779d6220 | 342 | /* Special case for 2h2v upsampling */ |
shoaib_ahmed | 0:791a779d6220 | 343 | upsample->methods[ci] = h2v2_upsample; |
shoaib_ahmed | 0:791a779d6220 | 344 | } else if ((h_out_group % h_in_group) == 0 && |
shoaib_ahmed | 0:791a779d6220 | 345 | (v_out_group % v_in_group) == 0) { |
shoaib_ahmed | 0:791a779d6220 | 346 | /* Generic integral-factors upsampling method */ |
shoaib_ahmed | 0:791a779d6220 | 347 | upsample->methods[ci] = int_upsample; |
shoaib_ahmed | 0:791a779d6220 | 348 | upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group); |
shoaib_ahmed | 0:791a779d6220 | 349 | upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group); |
shoaib_ahmed | 0:791a779d6220 | 350 | } else |
shoaib_ahmed | 0:791a779d6220 | 351 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); |
shoaib_ahmed | 0:791a779d6220 | 352 | upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray) |
shoaib_ahmed | 0:791a779d6220 | 353 | ((j_common_ptr) cinfo, JPOOL_IMAGE, |
shoaib_ahmed | 0:791a779d6220 | 354 | (JDIMENSION) jround_up((long) cinfo->output_width, |
shoaib_ahmed | 0:791a779d6220 | 355 | (long) cinfo->max_h_samp_factor), |
shoaib_ahmed | 0:791a779d6220 | 356 | (JDIMENSION) cinfo->max_v_samp_factor); |
shoaib_ahmed | 0:791a779d6220 | 357 | } |
shoaib_ahmed | 0:791a779d6220 | 358 | } |