Hello all,

I'm working on a jpeg decoder and I finally have something that can decode jpeg files loaded in memory and display them in a window. It will decode the most common types of jpeg (except progressive jpegs...)

There is a decoding library and a sample program. The interface of the decoder is very simple :



include jpeg_dec.inc

.data
img dword ?

.code
; decode a jpeg
INVOKE JPEG_Decode OFFSET jpeg_buffer, jpeg_size, OFFSET img, 0
cmp eax, JPEG_SUCCESS
jne Error

mov eax, img
ASSUME eax:PTR JPEGIMAGE
; use the image :
; [eax].width : image width
; [eax].height : image height
; [eax].pRGB : pointer to rgb data

; free the image
INVOKE JPEG_Free img


It is not super fast because I use floating point SSE for all calculations (IDCT, rgb conversion...) The benefit is that it should be precise and I will be able to extend it to support jpeg with 12-bit precision.

Bugs and limitations :
- requires SSE
- 12-bit precision not supported
- supports only jpeg with sampling factor 1x1, 2x2, 2x1, 1x2

If you find a problem with an image could you send it to manhattan95@wanadoo.fr please ? Thanks.
Posted on 2004-10-23 13:29:50 by Dr. Manhattan
Hi,

It works for me, just that it could not open one file (probably progressive jpg since it gave the error format not support). Keep up the good job, mate.
Posted on 2004-10-23 14:04:50 by roticv
wow, i can call this very impressive (altough i don't know exact how jpg's work). great job!
Posted on 2004-10-23 14:26:06 by lifewire
Thank you for your comments. I found why some images were not decoded correctly. I uploaded a new version of the files. Thanks.
Posted on 2004-10-24 08:57:51 by Dr. Manhattan
Very impressive indeed!
Posted on 2004-10-24 10:15:55 by comrade
The only two pictures it would not open were due to their size, recieved "can't allocate graphic object" error. This is great work :!:
Posted on 2004-10-24 11:09:39 by bitRAKE
I can't check your work just now, but I would be glad if it isn't as buggy as the image library from the MASM package. Keep up the (good) work :)


/siddhartha
Posted on 2004-11-06 11:37:53 by siddhartha
Impressive :alright:
Also found several images that return "format not supported", but the viewer renders the supported images really quickly.
Posted on 2004-11-06 14:31:56 by Ultrano
Thank you all. I've found bugs with some malformed jpeg files. I have also found a big memory leak when the window was closed with a file opened :oops:
I have uploaded a new version that fix these bugs. If you are interested, there is also a sourceforge project at http://sourceforge.net/projects/jpegdec
Posted on 2004-11-06 15:00:42 by Dr. Manhattan
Hi Dr.Manhattan,

The link above gives:
Invalid Project

:?
Posted on 2004-11-07 03:35:07 by Vortex
Just remove the dot after it, thus you get:
http://sourceforge.net/projects/jpegdec
:-D
Posted on 2004-11-07 04:22:56 by Ultrano
Funly.
but the sample is C code,I wanna the masm code,would you like paste it?
thanks.
Posted on 2009-11-03 18:02:52 by pmason_rose

Funly.
but the sample is C code,I wanna the masm code,would you like paste it?
thanks.


Are you sure that the code on http://sourceforge.net/projects/jpegdec is C code?  :shock:
Posted on 2009-11-03 21:43:47 by JimmyClif
thank your reply.
The viewer code is true C,I link it use Vc6.0 .

for this code,why it exit with error!

.386
.model flat, stdcall  ;32 bit memory model
option casemap :none  ;case sensitive
include windows.inc
include kernel32.inc
include user32.inc
include Comctl32.inc
include shell32.inc

includelib kernel32.lib
includelib user32.lib
includelib Comctl32.lib
includelib shell32.lib
include macros.asm

include jpeg_dec.inc
includelib jpeg_dec.lib
.const
IDD_DIALOG1 equ 101
.data?
hInstance dd ?
hFile dd ?
dwFileSize dd ?
lpJpegMemory dd ?
jimg dd ?
.code
DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL @dwBytesRead
mov eax,uMsg
.if eax==WM_INITDIALOG

.elseif eax==WM_COMMAND
mov eax,wParam
.if ax == IDOK
invoke CreateFile,CTXT("test.JPG"),GENERIC_READ,FILE_SHARE_READ or FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
mov hFile,eax
invoke GetFileSize,hFile,NULL
mov dwFileSize,eax
invoke GlobalAlloc,GPTR,dwFileSize
mov lpJpegMemory,eax
invoke ReadFile,hFile,lpJpegMemory,dwFileSize,addr @dwBytesRead,0

invoke JPEG_Decode,lpJpegMemory,dwFileSize,addr jimg,NULL
.if eax==JPEG_SUCCESS
invoke MessageBox,NULL,CTXT("OK"),NULL,MB_OK
.endif
invoke JPEG_Free,addr jimg
.endif
.elseif eax==WM_CLOSE
invoke EndDialog,hWin,0
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret

DlgProc endp
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
    invoke InitCommonControls
invoke DialogBoxParam,hInstance,IDD_DIALOG1,NULL,addr DlgProc,NULL
invoke ExitProcess,0
end start
Posted on 2009-11-04 00:55:23 by pmason_rose
What kind of error does it give you? Is the error rerlated to the jpeg_decoder?
Posted on 2009-11-04 11:15:31 by JimmyClif
hi!
someone write the masm32's code to change JPEG file to BMP file use this lib ?
please paste the code,please,thanks
Posted on 2009-11-06 03:59:45 by pmason_rose
:lol:
Attachments:
Posted on 2010-05-12 04:27:29 by pmason_rose