📄 api.asm
字号:
;// Public functions
.686P
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
.XMM
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
INCLUDE jpeg.inc
;//=========================================================================
;// Decode a jpeg buffer
;// params : bufIn : input buffer
;// params : sizeIn : buffer size
;// params : options : options
;// params : pointer to decoded image
;// returns : an error or success code
;//=========================================================================
.CODE
JPEG_Decode PROC STDCALL bufIn:dword, sizIn:dword, pImg:dword, options:dword
BUFIN TEXTEQU <DPTR [esp+4*1]>
SIZIN TEXTEQU <DPTR [esp+4*2]>
PIMG TEXTEQU <DPTR [esp+4*3]>
OPTS TEXTEQU <DPTR [esp+4*4]>
sub eax, eax
pushad
DBGSTART
;// zero pointer param
mov eax, PIMG[SPUSHAD]
mov DPTR [eax], 0
;// allocate decoder structure
mov eax, sizeof(DECODER)
call MEM_Alloc
jz ErrorMem
mov Ctx, eax
mov [Ctx].Magic, MAGIC
;// init decoder
mov eax, OPTS[SPUSHAD]
call JPG_InitDecoder
test eax, eax
jz DecEnd
;// init bitstream
mov esi, BUFIN[SPUSHAD]
mov ecx, SIZIN[SPUSHAD]
call BS_Init
;// decode loop
DecLoop:
call JPG_GetMarker
test eax, eax
jz DecEnd
call JPG_ProcessMarker
test eax, eax
jnz DecLoop
DecEnd:
mov bl, BPTR [Ctx].LastError
cmp bl, JPEG_SUCCESS
jne Error
;// return context
mov ecx, PIMG[SPUSHAD]
mov [ecx], Ctx
AError:
mov BPTR [esp]._PUSHAD._EAX, bl
Done:
DBGSTOP
popad
ret 4*4
Error:
push Ctx
call JPEG_Free
jmp AError
ErrorMem:
mov bl, JPEG_OUTOFMEM
jmp AError
JPEG_Decode ENDP
;//=========================================================================
;// Free memory
;// params : a pointer to a RGB_IMAGE (no error if null)
;// returns : eax = 0
;//=========================================================================
JPEG_Free PROC STDCALL img:dword
IMG TEXTEQU <DPTR [esp+4*1]>
push Ctx
mov Ctx, IMG[4*1]
test Ctx, Ctx
jz Done
cmp [Ctx].Magic, MAGIC
jne Corrupt
FreeMem:
mov eax, [Ctx].AllocMem
call MEM_Free
mov [Ctx].Magic, eax
mov eax, Ctx
call MEM_Free
Done:
pop Ctx
ret 4*1
Corrupt:
;// fatal error
int 3
jmp FreeMem
JPEG_Free ENDP
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -