Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibJPEG/libjpeg.txt view on Meta::CPAN
int component_id
The one-byte identifier code to be recorded in the JPEG file for
this component. For the standard color spaces, we recommend you
leave the default values alone.
int h_samp_factor
int v_samp_factor
Horizontal and vertical sampling factors for the component; must
be 1..4 according to the JPEG standard. Note that larger sampling
factors indicate a higher-resolution component; many people find
this behavior quite unintuitive. The default values are 2,2 for
luminance components and 1,1 for chrominance components, except
for grayscale where 1,1 is used.
int quant_tbl_no
Quantization table number for component. The default value is
0 for luminance components and 1 for chrominance components.
int dc_tbl_no
int ac_tbl_no
DC and AC entropy coding table numbers. The default values are
0 for luminance components and 1 for chrominance components.
int component_index
Must equal the component's index in comp_info[]. (Beginning in
release v6, the compressor library will fill this in automatically;
you don't have to.)
Decompression parameter selection
---------------------------------
Decompression parameter selection is somewhat simpler than compression
parameter selection, since all of the JPEG internal parameters are
recorded in the source file and need not be supplied by the application.
(Unless you are working with abbreviated files, in which case see
"Abbreviated datastreams", below.) Decompression parameters control
the postprocessing done on the image to deliver it in a format suitable
for the application's use. Many of the parameters control speed/quality
tradeoffs, in which faster decompression may be obtained at the price of
a poorer-quality image. The defaults select the highest quality (slowest)
processing.
The following fields in the JPEG object are set by jpeg_read_header() and
may be useful to the application in choosing decompression parameters:
JDIMENSION image_width Width and height of image
JDIMENSION image_height
int num_components Number of color components
J_COLOR_SPACE jpeg_color_space Colorspace of image
boolean saw_JFIF_marker TRUE if a JFIF APP0 marker was seen
UINT8 JFIF_major_version Version information from JFIF marker
UINT8 JFIF_minor_version
UINT8 density_unit Resolution data from JFIF marker
UINT16 X_density
UINT16 Y_density
boolean saw_Adobe_marker TRUE if an Adobe APP14 marker was seen
UINT8 Adobe_transform Color transform code from Adobe marker
The JPEG color space, unfortunately, is something of a guess since the JPEG
standard proper does not provide a way to record it. In practice most files
adhere to the JFIF or Adobe conventions, and the decoder will recognize these
correctly. See "Special color spaces", below, for more info.
The decompression parameters that determine the basic properties of the
returned image are:
J_COLOR_SPACE out_color_space
Output color space. jpeg_read_header() sets an appropriate default
based on jpeg_color_space; typically it will be RGB or grayscale.
The application can change this field to request output in a different
colorspace. For example, set it to JCS_GRAYSCALE to get grayscale
output from a color file. (This is useful for previewing: grayscale
output is faster than full color since the color components need not
be processed.) Note that not all possible color space transforms are
currently implemented; you may need to extend jdcolor.c if you want an
unusual conversion.
unsigned int scale_num, scale_denom
Scale the image by the fraction scale_num/scale_denom. Currently,
the supported scaling ratios are M/N with all M from 1 to 16, where
N is the source DCT size, which is 8 for baseline JPEG. (The library
design allows for arbitrary scaling ratios but this is not likely
to be implemented any time soon.) The values are initialized by
jpeg_read_header() with the source DCT size. For baseline JPEG
this is 8/8. If you change only the scale_num value while leaving
the other unchanged, then this specifies the DCT scaled size to be
applied on the given input. For baseline JPEG this is equivalent
to M/8 scaling, since the source DCT size for baseline JPEG is 8.
Smaller scaling ratios permit significantly faster decoding since
fewer pixels need be processed and a simpler IDCT method can be used.
boolean quantize_colors
If set TRUE, colormapped output will be delivered. Default is FALSE,
meaning that full-color output will be delivered.
The next three parameters are relevant only if quantize_colors is TRUE.
int desired_number_of_colors
Maximum number of colors to use in generating a library-supplied color
map (the actual number of colors is returned in a different field).
Default 256. Ignored when the application supplies its own color map.
boolean two_pass_quantize
If TRUE, an extra pass over the image is made to select a custom color
map for the image. This usually looks a lot better than the one-size-
fits-all colormap that is used otherwise. Default is TRUE. Ignored
when the application supplies its own color map.
J_DITHER_MODE dither_mode
Selects color dithering method. Supported values are:
JDITHER_NONE no dithering: fast, very low quality
JDITHER_ORDERED ordered dither: moderate speed and quality
JDITHER_FS Floyd-Steinberg dither: slow, high quality
Default is JDITHER_FS. (At present, ordered dither is implemented
only in the single-pass, standard-colormap case. If you ask for
ordered dither when two_pass_quantize is TRUE or when you supply
an external color map, you'll get F-S dithering.)
src/Source/LibJPEG/libjpeg.txt view on Meta::CPAN
go to the trouble of honoring rec_outbuf_height so as to avoid data copying.
(An output buffer larger than rec_outbuf_height lines is OK, but won't
provide any material speed improvement over that height.)
Special color spaces
--------------------
The JPEG standard itself is "color blind" and doesn't specify any particular
color space. It is customary to convert color data to a luminance/chrominance
color space before compressing, since this permits greater compression. The
existing JPEG file interchange format standards specify YCbCr or GRAYSCALE
data (JFIF version 1), GRAYSCALE, RGB, YCbCr, CMYK, or YCCK (Adobe), or BG_RGB
or BG_YCC (big gamut color spaces, JFIF version 2). For special applications
such as multispectral images, other color spaces can be used,
but it must be understood that such files will be unportable.
The JPEG library can handle the most common colorspace conversions (namely
RGB <=> YCbCr and CMYK <=> YCCK). It can also deal with data of an unknown
color space, passing it through without conversion. If you deal extensively
with an unusual color space, you can easily extend the library to understand
additional color spaces and perform appropriate conversions.
For compression, the source data's color space is specified by field
in_color_space. This is transformed to the JPEG file's color space given
by jpeg_color_space. jpeg_set_defaults() chooses a reasonable JPEG color
space depending on in_color_space, but you can override this by calling
jpeg_set_colorspace(). Of course you must select a supported transformation.
jccolor.c currently supports the following transformations:
RGB => YCbCr
RGB => GRAYSCALE
RGB => BG_YCC
YCbCr => GRAYSCALE
YCbCr => BG_YCC
CMYK => YCCK
plus the null transforms: GRAYSCALE => GRAYSCALE, RGB => RGB,
BG_RGB => BG_RGB, YCbCr => YCbCr, BG_YCC => BG_YCC, CMYK => CMYK,
YCCK => YCCK, and UNKNOWN => UNKNOWN.
The file interchange format standards (JFIF and Adobe) specify APPn markers
that indicate the color space of the JPEG file. It is important to ensure
that these are written correctly, or omitted if the JPEG file's color space
is not one of the ones supported by the interchange standards.
jpeg_set_colorspace() will set the compression parameters to include or omit
the APPn markers properly, so long as it is told the truth about the JPEG
color space. For example, if you are writing some random 3-component color
space without conversion, don't try to fake out the library by setting
in_color_space and jpeg_color_space to JCS_YCbCr; use JCS_UNKNOWN.
You may want to write an APPn marker of your own devising to identify
the colorspace --- see "Special markers", below.
When told that the color space is UNKNOWN, the library will default to using
luminance-quality compression parameters for all color components. You may
well want to change these parameters. See the source code for
jpeg_set_colorspace(), in jcparam.c, for details.
For decompression, the JPEG file's color space is given in jpeg_color_space,
and this is transformed to the output color space out_color_space.
jpeg_read_header's setting of jpeg_color_space can be relied on if the file
conforms to JFIF or Adobe conventions, but otherwise it is no better than a
guess. If you know the JPEG file's color space for certain, you can override
jpeg_read_header's guess by setting jpeg_color_space. jpeg_read_header also
selects a default output color space based on (its guess of) jpeg_color_space;
set out_color_space to override this. Again, you must select a supported
transformation. jdcolor.c currently supports
YCbCr => RGB
YCbCr => GRAYSCALE
BG_YCC => RGB
BG_YCC => GRAYSCALE
RGB => GRAYSCALE
GRAYSCALE => RGB
YCCK => CMYK
as well as the null transforms. (Since GRAYSCALE=>RGB is provided, an
application can force grayscale JPEGs to look like color JPEGs if it only
wants to handle one case.)
The two-pass color quantizer, jquant2.c, is specialized to handle RGB data
(it weights distances appropriately for RGB colors). You'll need to modify
the code if you want to use it for non-RGB output color spaces. Note that
jquant2.c is used to map to an application-supplied colormap as well as for
the normal two-pass colormap selection process.
CAUTION: it appears that Adobe Photoshop writes inverted data in CMYK JPEG
files: 0 represents 100% ink coverage, rather than 0% ink as you'd expect.
This is arguably a bug in Photoshop, but if you need to work with Photoshop
CMYK files, you will have to deal with it in your application. We cannot
"fix" this in the library by inverting the data during the CMYK<=>YCCK
transform, because that would break other applications, notably Ghostscript.
Photoshop versions prior to 3.0 write EPS files containing JPEG-encoded CMYK
data in the same inverted-YCCK representation used in bare JPEG files, but
the surrounding PostScript code performs an inversion using the PS image
operator. I am told that Photoshop 3.0 will write uninverted YCCK in
EPS/JPEG files, and will omit the PS-level inversion. (But the data
polarity used in bare JPEG files will not change in 3.0.) In either case,
the JPEG library must not invert the data itself, or else Ghostscript would
read these EPS files incorrectly.
Error handling
--------------
When the default error handler is used, any error detected inside the JPEG
routines will cause a message to be printed on stderr, followed by exit().
You can supply your own error handling routines to override this behavior
and to control the treatment of nonfatal warnings and trace/debug messages.
The file example.c illustrates the most common case, which is to have the
application regain control after an error rather than exiting.
The JPEG library never writes any message directly; it always goes through
the error handling routines. Three classes of messages are recognized:
* Fatal errors: the library cannot continue.
* Warnings: the library can continue, but the data is corrupt, and a
damaged output image is likely to result.
* Trace/informational messages. These come with a trace level indicating
the importance of the message; you can control the verbosity of the
program by adjusting the maximum trace level that will be displayed.
You may, if you wish, simply replace the entire JPEG error handling module
(jerror.c) with your own code. However, you can avoid code duplication by
only replacing some of the routines depending on the behavior you need.
This is accomplished by calling jpeg_std_error() as usual, but then overriding
some of the method pointers in the jpeg_error_mgr struct, as illustrated by
example.c.
( run in 0.485 second using v1.01-cache-2.11-cpan-5511b514fd6 )