JPEGV Beta Version 2 by Antoni Gual (agual@eic.ictnet.es) march 2001
-------------------------------------------------------------------------------------------


The copy of my first JPEG viewer at Future Software has been downoaded by 1600 people 
in 3 years, so I projected to enhance it with a decent user interface, panning by using 
EMS, ability to read all JPEG headers, even if unable to decode it, a bsave-bload 
routine  and the decoding of progressive jpegs. But my proffessional work, my family, my cat 
and my laziness stopped me in the project. Well, the true is now i'm interested in language
scanners and parsers, so.. 
I offer you the work where it is so far, I hope it will be of your interest, with all it's
defaults.

WARNING:
--------
Setting your video card to resolutions  your monitor can't handle can damage the monitor!
This is why the program starts at a low and safe 640x480x8 resolution. Try the highest 
resolutions at your own risk! If the monitor starts to complain, press ESC!!


What's new:
-----------

-Some silly bugs solved. Thanks to Torben Schramme and Tom Lake for their help.

- It's 40% faster in the IDE and ~2 times faster compiled than the first version.
  For example it decodes a 3,5 Mpixel (2400 x 1600) image to a 1280*1024 screen in 10,2 sec
  in a W98 DOS window in a cheap P4 1.4. The first version needed 19,8 seconds in the same
  machine.
 (Speed increase has been achieved without a single line of assembler or external libraries)

-The assembler CALL INTERRUPT is here only to open the program to QB 1.1 users. 
 The 3,5 Megapixel test image is decoded in 59 seconds in QB1.1. Not so fast..

-A Serious looking file selector, with LFN (if in Win95+). Uses shell calls to DOS DIR so
 probably it will not work in WNT or W2000. The file selector itself accounts for 13 K of 
 source..

-The SVGA 24 bits modes are banned for speed reasons. See How I managed to make this thing so fast
 
-Two IDCT algorithms you can select, the Arai, Agui &Nakajima is fast and dirty (I could
 have some bug there), the Loeffler  Ligtenberg-Moschytz is more accurate and slower. I have 
 translated them from the C JPEG library of the Independent JPEG Group, by Thomas G.Lane.

-Better main menu. Program don't ask you to input the video mode for each image displayed.

-Scalable SVGA text print routine that keeps the screen messages readable at almost all
 resolutions.


Image specs
-----------

This program displays JPEG images:
Colorspace: JFIF (Y-Cb-Cr 3 interleaved components) and Monochrome
Sample size: 8 bits (not 12 bits, well, i think it could work)
DCT based (not losless)
Huffman encoded with 2 DC and 2 DC tables (no arithmetic encoding)
Mode of operation: Sequential (not  progressive or hierarchical)

Trying to load an image with another format will break the program as in the first version..

No XMS and no EMS are used.It uses assembler ONLY to call interrupts.
The only way to reach the VESA API for SVGA) This way the program can be run in QB 1.1


How I managed to make this thing so fast
------------------------------------------

When I finished first version I believed only marginal increase was possible. But then I 
entered the QB Demo coder's world. People as Toshi, Enthropy, Qasir and many others taught
me things that I believed impossible in QB. This second version is the result of two years
learning how to do things really fast. There are some things i did:

-Improved bit handling at Huffman decoder, bit handling is where QB fails.

-The program builds now a true Huffman tree while reading Huffman table, this way it can
 do a fast tree search instead of check sequentially entries in a table as exposed  in 
 JPEG spec.

-For the IDCT I Translated the AAN algorithm from C to QB, this algorithm is very 
 approximative it creates  a lot of noise, but is 15% faster. Don't ask me about the theory
 behind the algorithm, I just translated it.

-The program changes the default line length of the SVGA mode it's using to one that keeps the 
 bank boundaries off the screen, so bank checking at each pixel is no more needed. This is 
 memory consuming, and this is why highest resolutions are no more available for small memory 
 cards. 
 The 24 bit color mode was formerly achieved by video cards using 4 bytes per pixel,
 wasting a byte per pixel. This program always supports thsi mode. Some new cards use 3 bytes
 per pixel in the 24 bit mode.
 Unfortunately, with 3 bytes/pixel no line length can hold an integer number of pixels 
 and be also an integer divisor of the bank size (64K). So I don't support 3 byte modes anymore.
 I imagine these cards were designed with linear addressing in mind, this no-banking scheme
 can only be used in protected mode.

-I Substituted a lot of calculations in colorspace translation and writing to screen 
 memory for precalculated look up tables, there are 12 or more of them. 

-I integrated the screen writes to the JPEGPut routine, avoiding repeated calls to
 SVGAPutPixel.

-The scaled text writer has been improved. Now it works line by line, it's more SVGA friendly.
 
WHO SAID QB IS SLOW?

NOTES:
------

-Don't try to compile it in QB 4.0, the result is slower as no floating point is used.
 Compiling with the FFIX patch gives no improvement.


Enjoy it, and e-mail me your comments! It will eventually encourage me to implement all the
goodies of the original project.

Antoni Gual (agual@eic.ictnet.es)







	 
 
