Page 1 of 1
JPG and GIF decode routines
Posted: Fri May 01, 2009 3:57 am
by Jef
I have already support for BMP images and I want to add support for JPG and GIF at my OS.
I found the headers and some additional information about them but it seems little hard to me, and i don't want to spent time to implement this right now from the scratch .
Can anyone give me a decode routine for this type of images written in asm ?
I know that if you want to make your own OS, you have to try hard, to read a lot of "how to", and not get ready code from others.
But i thing that this is not critical function for an OS, and i prefer to spent my time at kernel functionality.
Thanks.
Re: JPG and GIF decode routines
Posted: Fri May 01, 2009 4:02 am
by JamesM
JPEG decoding involves fourier transforms - all the compression is done on the frequency domain (high frequency signals are culled because the eye can't pick them up as easily). It is therefore an immensely complex task. I suggest googling for fast fourier transform (FFT) algorithms, implement one in asm, then adapt that to implement the JPEG algorithm (inverse FFT of multiple 8x8 matrices).
Re: JPG and GIF decode routines
Posted: Fri May 01, 2009 4:45 am
by skyking
Jef wrote:
I know that if you want to make your own OS, you have to try hard, to read a lot of "how to", and not get ready code from others.
But i thing that this is not critical function for an OS, and i prefer to spent my time at kernel functionality.
Then why bother right now? Implement critical functionality instead, when the C library has enough support you could build libMagick to get decoders for all kinds of image formats.
Re: JPG and GIF decode routines
Posted: Fri May 01, 2009 5:12 am
by Jef
skyking wrote:Then why bother right now? Implement critical functionality instead, when the C library has enough support you could build libMagick to get decoders for all kinds of image formats.
Your are right but,
actually for now, i am writing only in asm.
The reason that i need this right now is that my OS works only with floppy image. I display some images and cannot fit into 1.44MB
So i need some smaller images like jpg.
Re: JPG and GIF decode routines
Posted: Fri May 01, 2009 5:23 am
by slasher
Have you considered looking at the PNG file format?
Re: JPG and GIF decode routines
Posted: Fri May 01, 2009 5:32 am
by Jef
slasher wrote:Have you considered looking at the PNG file format?
No. You think that's is more easier to implement? Or just for the image file size?
I choose jpg because is more common, but if it's easier to implement png, sounds good choice.
Re: JPG and GIF decode routines
Posted: Fri May 01, 2009 6:16 am
by bewing
JPG actually uses something called a "discrete cosine transform" rather than a fourier transform, but the math is very similar. I have worked on a simplified JPG decoder in the past (and it's a lot smaller than the official JPEG group's freeware library), but I have not yet simplified mine enough that it can be translated into ASM by hand. And, at the very least, you would need to have an inverse cosine math function (in ASM?) in your library/kernel before it would work at all.
GIF decode routines may cause you licensing problems with GPL -- which is one of the reasons why PNG was created.
The "best" image format to use depends on what kind of image you are trying to display. If it is something like a photograph, then JPG is probably best. If it is a computer-generated drawing of some sort, then PNG is probably an excellent choice.
Note: If you do use JPG, make sure your image is a multiple of 8 pixels wide (16 is even better), an even number of pixels high (a multiple of 16 is even better), and uses sequential compression (NOT PROGRESSIVE).
Re: JPG and GIF decode routines
Posted: Fri May 01, 2009 7:49 am
by jal
bewing wrote:GIF decode routines may cause you licensing problems with GPL -- which is one of the reasons why PNG was created.
GIF patents have expired a while ago now.
JAL
Re: JPG and GIF decode routines
Posted: Fri May 01, 2009 1:56 pm
by bewing
IIRC -- not in the US. Some of the patents go until 2011.
Re: JPG and GIF decode routines
Posted: Fri May 01, 2009 2:06 pm
by jal
bewing wrote:IIRC -- not in the US. Some of the patents go until 2011.
The US is about the only place that stuff is patentable at all, so I'm pretty sure the source I read was about the US. Wasn't 2011 for some parts of the FAT patent?
EDIT: The Wikipedia says this:
Wikipedia wrote:The US LZW patent expired on June 20, 2003. The counterpart patents in the United Kingdom, France, Germany and Italy expired on June 18, 2004, the Japanese counterpart patents expired on June 20, 2004 and the counterpart Canadian patent expired on July 7, 2004. Consequently, while Unisys has further patents and patent applications relating to improvements to the LZW technique, the GIF format may now be used freely.
The Dutch Wikipedia also mentions, without source:
Dutch Wikipedia wrote:According to research by the Free Software Foundation, the last patent (filed by IBM) expired at Augustus 11th, 2006.
JAL
Re: JPG and GIF decode routines
Posted: Fri May 01, 2009 3:18 pm
by Dex
Sure here alink to some asm code for jpeg decoding,
http://board.flatassembler.net/topic.php?t=1159
Note: you may need to join to see the code.
Also you will find code for gif jpeg decoding in the source code of my OS, in the gui folder.
Also in the source code of KolibriOS you will find libs for jpeg, gif, png etc.
But please give credit if you use the code.
And this is a case of something you should not have to write yourself, like you should not for mp3, its a mathamatic formular.
Re: JPG and GIF decode routines
Posted: Fri May 01, 2009 4:37 pm
by Jef
Dex wrote:But please give credit if you use the code.
And this is a case of something you should not have to write yourself, like you should not for mp3, its a mathamatic formular.
Of course! no problem.
I have download the code. I will see the code the next days, and probable i will use it.
Thanks.