[fpc-pascal]How to use Linux libraries?
michalis at camelot.homedns.org
Sat Jul 26 06:50:13 CEST 2003
Pasjpeg is basically just a Pascal translation of sources originally
written in ANSI C by IJG, Independent JPEG Group. You can find this C
code with documentation at http://www.ijg.org/. At these URL there are
also some informations about JPEG file coding (actually JFIF, JPEG is a
standard for compressing image data and JFIF is a file format that uses
JPEG compression; JFIF stands for "JPEG File Interchange Format"). But
you will not find there a complete specification of JPEG format and, to
be honest, I don't know where you can find it on the internet.
Definitely, coding JPEG [de]compression by yourself is really an
advanced topic and I would not advice you this.
Besides, Pasjpeg can really do all that you want. Pasjpeg contains some
extra units not found in IJG code - mainly Jeg.pas and Pasjpeg.pas.
The first one implements a class that loads a jpeg image into a TGraphic
class descendant from Graphics unit. Graphics unit comes from Delphi's
VCL and it's not available with FPC - but I know Lazarus tries to
implement library compatible with VCL (but Lazarus does it for FPC and
for many platforms FPC supports), so maybe you could integrate Jpeg with
Lazarus (I don't know, maybe they even already did that in Lazarus ?).
So that's the first option you can try.
The second option is to take Jpeg unit and tweak it so that it is
capable of reading and storing jpeg images in your preferable format,
like simple two-dimensional array of RGB. For that you will definitely
need IJG documentation to understand how Jpeg unit works - it's really
too big subject to describe it in this letter.
Third option is probably the easiest one - you can use Pasjpeg unit to
convert jpeg files into BMP files. Than you can learn how to read BMP
files, it's really simple, and after doing that you will be able to read
both BMP and JPEG images in quite the same way, you will only have to
"filter" JPEG images through Pasjpeg. Not very elegant way to read JPEG
images, but simple and working.
There is also a forth option, probably the hardets one : read IJG
documentation and write your own code to handle pasjpeg library without
Pasjpeg and Jpeg units (I hope you don't get confused when I sometimes
use "pasjpeg" to name the whole "pasjpeg library" and sometimes to name
the specific unit named "Pasjpeg.pas" in that library). Actually, if you
learn how to do that you will not need pasjpeg library - under Linux
there is usually a libjpeg.so shared library that contains whole IJG
code, so you will not have to use pasjpeg library - just link
dynamically to libjpeg.so (or statically to libjpeg.a).
Final words : what do I advise : take the easiest way - learn how to
read BMP images and than use Pasjpeg unit. Also, there is a question -
do you really need the JPEG format ? If you want just ANY image format
than thinking about JPEG is a big mistake - there are many image formats
MUCH easier to read. E.g. PPM (the simplest possible image format, you
can handle it with a few lines of code), PNG (nice format with lots of
capabilities and lossless compression (you DO know that JPEG compression
is lossy, do you?), very easily readable with libpng) and so on. BMP
format is somewhere between, it's a bit more complicated and a bit more
functional than PPM - if you don't care about JPEGs anymore I would
advice you PPM (or more general PNM) or PNG formats.
And remember there are many programs that can convert JPEG images into
other formats (like PPM and PNG).
Oh, one more thing - Pasjpeg unit uses TStream classes and you said you
dont like Classes. But, really, they are so simple - I guarantee that
you will be glad when you learn how to use them and when you see what
TStream and it's descendants can do for you.
Hope this helps,
michalis at camelot.homedns.org
More information about the fpc-pascal