AlbumShaper  1.0a3
jpegInternal.h
Go to the documentation of this file.
1 //==============================================
2 // copyright : (C) 2003-2005 by Will Stokes
3 //==============================================
4 // This program is free software; you can redistribute it
5 // and/or modify it under the terms of the GNU General
6 // Public License as published by the Free Software
7 // Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //==============================================
10 
11 #ifndef BACKEND_TOOLS_JPEG_JPEGINTERNAL
12 #define BACKEND_TOOLS_JPEG_JPEGINTERNAL
13 
14 //Support for copying optional markers from source to destination file.
15 typedef enum {
16  JCOPYOPT_NONE, //copy no optional markers
17  JCOPYOPT_COMMENTS,//copy only comment (COM) markers
18  JCOPYOPT_ALL //copy all optional markers
19 } JCOPY_OPTION;
20 
21 //Codes for supported types of image transformations.
22 typedef enum {
23  JXFORM_NONE, // no transformation
24  JXFORM_FLIP_H, // horizontal flip
25  JXFORM_FLIP_V, // vertical flip
26  JXFORM_TRANSPOSE, // transpose across UL-to-LR axis
27  JXFORM_TRANSVERSE, // transpose across UR-to-LL axis
28  JXFORM_ROT_90, // 90-degree clockwise rotation
29  JXFORM_ROT_180, // 180-degree rotation
30  JXFORM_ROT_270 // 270-degree clockwise (or 90 ccw)
31 } JXFORM_CODE;
32 
33 // Although rotating and flipping data expressed as DCT coefficients is not
34 // hard, there is an asymmetry in the JPEG format specification for images
35 // whose dimensions aren't multiples of the iMCU size. The right and bottom
36 // image edges are padded out to the next iMCU boundary with junk data; but
37 // no padding is possible at the top and left edges. If we were to flip
38 // the whole image including the pad data, then pad garbage would become
39 // visible at the top and/or left, and real pixels would disappear into the
40 // pad margins --- perhaps permanently, since encoders & decoders may not
41 // bother to preserve DCT blocks that appear to be completely outside the
42 // nominal image area. So, we have to exclude any partial iMCUs from the
43 // basic transformation.
44 //
45 // Transpose is the only transformation that can handle partial iMCUs at the
46 // right and bottom edges completely cleanly. flip_h can flip partial iMCUs
47 // at the bottom, but leaves any partial iMCUs at the right edge untouched.
48 // Similarly flip_v leaves any partial iMCUs at the bottom edge untouched.
49 // The other transforms are defined as combinations of these basic transforms
50 // and process edge blocks in a way that preserves the equivalence.
51 //
52 // The "trim" option causes untransformable partial iMCUs to be dropped;
53 // this is not strictly lossless, but it usually gives the best-looking
54 // result for odd-size images. Note that when this option is active,
55 // the expected mathematical equivalences between the transforms may not hold.
56 // (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim
57 // followed by -rot 180 -trim trims both edges.)
58 //
59 // We also offer a "force to grayscale" option, which simply discards the
60 // chrominance channels of a YCbCr image. This is lossless in the sense that
61 // the luminance channel is preserved exactly. It's not the same kind of
62 // thing as the rotate/flip transformations, but it's convenient to handle it
63 // as part of this package, mainly because the transformation routines have to
64 // be aware of the option to know how many components to work on.
65 typedef struct {
66  //Options: set by caller
67  JXFORM_CODE transform; // image transform operator
68  boolean trim; // if TRUE, trim partial MCUs as needed
69  boolean force_grayscale; // if TRUE, convert color image to grayscale
70 
72  int num_components; // # of components in workspace
73  jvirt_barray_ptr * workspace_coef_arrays; // workspace for transformations
75 
76 // Setup decompression object to save desired markers in memory
77 void jcopy_markers_setup(j_decompress_ptr srcinfo, JCOPY_OPTION option);
78 
79 // Request any required workspace
80 void jtransform_request_workspace(j_decompress_ptr srcinfo, jpeg_transform_info *info);
81 
82 // Adjust output image parameters
83 jvirt_barray_ptr * jtransform_adjust_parameters(j_compress_ptr dstinfo,
84  jvirt_barray_ptr *src_coef_arrays,
85  jpeg_transform_info *info);
86 // Execute the actual transformation, if any
87 void jtransform_execute_transformation(j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
88  jvirt_barray_ptr *src_coef_arrays,
89  jpeg_transform_info *info);
90 
91 // Copy markers saved in the given source object to the destination object
92 void jcopy_markers_execute(j_decompress_ptr srcinfo, j_compress_ptr dstinfo);
93 
94 
95 void do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
96  jvirt_barray_ptr *src_coef_arrays,
97  jvirt_barray_ptr *dst_coef_arrays);
98 
99 void do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
100  jvirt_barray_ptr *src_coef_arrays,
101  jvirt_barray_ptr *dst_coef_arrays);
102 
103 void do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
104  jvirt_barray_ptr *src_coef_arrays,
105  jvirt_barray_ptr *dst_coef_arrays);
106 
107 void do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
108  jvirt_barray_ptr *src_coef_arrays,
109  jvirt_barray_ptr *dst_coef_arrays);
110 
111 void do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
112  jvirt_barray_ptr *src_coef_arrays,
113  jvirt_barray_ptr *dst_coef_arrays);
114 
115 void do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
116  jvirt_barray_ptr *src_coef_arrays);
117 
118 void trim_bottom_edge (j_compress_ptr dstinfo);
119 void trim_right_edge (j_compress_ptr dstinfo);
120 
121 void do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
122  jvirt_barray_ptr *src_coef_arrays,
123  jvirt_barray_ptr *dst_coef_arrays);
124 
125 EXTERN(long) jround_up JPP((long a, long b));
126 
127 EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row,
128  JBLOCKROW output_row,
129  JDIMENSION num_blocks));
130 
131 #endif //BACKEND_TOOLS_JPEG_JPEGINTERNAL
132 
void do_transpose(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, jvirt_barray_ptr *src_coef_arrays, jvirt_barray_ptr *dst_coef_arrays)
void trim_right_edge(j_compress_ptr dstinfo)
void jcopy_markers_setup(j_decompress_ptr srcinfo, JCOPY_OPTION option)
JBLOCKROW JDIMENSION num_blocks
Definition: jpegInternal.h:128
void do_rot_90(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, jvirt_barray_ptr *src_coef_arrays, jvirt_barray_ptr *dst_coef_arrays)
void jcopy_markers_execute(j_decompress_ptr srcinfo, j_compress_ptr dstinfo)
jvirt_barray_ptr * jtransform_adjust_parameters(j_compress_ptr dstinfo, jvirt_barray_ptr *src_coef_arrays, jpeg_transform_info *info)
long b
Definition: jpegInternal.h:125
EXTERN(long) jround_up JPP((long a
void trim_bottom_edge(j_compress_ptr dstinfo)
JXFORM_CODE transform
Definition: jpegInternal.h:67
void do_rot_270(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, jvirt_barray_ptr *src_coef_arrays, jvirt_barray_ptr *dst_coef_arrays)
void do_flip_v(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, jvirt_barray_ptr *src_coef_arrays, jvirt_barray_ptr *dst_coef_arrays)
void jtransform_request_workspace(j_decompress_ptr srcinfo, jpeg_transform_info *info)
int num_components
Internal workspace: caller should not touch these.
Definition: jpegInternal.h:72
void do_rot_180(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, jvirt_barray_ptr *src_coef_arrays, jvirt_barray_ptr *dst_coef_arrays)
JCOPY_OPTION
Definition: jpegInternal.h:15
JXFORM_CODE
Definition: jpegInternal.h:22
JBLOCKROW output_row
Definition: jpegInternal.h:128
void do_flip_h(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, jvirt_barray_ptr *src_coef_arrays)
jvirt_barray_ptr * workspace_coef_arrays
Definition: jpegInternal.h:73
void jtransform_execute_transformation(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, jvirt_barray_ptr *src_coef_arrays, jpeg_transform_info *info)
void do_transverse(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, jvirt_barray_ptr *src_coef_arrays, jvirt_barray_ptr *dst_coef_arrays)