Malcolm McLean said:
Firstly you need to grab the drawing area as an array of rgb values. This
can be done by iteratively calling a function with a name like getpixel()
or similar - I am not familiar with your particular graphics package.
I think I recognize it...
I think it is some Borland specific graphics interface (I think I remember
it being available with their older DOS-based compilers, don't know if it is
still maintained, or has been cloned...).
my opinion:
this is not likely the way I would do graphics;
usually, if I am doing any kind of raster graphics, I usually use a big flat
array which I can draw into directly;
as needed, this framebuffer can be drawn in whatever way is useful, or can
be saved to a file or whatever (explicit framebuffers are far more general
and flexible than some special-purpose graphics library).
in my case, I usually use OpenGL, so glWritePixels is good for raw display,
or the image can be loaded into a texture (much more common IME), or
compressed and saved out (very often if I am drawing into images directly,
they are for some special task, such as serving as lightmaps, ... so, they
are usually created and stored out).
Once you've done that, grap my savejpeg.c program from my website and
simply call with the raster, the name of the file you wish to create, and
the image dimensions. You'll proably want to fiddle with the code to give
control over the compression ratio.
yeah.
in my case, I had used a floating point value for controlling the quality
level, and a special set of algos for analyzing the DCT blocks and comming
up with a good set of quantizer values (at the time, I beat them together
experimentally, and this worked acceptably).
for my higher-speed compressor, I think I had an algo that came up with
quantizers for a particular quality level, which was based on more or less a
hand-tuned set of exponential equations (linear, square, and cubic factors).
this was faster in that it did not involve scanning over the blocks, but had
a worse quality/ratio tradeoff as a reult of it being that the quantizers
were not really tuned to the image.
I think scaling a fixed table of quantizer values is also possible, but IME
does not really produce as good of results (the ideal relation between the
components at various quality levels does not seem to be strictly linear).
also possible would be to add a function to search for the best quality
setting to produce a given sized output (would be useful in allowing setting
particular bitrates for MJPEG files, ...).
or such...