00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 #define JPEG_INTERNALS
00019 
00020 #include "jinclude.h"
00021 #include "jpeglib.h"
00022 #include "transupp.h"           
00023 
00024 
00025 #if TRANSFORMS_SUPPORTED
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 LOCAL(void)
00066 do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
00067            jvirt_barray_ptr *src_coef_arrays)
00068 
00069 {
00070   JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
00071   int ci, k, offset_y;
00072   JBLOCKARRAY buffer;
00073   JCOEFPTR ptr1, ptr2;
00074   JCOEF temp1, temp2;
00075   jpeg_component_info *compptr;
00076 
00077   
00078 
00079 
00080 
00081 
00082   MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
00083 
00084   for (ci = 0; ci < dstinfo->num_components; ci++) {
00085     compptr = dstinfo->comp_info + ci;
00086     comp_width = MCU_cols * compptr->h_samp_factor;
00087     for (blk_y = 0; blk_y < compptr->height_in_blocks;
00088          blk_y += compptr->v_samp_factor) {
00089       buffer = (*srcinfo->mem->access_virt_barray)
00090         ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
00091          (JDIMENSION) compptr->v_samp_factor, TRUE);
00092       for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
00093         for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
00094           ptr1 = buffer[offset_y][blk_x];
00095           ptr2 = buffer[offset_y][comp_width - blk_x - 1];
00096           
00097           for (k = 0; k < DCTSIZE2; k += 2) {
00098             temp1 = *ptr1;      
00099             temp2 = *ptr2;
00100             *ptr1++ = temp2;
00101             *ptr2++ = temp1;
00102             temp1 = *ptr1;      
00103             temp2 = *ptr2;
00104             *ptr1++ = -temp2;
00105             *ptr2++ = -temp1;
00106           }
00107         }
00108       }
00109     }
00110   }
00111 }
00112 
00113 
00114 LOCAL(void)
00115 do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
00116            jvirt_barray_ptr *src_coef_arrays,
00117            jvirt_barray_ptr *dst_coef_arrays)
00118 
00119 {
00120   JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
00121   int ci, i, j, offset_y;
00122   JBLOCKARRAY src_buffer, dst_buffer;
00123   JBLOCKROW src_row_ptr, dst_row_ptr;
00124   JCOEFPTR src_ptr, dst_ptr;
00125   jpeg_component_info *compptr;
00126 
00127   
00128 
00129 
00130 
00131 
00132 
00133 
00134   MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
00135 
00136   for (ci = 0; ci < dstinfo->num_components; ci++) {
00137     compptr = dstinfo->comp_info + ci;
00138     comp_height = MCU_rows * compptr->v_samp_factor;
00139     for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
00140          dst_blk_y += compptr->v_samp_factor) {
00141       dst_buffer = (*srcinfo->mem->access_virt_barray)
00142         ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
00143          (JDIMENSION) compptr->v_samp_factor, TRUE);
00144       if (dst_blk_y < comp_height) {
00145         
00146         src_buffer = (*srcinfo->mem->access_virt_barray)
00147           ((j_common_ptr) srcinfo, src_coef_arrays[ci],
00148            comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
00149            (JDIMENSION) compptr->v_samp_factor, FALSE);
00150       } else {
00151         
00152         src_buffer = (*srcinfo->mem->access_virt_barray)
00153           ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
00154            (JDIMENSION) compptr->v_samp_factor, FALSE);
00155       }
00156       for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
00157         if (dst_blk_y < comp_height) {
00158           
00159           dst_row_ptr = dst_buffer[offset_y];
00160           src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
00161           for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
00162                dst_blk_x++) {
00163             dst_ptr = dst_row_ptr[dst_blk_x];
00164             src_ptr = src_row_ptr[dst_blk_x];
00165             for (i = 0; i < DCTSIZE; i += 2) {
00166               
00167               for (j = 0; j < DCTSIZE; j++)
00168                 *dst_ptr++ = *src_ptr++;
00169               
00170               for (j = 0; j < DCTSIZE; j++)
00171                 *dst_ptr++ = - *src_ptr++;
00172             }
00173           }
00174         } else {
00175           
00176           jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
00177                           compptr->width_in_blocks);
00178         }
00179       }
00180     }
00181   }
00182 }
00183 
00184 
00185 LOCAL(void)
00186 do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
00187               jvirt_barray_ptr *src_coef_arrays,
00188               jvirt_barray_ptr *dst_coef_arrays)
00189 
00190 {
00191   JDIMENSION dst_blk_x, dst_blk_y;
00192   int ci, i, j, offset_x, offset_y;
00193   JBLOCKARRAY src_buffer, dst_buffer;
00194   JCOEFPTR src_ptr, dst_ptr;
00195   jpeg_component_info *compptr;
00196 
00197   
00198 
00199 
00200 
00201 
00202   for (ci = 0; ci < dstinfo->num_components; ci++) {
00203     compptr = dstinfo->comp_info + ci;
00204     for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
00205          dst_blk_y += compptr->v_samp_factor) {
00206       dst_buffer = (*srcinfo->mem->access_virt_barray)
00207         ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
00208          (JDIMENSION) compptr->v_samp_factor, TRUE);
00209       for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
00210         for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
00211              dst_blk_x += compptr->h_samp_factor) {
00212           src_buffer = (*srcinfo->mem->access_virt_barray)
00213             ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
00214              (JDIMENSION) compptr->h_samp_factor, FALSE);
00215           for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
00216             src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
00217             dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
00218             for (i = 0; i < DCTSIZE; i++)
00219               for (j = 0; j < DCTSIZE; j++)
00220                 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
00221           }
00222         }
00223       }
00224     }
00225   }
00226 }
00227 
00228 
00229 LOCAL(void)
00230 do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
00231            jvirt_barray_ptr *src_coef_arrays,
00232            jvirt_barray_ptr *dst_coef_arrays)
00233 
00234 
00235 
00236 
00237 
00238 {
00239   JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
00240   int ci, i, j, offset_x, offset_y;
00241   JBLOCKARRAY src_buffer, dst_buffer;
00242   JCOEFPTR src_ptr, dst_ptr;
00243   jpeg_component_info *compptr;
00244 
00245   
00246 
00247 
00248 
00249   MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
00250 
00251   for (ci = 0; ci < dstinfo->num_components; ci++) {
00252     compptr = dstinfo->comp_info + ci;
00253     comp_width = MCU_cols * compptr->h_samp_factor;
00254     for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
00255          dst_blk_y += compptr->v_samp_factor) {
00256       dst_buffer = (*srcinfo->mem->access_virt_barray)
00257         ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
00258          (JDIMENSION) compptr->v_samp_factor, TRUE);
00259       for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
00260         for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
00261              dst_blk_x += compptr->h_samp_factor) {
00262           src_buffer = (*srcinfo->mem->access_virt_barray)
00263             ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
00264              (JDIMENSION) compptr->h_samp_factor, FALSE);
00265           for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
00266             src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
00267             if (dst_blk_x < comp_width) {
00268               
00269               dst_ptr = dst_buffer[offset_y]
00270                 [comp_width - dst_blk_x - offset_x - 1];
00271               for (i = 0; i < DCTSIZE; i++) {
00272                 for (j = 0; j < DCTSIZE; j++)
00273                   dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
00274                 i++;
00275                 for (j = 0; j < DCTSIZE; j++)
00276                   dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
00277               }
00278             } else {
00279               
00280               dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
00281               for (i = 0; i < DCTSIZE; i++)
00282                 for (j = 0; j < DCTSIZE; j++)
00283                   dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
00284             }
00285           }
00286         }
00287       }
00288     }
00289   }
00290 }
00291 
00292 
00293 LOCAL(void)
00294 do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
00295             jvirt_barray_ptr *src_coef_arrays,
00296             jvirt_barray_ptr *dst_coef_arrays)
00297 
00298 
00299 
00300 
00301 
00302 {
00303   JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
00304   int ci, i, j, offset_x, offset_y;
00305   JBLOCKARRAY src_buffer, dst_buffer;
00306   JCOEFPTR src_ptr, dst_ptr;
00307   jpeg_component_info *compptr;
00308 
00309   
00310 
00311 
00312 
00313   MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
00314 
00315   for (ci = 0; ci < dstinfo->num_components; ci++) {
00316     compptr = dstinfo->comp_info + ci;
00317     comp_height = MCU_rows * compptr->v_samp_factor;
00318     for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
00319          dst_blk_y += compptr->v_samp_factor) {
00320       dst_buffer = (*srcinfo->mem->access_virt_barray)
00321         ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
00322          (JDIMENSION) compptr->v_samp_factor, TRUE);
00323       for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
00324         for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
00325              dst_blk_x += compptr->h_samp_factor) {
00326           src_buffer = (*srcinfo->mem->access_virt_barray)
00327             ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
00328              (JDIMENSION) compptr->h_samp_factor, FALSE);
00329           for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
00330             dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
00331             if (dst_blk_y < comp_height) {
00332               
00333               src_ptr = src_buffer[offset_x]
00334                 [comp_height - dst_blk_y - offset_y - 1];
00335               for (i = 0; i < DCTSIZE; i++) {
00336                 for (j = 0; j < DCTSIZE; j++) {
00337                   dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
00338                   j++;
00339                   dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
00340                 }
00341               }
00342             } else {
00343               
00344               src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
00345               for (i = 0; i < DCTSIZE; i++)
00346                 for (j = 0; j < DCTSIZE; j++)
00347                   dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
00348             }
00349           }
00350         }
00351       }
00352     }
00353   }
00354 }
00355 
00356 
00357 LOCAL(void)
00358 do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
00359             jvirt_barray_ptr *src_coef_arrays,
00360             jvirt_barray_ptr *dst_coef_arrays)
00361 
00362 
00363 
00364 
00365 
00366 {
00367   JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
00368   int ci, i, j, offset_y;
00369   JBLOCKARRAY src_buffer, dst_buffer;
00370   JBLOCKROW src_row_ptr, dst_row_ptr;
00371   JCOEFPTR src_ptr, dst_ptr;
00372   jpeg_component_info *compptr;
00373 
00374   MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
00375   MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
00376 
00377   for (ci = 0; ci < dstinfo->num_components; ci++) {
00378     compptr = dstinfo->comp_info + ci;
00379     comp_width = MCU_cols * compptr->h_samp_factor;
00380     comp_height = MCU_rows * compptr->v_samp_factor;
00381     for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
00382          dst_blk_y += compptr->v_samp_factor) {
00383       dst_buffer = (*srcinfo->mem->access_virt_barray)
00384         ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
00385          (JDIMENSION) compptr->v_samp_factor, TRUE);
00386       if (dst_blk_y < comp_height) {
00387         
00388         src_buffer = (*srcinfo->mem->access_virt_barray)
00389           ((j_common_ptr) srcinfo, src_coef_arrays[ci],
00390            comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
00391            (JDIMENSION) compptr->v_samp_factor, FALSE);
00392       } else {
00393         
00394         src_buffer = (*srcinfo->mem->access_virt_barray)
00395           ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
00396            (JDIMENSION) compptr->v_samp_factor, FALSE);
00397       }
00398       for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
00399         if (dst_blk_y < comp_height) {
00400           
00401           dst_row_ptr = dst_buffer[offset_y];
00402           src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
00403           
00404           for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
00405             dst_ptr = dst_row_ptr[dst_blk_x];
00406             src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
00407             for (i = 0; i < DCTSIZE; i += 2) {
00408               
00409               for (j = 0; j < DCTSIZE; j += 2) {
00410                 *dst_ptr++ = *src_ptr++;
00411                 *dst_ptr++ = - *src_ptr++;
00412               }
00413               
00414               for (j = 0; j < DCTSIZE; j += 2) {
00415                 *dst_ptr++ = - *src_ptr++;
00416                 *dst_ptr++ = *src_ptr++;
00417               }
00418             }
00419           }
00420           
00421           for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
00422             dst_ptr = dst_row_ptr[dst_blk_x];
00423             src_ptr = src_row_ptr[dst_blk_x];
00424             for (i = 0; i < DCTSIZE; i += 2) {
00425               for (j = 0; j < DCTSIZE; j++)
00426                 *dst_ptr++ = *src_ptr++;
00427               for (j = 0; j < DCTSIZE; j++)
00428                 *dst_ptr++ = - *src_ptr++;
00429             }
00430           }
00431         } else {
00432           
00433           dst_row_ptr = dst_buffer[offset_y];
00434           src_row_ptr = src_buffer[offset_y];
00435           
00436           for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
00437             dst_ptr = dst_row_ptr[dst_blk_x];
00438             src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
00439             for (i = 0; i < DCTSIZE2; i += 2) {
00440               *dst_ptr++ = *src_ptr++;
00441               *dst_ptr++ = - *src_ptr++;
00442             }
00443           }
00444           
00445           for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
00446             dst_ptr = dst_row_ptr[dst_blk_x];
00447             src_ptr = src_row_ptr[dst_blk_x];
00448             for (i = 0; i < DCTSIZE2; i++)
00449               *dst_ptr++ = *src_ptr++;
00450           }
00451         }
00452       }
00453     }
00454   }
00455 }
00456 
00457 
00458 LOCAL(void)
00459 do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
00460                jvirt_barray_ptr *src_coef_arrays,
00461                jvirt_barray_ptr *dst_coef_arrays)
00462 
00463 
00464 
00465 
00466 
00467 
00468 
00469 
00470 
00471 {
00472   JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
00473   int ci, i, j, offset_x, offset_y;
00474   JBLOCKARRAY src_buffer, dst_buffer;
00475   JCOEFPTR src_ptr, dst_ptr;
00476   jpeg_component_info *compptr;
00477 
00478   MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
00479   MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
00480 
00481   for (ci = 0; ci < dstinfo->num_components; ci++) {
00482     compptr = dstinfo->comp_info + ci;
00483     comp_width = MCU_cols * compptr->h_samp_factor;
00484     comp_height = MCU_rows * compptr->v_samp_factor;
00485     for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
00486          dst_blk_y += compptr->v_samp_factor) {
00487       dst_buffer = (*srcinfo->mem->access_virt_barray)
00488         ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
00489          (JDIMENSION) compptr->v_samp_factor, TRUE);
00490       for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
00491         for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
00492              dst_blk_x += compptr->h_samp_factor) {
00493           src_buffer = (*srcinfo->mem->access_virt_barray)
00494             ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
00495              (JDIMENSION) compptr->h_samp_factor, FALSE);
00496           for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
00497             if (dst_blk_y < comp_height) {
00498               src_ptr = src_buffer[offset_x]
00499                 [comp_height - dst_blk_y - offset_y - 1];
00500               if (dst_blk_x < comp_width) {
00501                 
00502                 dst_ptr = dst_buffer[offset_y]
00503                   [comp_width - dst_blk_x - offset_x - 1];
00504                 for (i = 0; i < DCTSIZE; i++) {
00505                   for (j = 0; j < DCTSIZE; j++) {
00506                     dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
00507                     j++;
00508                     dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
00509                   }
00510                   i++;
00511                   for (j = 0; j < DCTSIZE; j++) {
00512                     dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
00513                     j++;
00514                     dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
00515                   }
00516                 }
00517               } else {
00518                 
00519                 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
00520                 for (i = 0; i < DCTSIZE; i++) {
00521                   for (j = 0; j < DCTSIZE; j++) {
00522                     dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
00523                     j++;
00524                     dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
00525                   }
00526                 }
00527               }
00528             } else {
00529               src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
00530               if (dst_blk_x < comp_width) {
00531                 
00532                 dst_ptr = dst_buffer[offset_y]
00533                   [comp_width - dst_blk_x - offset_x - 1];
00534                 for (i = 0; i < DCTSIZE; i++) {
00535                   for (j = 0; j < DCTSIZE; j++)
00536                     dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
00537                   i++;
00538                   for (j = 0; j < DCTSIZE; j++)
00539                     dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
00540                 }
00541               } else {
00542                 
00543                 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
00544                 for (i = 0; i < DCTSIZE; i++)
00545                   for (j = 0; j < DCTSIZE; j++)
00546                     dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
00547               }
00548             }
00549           }
00550         }
00551       }
00552     }
00553   }
00554 }
00555 
00556 
00557 
00558 
00559 
00560 
00561 
00562 
00563 
00564 
00565 
00566 
00567 GLOBAL(void)
00568 jtransform_request_workspace (j_decompress_ptr srcinfo,
00569                               jpeg_transform_info *info)
00570 {
00571   jvirt_barray_ptr *coef_arrays = NULL;
00572   jpeg_component_info *compptr;
00573   int ci;
00574 
00575   if (info->force_grayscale &&
00576       srcinfo->jpeg_color_space == JCS_YCbCr &&
00577       srcinfo->num_components == 3) {
00578     
00579     info->num_components = 1;
00580   } else {
00581     
00582     info->num_components = srcinfo->num_components;
00583   }
00584 
00585   switch (info->transform) {
00586   case JXFORM_NONE:
00587   case JXFORM_FLIP_H:
00588     
00589     break;
00590   case JXFORM_FLIP_V:
00591   case JXFORM_ROT_180:
00592     
00593 
00594 
00595 
00596     coef_arrays = (jvirt_barray_ptr *)
00597       (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
00598         SIZEOF(jvirt_barray_ptr) * info->num_components);
00599     for (ci = 0; ci < info->num_components; ci++) {
00600       compptr = srcinfo->comp_info + ci;
00601       coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
00602         ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
00603          (JDIMENSION) jround_up((long) compptr->width_in_blocks,
00604                                 (long) compptr->h_samp_factor),
00605          (JDIMENSION) jround_up((long) compptr->height_in_blocks,
00606                                 (long) compptr->v_samp_factor),
00607          (JDIMENSION) compptr->v_samp_factor);
00608     }
00609     break;
00610   case JXFORM_TRANSPOSE:
00611   case JXFORM_TRANSVERSE:
00612   case JXFORM_ROT_90:
00613   case JXFORM_ROT_270:
00614     
00615 
00616 
00617 
00618     coef_arrays = (jvirt_barray_ptr *)
00619       (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
00620         SIZEOF(jvirt_barray_ptr) * info->num_components);
00621     for (ci = 0; ci < info->num_components; ci++) {
00622       compptr = srcinfo->comp_info + ci;
00623       coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
00624         ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
00625          (JDIMENSION) jround_up((long) compptr->height_in_blocks,
00626                                 (long) compptr->v_samp_factor),
00627          (JDIMENSION) jround_up((long) compptr->width_in_blocks,
00628                                 (long) compptr->h_samp_factor),
00629          (JDIMENSION) compptr->h_samp_factor);
00630     }
00631     break;
00632   }
00633   info->workspace_coef_arrays = coef_arrays;
00634 }
00635 
00636 
00637 
00638 
00639 LOCAL(void)
00640 transpose_critical_parameters (j_compress_ptr dstinfo)
00641 {
00642   int tblno, i, j, ci, itemp;
00643   jpeg_component_info *compptr;
00644   JQUANT_TBL *qtblptr;
00645   JDIMENSION dtemp;
00646   UINT16 qtemp;
00647 
00648   
00649   dtemp = dstinfo->image_width;
00650   dstinfo->image_width = dstinfo->image_height;
00651   dstinfo->image_height = dtemp;
00652 
00653   
00654   for (ci = 0; ci < dstinfo->num_components; ci++) {
00655     compptr = dstinfo->comp_info + ci;
00656     itemp = compptr->h_samp_factor;
00657     compptr->h_samp_factor = compptr->v_samp_factor;
00658     compptr->v_samp_factor = itemp;
00659   }
00660 
00661   
00662   for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
00663     qtblptr = dstinfo->quant_tbl_ptrs[tblno];
00664     if (qtblptr != NULL) {
00665       for (i = 0; i < DCTSIZE; i++) {
00666         for (j = 0; j < i; j++) {
00667           qtemp = qtblptr->quantval[i*DCTSIZE+j];
00668           qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
00669           qtblptr->quantval[j*DCTSIZE+i] = qtemp;
00670         }
00671       }
00672     }
00673   }
00674 }
00675 
00676 
00677 
00678 
00679 LOCAL(void)
00680 trim_right_edge (j_compress_ptr dstinfo)
00681 {
00682   int ci, max_h_samp_factor;
00683   JDIMENSION MCU_cols;
00684 
00685   
00686 
00687 
00688 
00689   max_h_samp_factor = 1;
00690   for (ci = 0; ci < dstinfo->num_components; ci++) {
00691     int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
00692     max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
00693   }
00694   MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
00695   if (MCU_cols > 0)             
00696     dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
00697 }
00698 
00699 LOCAL(void)
00700 trim_bottom_edge (j_compress_ptr dstinfo)
00701 {
00702   int ci, max_v_samp_factor;
00703   JDIMENSION MCU_rows;
00704 
00705   
00706 
00707 
00708 
00709   max_v_samp_factor = 1;
00710   for (ci = 0; ci < dstinfo->num_components; ci++) {
00711     int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
00712     max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
00713   }
00714   MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
00715   if (MCU_rows > 0)             
00716     dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
00717 }
00718 
00719 
00720 
00721 
00722 
00723 
00724 
00725 
00726 
00727 
00728 
00729 
00730 
00731 GLOBAL(jvirt_barray_ptr *)
00732 jtransform_adjust_parameters (j_decompress_ptr srcinfo,
00733                               j_compress_ptr dstinfo,
00734                               jvirt_barray_ptr *src_coef_arrays,
00735                               jpeg_transform_info *info)
00736 {
00737   
00738   if (info->force_grayscale) {
00739     
00740 
00741 
00742 
00743 
00744 
00745 
00746     if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
00747          dstinfo->num_components == 3) ||
00748         (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
00749          dstinfo->num_components == 1)) {
00750       
00751       int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
00752       jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
00753       dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
00754     } else {
00755       
00756       ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
00757     }
00758   }
00759 
00760   
00761   switch (info->transform) {
00762   case JXFORM_NONE:
00763     
00764     break;
00765   case JXFORM_FLIP_H:
00766     if (info->trim)
00767       trim_right_edge(dstinfo);
00768     break;
00769   case JXFORM_FLIP_V:
00770     if (info->trim)
00771       trim_bottom_edge(dstinfo);
00772     break;
00773   case JXFORM_TRANSPOSE:
00774     transpose_critical_parameters(dstinfo);
00775     
00776     break;
00777   case JXFORM_TRANSVERSE:
00778     transpose_critical_parameters(dstinfo);
00779     if (info->trim) {
00780       trim_right_edge(dstinfo);
00781       trim_bottom_edge(dstinfo);
00782     }
00783     break;
00784   case JXFORM_ROT_90:
00785     transpose_critical_parameters(dstinfo);
00786     if (info->trim)
00787       trim_right_edge(dstinfo);
00788     break;
00789   case JXFORM_ROT_180:
00790     if (info->trim) {
00791       trim_right_edge(dstinfo);
00792       trim_bottom_edge(dstinfo);
00793     }
00794     break;
00795   case JXFORM_ROT_270:
00796     transpose_critical_parameters(dstinfo);
00797     if (info->trim)
00798       trim_bottom_edge(dstinfo);
00799     break;
00800   }
00801 
00802   
00803   if (info->workspace_coef_arrays != NULL)
00804     return info->workspace_coef_arrays;
00805   return src_coef_arrays;
00806 }
00807 
00808 
00809 
00810 
00811 
00812 
00813 
00814 
00815 
00816 
00817 
00818 GLOBAL(void)
00819 jtransform_execute_transformation (j_decompress_ptr srcinfo,
00820                                    j_compress_ptr dstinfo,
00821                                    jvirt_barray_ptr *src_coef_arrays,
00822                                    jpeg_transform_info *info)
00823 {
00824   jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
00825 
00826   switch (info->transform) {
00827   case JXFORM_NONE:
00828     break;
00829   case JXFORM_FLIP_H:
00830     do_flip_h(srcinfo, dstinfo, src_coef_arrays);
00831     break;
00832   case JXFORM_FLIP_V:
00833     do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
00834     break;
00835   case JXFORM_TRANSPOSE:
00836     do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
00837     break;
00838   case JXFORM_TRANSVERSE:
00839     do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
00840     break;
00841   case JXFORM_ROT_90:
00842     do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
00843     break;
00844   case JXFORM_ROT_180:
00845     do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
00846     break;
00847   case JXFORM_ROT_270:
00848     do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
00849     break;
00850   }
00851 }
00852 
00853 #endif 
00854 
00855 
00856 
00857 
00858 
00859 
00860 GLOBAL(void)
00861 jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
00862 {
00863 #ifdef SAVE_MARKERS_SUPPORTED
00864   int m;
00865 
00866   
00867   if (option != JCOPYOPT_NONE) {
00868     jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
00869   }
00870   
00871   if (option == JCOPYOPT_ALL) {
00872     for (m = 0; m < 16; m++)
00873       jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
00874   }
00875 #endif 
00876 }
00877 
00878 
00879 
00880 
00881 
00882 
00883 
00884 
00885 GLOBAL(void)
00886 jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
00887                        JCOPY_OPTION option)
00888 {
00889   jpeg_saved_marker_ptr marker;
00890 
00891   
00892 
00893 
00894 
00895 
00896   for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
00897     if (dstinfo->write_JFIF_header &&
00898         marker->marker == JPEG_APP0 &&
00899         marker->data_length >= 5 &&
00900         GETJOCTET(marker->data[0]) == 0x4A &&
00901         GETJOCTET(marker->data[1]) == 0x46 &&
00902         GETJOCTET(marker->data[2]) == 0x49 &&
00903         GETJOCTET(marker->data[3]) == 0x46 &&
00904         GETJOCTET(marker->data[4]) == 0)
00905       continue;                 
00906     if (dstinfo->write_Adobe_marker &&
00907         marker->marker == JPEG_APP0+14 &&
00908         marker->data_length >= 5 &&
00909         GETJOCTET(marker->data[0]) == 0x41 &&
00910         GETJOCTET(marker->data[1]) == 0x64 &&
00911         GETJOCTET(marker->data[2]) == 0x6F &&
00912         GETJOCTET(marker->data[3]) == 0x62 &&
00913         GETJOCTET(marker->data[4]) == 0x65)
00914       continue;                 
00915 #ifdef NEED_FAR_POINTERS
00916     
00917     {
00918       unsigned int i;
00919       jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
00920       for (i = 0; i < marker->data_length; i++)
00921         jpeg_write_m_byte(dstinfo, marker->data[i]);
00922     }
00923 #else
00924     jpeg_write_marker(dstinfo, marker->marker,
00925                       marker->data, marker->data_length);
00926 #endif
00927   }
00928 }