Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibJPEG/libjpeg.txt view on Meta::CPAN
functions. To do this, undefine xxx_SUPPORTED symbols as necessary.
You can also save a few K by not having text error messages in the library;
the standard error message table occupies about 5Kb. This is particularly
reasonable for embedded applications where there's no good way to display
a message anyway. To do this, remove the creation of the message table
(jpeg_std_message_table[]) from jerror.c, and alter format_message to do
something reasonable without it. You could output the numeric value of the
message code number, for example. If you do this, you can also save a couple
more K by modifying the TRACEMSn() macros in jerror.h to expand to nothing;
you don't need trace capability anyway, right?
Portability considerations
--------------------------
The JPEG library has been written to be extremely portable; the sample
applications cjpeg and djpeg are slightly less so. This section summarizes
the design goals in this area. (If you encounter any bugs that cause the
library to be less portable than is claimed here, we'd appreciate hearing
about them.)
The code works fine on ANSI C, C++, and pre-ANSI C compilers, using any of
the popular system include file setups, and some not-so-popular ones too.
See install.txt for configuration procedures.
The code is not dependent on the exact sizes of the C data types. As
distributed, we make the assumptions that
char is at least 8 bits wide
short is at least 16 bits wide
int is at least 16 bits wide
long is at least 32 bits wide
(These are the minimum requirements of the ANSI C standard.) Wider types will
work fine, although memory may be used inefficiently if char is much larger
than 8 bits or short is much bigger than 16 bits. The code should work
equally well with 16- or 32-bit ints.
In a system where these assumptions are not met, you may be able to make the
code work by modifying the typedefs in jmorecfg.h. However, you will probably
have difficulty if int is less than 16 bits wide, since references to plain
int abound in the code.
char can be either signed or unsigned, although the code runs faster if an
unsigned char type is available. If char is wider than 8 bits, you will need
to redefine JOCTET and/or provide custom data source/destination managers so
that JOCTET represents exactly 8 bits of data on external storage.
The JPEG library proper does not assume ASCII representation of characters.
But some of the image file I/O modules in cjpeg/djpeg do have ASCII
dependencies in file-header manipulation; so does cjpeg's select_file_type()
routine.
The JPEG library does not rely heavily on the C library. In particular, C
stdio is used only by the data source/destination modules and the error
handler, all of which are application-replaceable. (cjpeg/djpeg are more
heavily dependent on stdio.) malloc and free are called only from the memory
manager "back end" module, so you can use a different memory allocator by
replacing that one file.
The code generally assumes that C names must be unique in the first 15
characters. However, global function names can be made unique in the
first 6 characters by defining NEED_SHORT_EXTERNAL_NAMES.
More info about porting the code may be gleaned by reading jconfig.txt,
jmorecfg.h, and jinclude.h.
Notes for MS-DOS implementors
-----------------------------
The IJG code is designed to work efficiently in 80x86 "small" or "medium"
memory models (i.e., data pointers are 16 bits unless explicitly declared
"far"; code pointers can be either size). You may be able to use small
model to compile cjpeg or djpeg by itself, but you will probably have to use
medium model for any larger application. This won't make much difference in
performance. You *will* take a noticeable performance hit if you use a
large-data memory model (perhaps 10%-25%), and you should avoid "huge" model
if at all possible.
The JPEG library typically needs 2Kb-3Kb of stack space. It will also
malloc about 20K-30K of near heap space while executing (and lots of far
heap, but that doesn't count in this calculation). This figure will vary
depending on selected operating mode, and to a lesser extent on image size.
There is also about 5Kb-6Kb of constant data which will be allocated in the
near data segment (about 4Kb of this is the error message table).
Thus you have perhaps 20K available for other modules' static data and near
heap space before you need to go to a larger memory model. The C library's
static data will account for several K of this, but that still leaves a good
deal for your needs. (If you are tight on space, you could reduce the sizes
of the I/O buffers allocated by jdatasrc.c and jdatadst.c, say from 4K to
1K. Another possibility is to move the error message table to far memory;
this should be doable with only localized hacking on jerror.c.)
About 2K of the near heap space is "permanent" memory that will not be
released until you destroy the JPEG object. This is only an issue if you
save a JPEG object between compression or decompression operations.
Far data space may also be a tight resource when you are dealing with large
images. The most memory-intensive case is decompression with two-pass color
quantization, or single-pass quantization to an externally supplied color
map. This requires a 128Kb color lookup table plus strip buffers amounting
to about 40 bytes per column for typical sampling ratios (eg, about 25600
bytes for a 640-pixel-wide image). You may not be able to process wide
images if you have large data structures of your own.
Of course, all of these concerns vanish if you use a 32-bit flat-memory-model
compiler, such as DJGPP or Watcom C. We highly recommend flat model if you
can use it; the JPEG library is significantly faster in flat model.
( run in 0.444 second using v1.01-cache-2.11-cpan-501a3233654 )