mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-02 17:49:01 +08:00
图片阅览器
This commit is contained in:
@@ -23,7 +23,7 @@ haribote.img : haribote/ipl20.bin haribote/haribote.sys Makefile \
|
|||||||
sosu/sosu.hrb sosu2/sosu2.hrb sosu3/sosu3.hrb \
|
sosu/sosu.hrb sosu2/sosu2.hrb sosu3/sosu3.hrb \
|
||||||
type/type.hrb iroha/iroha.hrb chklang/chklang.hrb \
|
type/type.hrb iroha/iroha.hrb chklang/chklang.hrb \
|
||||||
notrec/notrec.hrb bball/bball.hrb invader/invader.hrb \
|
notrec/notrec.hrb bball/bball.hrb invader/invader.hrb \
|
||||||
calc/calc.hrb tview/tview.hrb mmlplay/mmlplay.hrb
|
calc/calc.hrb tview/tview.hrb mmlplay/mmlplay.hrb gview/gview.hrb
|
||||||
$(EDIMG) imgin:../z_tools/fdimg0at.tek \
|
$(EDIMG) imgin:../z_tools/fdimg0at.tek \
|
||||||
wbinimg src:haribote/ipl20.bin len:512 from:0 to:0 \
|
wbinimg src:haribote/ipl20.bin len:512 from:0 to:0 \
|
||||||
copy from:haribote/haribote.sys to:@: \
|
copy from:haribote/haribote.sys to:@: \
|
||||||
@@ -62,6 +62,9 @@ haribote.img : haribote/ipl20.bin haribote/haribote.sys Makefile \
|
|||||||
copy from:mmldata/fujisan.mml to:@: \
|
copy from:mmldata/fujisan.mml to:@: \
|
||||||
copy from:mmldata/daigo.mml to:@: \
|
copy from:mmldata/daigo.mml to:@: \
|
||||||
copy from:mmldata/daiku.mml to:@: \
|
copy from:mmldata/daiku.mml to:@: \
|
||||||
|
copy from:gview/gview.hrb to:@: \
|
||||||
|
copy from:pictdata/fujisan.jpg to:@: \
|
||||||
|
copy from:pictdata/night.bmp to:@: \
|
||||||
copy from:nihongo/nihongo.fnt to:@: \
|
copy from:nihongo/nihongo.fnt to:@: \
|
||||||
imgout:haribote.img
|
imgout:haribote.img
|
||||||
|
|
||||||
@@ -108,6 +111,7 @@ full :
|
|||||||
$(MAKE) -C calc
|
$(MAKE) -C calc
|
||||||
$(MAKE) -C tview
|
$(MAKE) -C tview
|
||||||
$(MAKE) -C mmlplay
|
$(MAKE) -C mmlplay
|
||||||
|
$(MAKE) -C gview
|
||||||
$(MAKE) haribote.img
|
$(MAKE) haribote.img
|
||||||
|
|
||||||
run_full :
|
run_full :
|
||||||
@@ -162,6 +166,7 @@ clean_full :
|
|||||||
$(MAKE) -C calc clean
|
$(MAKE) -C calc clean
|
||||||
$(MAKE) -C tview clean
|
$(MAKE) -C tview clean
|
||||||
$(MAKE) -C mmlplay clean
|
$(MAKE) -C mmlplay clean
|
||||||
|
$(MAKE) -C gview clean
|
||||||
|
|
||||||
src_only_full :
|
src_only_full :
|
||||||
$(MAKE) -C haribote src_only
|
$(MAKE) -C haribote src_only
|
||||||
@@ -195,6 +200,7 @@ src_only_full :
|
|||||||
$(MAKE) -C calc src_only
|
$(MAKE) -C calc src_only
|
||||||
$(MAKE) -C tview src_only
|
$(MAKE) -C tview src_only
|
||||||
$(MAKE) -C mmlplay src_only
|
$(MAKE) -C mmlplay src_only
|
||||||
|
$(MAKE) -C gview src_only
|
||||||
-$(DEL) haribote.img
|
-$(DEL) haribote.img
|
||||||
|
|
||||||
refresh :
|
refresh :
|
||||||
|
|||||||
1
30_day/gview/!cons_9x.bat
Normal file
1
30_day/gview/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
|||||||
|
command
|
||||||
1
30_day/gview/!cons_nt.bat
Normal file
1
30_day/gview/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
|||||||
|
cmd.exe
|
||||||
90
30_day/gview/Makefile
Normal file
90
30_day/gview/Makefile
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
APP = gview
|
||||||
|
STACK = 4480k
|
||||||
|
MALLOC = 0k
|
||||||
|
|
||||||
|
TOOLPATH = ../../z_tools/
|
||||||
|
INCPATH = ../../z_tools/haribote/
|
||||||
|
APILIBPATH = ../apilib/
|
||||||
|
HARIBOTEPATH = ../haribote/
|
||||||
|
|
||||||
|
MAKE = $(TOOLPATH)make.exe -r
|
||||||
|
NASK = $(TOOLPATH)nask.exe
|
||||||
|
CC1 = $(TOOLPATH)cc1.exe -I$(INCPATH) -I../ -Os -Wall -quiet
|
||||||
|
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
|
||||||
|
OBJ2BIM = $(TOOLPATH)obj2bim.exe
|
||||||
|
MAKEFONT = $(TOOLPATH)makefont.exe
|
||||||
|
BIN2OBJ = $(TOOLPATH)bin2obj.exe
|
||||||
|
BIM2HRB = $(TOOLPATH)bim2hrb.exe
|
||||||
|
BIM2BIN = $(TOOLPATH)bim2bin.exe
|
||||||
|
RULEFILE = ../haribote.rul
|
||||||
|
EDIMG = $(TOOLPATH)edimg.exe
|
||||||
|
IMGTOL = $(TOOLPATH)imgtol.com
|
||||||
|
GOLIB = $(TOOLPATH)golib00.exe
|
||||||
|
COPY = copy
|
||||||
|
DEL = del
|
||||||
|
|
||||||
|
#默认动作
|
||||||
|
|
||||||
|
default :
|
||||||
|
$(MAKE) $(APP).hrb
|
||||||
|
|
||||||
|
#文件生成规则
|
||||||
|
|
||||||
|
$(APP).bim : $(APP).obj bmp.obj jpeg.obj $(APILIBPATH)apilib.lib Makefile
|
||||||
|
$(OBJ2BIM) @$(RULEFILE) out:$(APP).bim map:$(APP).map stack:$(STACK) \
|
||||||
|
$(APP).obj jpeg.obj bmp.obj $(APILIBPATH)apilib.lib
|
||||||
|
|
||||||
|
haribote.img : ../haribote/ipl20.bin ../haribote/haribote.sys $(APP).hrb \
|
||||||
|
Makefile
|
||||||
|
$(EDIMG) imgin:../../z_tools/fdimg0at.tek \
|
||||||
|
wbinimg src:../haribote/ipl20.bin len:512 from:0 to:0 \
|
||||||
|
copy from:../haribote/haribote.sys to:@: \
|
||||||
|
copy from:$(APP).hrb to:@: \
|
||||||
|
copy from:../nihongo/nihongo.fnt to:@: \
|
||||||
|
imgout:haribote.img
|
||||||
|
|
||||||
|
# 其他指令
|
||||||
|
|
||||||
|
%.gas : %.c ../apilib.h Makefile
|
||||||
|
$(CC1) -o $*.gas $*.c
|
||||||
|
|
||||||
|
%.nas : %.gas Makefile
|
||||||
|
$(GAS2NASK) $*.gas $*.nas
|
||||||
|
|
||||||
|
%.obj : %.nas Makefile
|
||||||
|
$(NASK) $*.nas $*.obj $*.lst
|
||||||
|
|
||||||
|
%.org : %.bim Makefile
|
||||||
|
$(BIM2HRB) $*.bim $*.org $(MALLOC)
|
||||||
|
|
||||||
|
%.hrb : %.org Makefile
|
||||||
|
$(BIM2BIN) -osacmp in:$*.org out:$*.hrb
|
||||||
|
|
||||||
|
# 运行程序
|
||||||
|
|
||||||
|
run :
|
||||||
|
$(MAKE) haribote.img
|
||||||
|
$(COPY) haribote.img ..\..\z_tools\qemu\fdimage0.bin
|
||||||
|
$(MAKE) -C ../../z_tools/qemu
|
||||||
|
|
||||||
|
full :
|
||||||
|
$(MAKE) -C $(APILIBPATH)
|
||||||
|
$(MAKE) $(APP).hrb
|
||||||
|
|
||||||
|
run_full :
|
||||||
|
$(MAKE) -C $(APILIBPATH)
|
||||||
|
$(MAKE) -C ../haribote
|
||||||
|
$(MAKE) run
|
||||||
|
|
||||||
|
clean :
|
||||||
|
-$(DEL) *.lst
|
||||||
|
-$(DEL) gview.obj
|
||||||
|
-$(DEL) jpeg.obj
|
||||||
|
-$(DEL) *.map
|
||||||
|
-$(DEL) *.bim
|
||||||
|
-$(DEL) *.org
|
||||||
|
-$(DEL) haribote.img
|
||||||
|
|
||||||
|
src_only :
|
||||||
|
$(MAKE) clean
|
||||||
|
-$(DEL) $(APP).hrb
|
||||||
646
30_day/gview/bmp.nasm
Normal file
646
30_day/gview/bmp.nasm
Normal file
@@ -0,0 +1,646 @@
|
|||||||
|
; BMP decode routine by I.Tak. 2003
|
||||||
|
|
||||||
|
section .text align=1
|
||||||
|
[bits 32]
|
||||||
|
;BMP File Structure (I can't understand MS.)
|
||||||
|
|
||||||
|
struc BMP
|
||||||
|
;FILE HEADER
|
||||||
|
.fType: resw 1 ;BM
|
||||||
|
.fSize: resd 1 ;whole file size
|
||||||
|
resd 1 ;reserved
|
||||||
|
.fOffBits: resd 1 ;offset from file top to image
|
||||||
|
;INFO HEADER
|
||||||
|
.iSize: resd 1 ;INFO HEADER size
|
||||||
|
.iWidth: resd 1 ;Image Width in pixels
|
||||||
|
.iHeight: resd 1 ;Image Height in pixels
|
||||||
|
.iPlanes: resw 1 ;must be 1
|
||||||
|
.iBitCount: resw 1 ;BitPerPixel 1, 4, 8, 24 (and 15,16 for new OS/2 ?)
|
||||||
|
.iCompression: resd 1 ;Compress Type. 0 for none, then SizeImage=0
|
||||||
|
.iSizeImage: resd 1 ;Image Size(compressed)
|
||||||
|
.iXPPM: resd 1 ;X Pixel Per Meter
|
||||||
|
.iYPPM: resd 1
|
||||||
|
.iClrUsed: resd 1 ;Number of used ColorQuad (0 for whole Quad)
|
||||||
|
.iClrImportant: resd 1 ;Number of Important ColorQuad.
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
struc BMPOS2
|
||||||
|
;FILE HEADER
|
||||||
|
.fType: resw 1 ;BM
|
||||||
|
.fSize: resd 1 ;whole file size
|
||||||
|
resd 1 ;reserved
|
||||||
|
.fOffBits: resd 1 ;offset from file top to image
|
||||||
|
;CORE HEADER
|
||||||
|
.iSize: resd 1 ;CORE HEADER size
|
||||||
|
.iWidth: resw 1 ;Image Width in pixels
|
||||||
|
.iHeight: resw 1 ;Image Height in pixels
|
||||||
|
.iPlanes: resw 1 ;must be 1
|
||||||
|
.iBitCount: resw 1 ;BitPerPixel 1, 4, 8, 24 (and 15,16 for new OS/2 ?)
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; B/W bmp can also have palettes. The first for 0, second for 1.
|
||||||
|
|
||||||
|
struc CQuad
|
||||||
|
.b: resb 1
|
||||||
|
.g: resb 1
|
||||||
|
.r: resb 1
|
||||||
|
resb 1 ;reserved
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
|
||||||
|
%if 0
|
||||||
|
int info_BMP(struct DLL_STRPICENV *env, int *info, int size, UCHAR *fp);
|
||||||
|
/* 成功したら1 (非0?), 失敗したら0 */
|
||||||
|
int decode0_BMP(struct DLL_STRPICENV *env, int size, UCHAR *fp,
|
||||||
|
int b_type, UCHAR *buf, int skip);
|
||||||
|
/* エラーコードを返す。とりあえず非0にしてるだけ */
|
||||||
|
envは64KBのワークエリアである。先頭8dwは返り値用になっている。
|
||||||
|
揮発性らしく, インスタンス変数的には使えないようだ。JPEG_initで
|
||||||
|
base_imgを作るのはdecodeのときだけでいいと思う。
|
||||||
|
%endif
|
||||||
|
|
||||||
|
[absolute 0] ;naskなら[section .bss] org 0 かな win32だからダメか
|
||||||
|
bmpinfo:
|
||||||
|
.regs: resd 4
|
||||||
|
.reteip: resd 1
|
||||||
|
.env: resd 1
|
||||||
|
.info: resd 1
|
||||||
|
.size: resd 1
|
||||||
|
.module: resd 1
|
||||||
|
[absolute 0]
|
||||||
|
info:
|
||||||
|
.type: resd 1 ;1 for BMP, 2 for JPEG
|
||||||
|
resd 1 ;0
|
||||||
|
.width: resd 1
|
||||||
|
.height: resd 1
|
||||||
|
[section .text]
|
||||||
|
[global _info_BMP]
|
||||||
|
_info_BMP:
|
||||||
|
push ebx
|
||||||
|
push ebp
|
||||||
|
push esi
|
||||||
|
push edi
|
||||||
|
mov esi, [esp+bmpinfo.module]
|
||||||
|
mov eax, [esp+bmpinfo.size]
|
||||||
|
call bmpHeader
|
||||||
|
test edi, edi
|
||||||
|
jz .ret
|
||||||
|
mov esi, [esp+bmpinfo.info]
|
||||||
|
mov [esi+info.width], eax
|
||||||
|
mov [esi+info.height], ecx
|
||||||
|
mov [esi+info.type], edi ;=1
|
||||||
|
dec edi
|
||||||
|
mov [esi+info.type+4], edi ;=0
|
||||||
|
inc edi
|
||||||
|
.ret: mov eax, edi
|
||||||
|
pop edi
|
||||||
|
pop esi
|
||||||
|
pop ebp
|
||||||
|
pop ebx
|
||||||
|
ret
|
||||||
|
|
||||||
|
;in: esi=module, eax=size
|
||||||
|
;ret:eax=width, ecx=hegiht, edx=paletteSize, ebx=palette
|
||||||
|
; ebp=bpp, esi=endOfImage, edi=successFlag
|
||||||
|
bmpHeader:
|
||||||
|
lea edx, [esi+eax] ;moduleEnd
|
||||||
|
xor edi, edi
|
||||||
|
push edx
|
||||||
|
xor edx, edx
|
||||||
|
|
||||||
|
cmp eax, byte BMP.iSize+4
|
||||||
|
jbe ..@ret ;中継してしまう
|
||||||
|
cmp word[esi],'BM'
|
||||||
|
je .notMAC
|
||||||
|
sub esi, byte -128
|
||||||
|
add eax, byte -128
|
||||||
|
pop ebx
|
||||||
|
push eax
|
||||||
|
cmp eax, byte BMP.iSize+4
|
||||||
|
..@ret: jbe .ret
|
||||||
|
cmp word[esi], 'BM'
|
||||||
|
jne .ret
|
||||||
|
.notMAC:
|
||||||
|
;;MS,OS/2 フォーマット確認
|
||||||
|
mov ecx, [esi +BMP.iSize]
|
||||||
|
cmp ecx, byte 12 ;OS/2 format.
|
||||||
|
jne .MS
|
||||||
|
cmp eax, byte BMPOS2_size
|
||||||
|
jbe .ret ;coreヘッダなし
|
||||||
|
lea ebx, [esi+ecx+14] ;palette
|
||||||
|
movzx eax, word[esi+BMPOS2.iWidth] ;width
|
||||||
|
movzx ecx, word[esi+BMPOS2.iHeight] ;height
|
||||||
|
movzx ebp, word[esi+BMPOS2.iBitCount] ;bpp
|
||||||
|
mov dl, 3 ;paletteSize
|
||||||
|
jmp short .endif
|
||||||
|
.MS: cmp eax, byte BMP_size
|
||||||
|
jbe .ret ;infoヘッダなし
|
||||||
|
lea ebx, [esi+ecx+14]
|
||||||
|
sub ecx,byte 40
|
||||||
|
jne .ret ;unknownFormat
|
||||||
|
cmp ecx, [esi+BMP.iCompression]
|
||||||
|
jne .ret ;Compressed.
|
||||||
|
mov eax, [esi+BMP.iWidth] ;width
|
||||||
|
mov ecx, [esi+BMP.iHeight] ;height
|
||||||
|
movzx ebp, word[esi +BMP.iBitCount] ;bpp
|
||||||
|
mov dl, 4 ;paletteSize
|
||||||
|
.endif:
|
||||||
|
add esi, [esi +BMP.fOffBits]
|
||||||
|
|
||||||
|
;sizeが小さい場合heightを削ってで<E381A6>
|
||||||
|
;読めると答えるべきだろう。今はエラー
|
||||||
|
push edx
|
||||||
|
push eax
|
||||||
|
mul ebp ;eax=width*bpp
|
||||||
|
add eax, byte 7
|
||||||
|
shr eax, 3 ;lineSizeWithoutPudding
|
||||||
|
mov edx, eax
|
||||||
|
add eax, byte 3 ;size<1GBを仮定してedxを無<E38292>
|
||||||
|
and al, -4 ;lineSizeWithPudding
|
||||||
|
sub edx, eax ;-puddingSize
|
||||||
|
push edx
|
||||||
|
mul ecx
|
||||||
|
pop edx
|
||||||
|
add esi, eax
|
||||||
|
add esi, edx ;最終行の最後にはpuddingがないと見るべき
|
||||||
|
cmp esi, [esp+8] ;endOfModule
|
||||||
|
pop eax
|
||||||
|
ja .ret2
|
||||||
|
sub esi, edx ;esi=endOfImage
|
||||||
|
inc edi ;succeeded!
|
||||||
|
.ret2: pop edx
|
||||||
|
.ret: add esp, byte 4
|
||||||
|
ret
|
||||||
|
|
||||||
|
;***************************************************************
|
||||||
|
; 小ささ優先で作っているが, 速さ優先で作った昔のよりいいかも。
|
||||||
|
; 品質最低の高速モードのみ作ってい<E381A6>
|
||||||
|
|
||||||
|
[absolute 0]
|
||||||
|
decode:
|
||||||
|
.regs: resd 4
|
||||||
|
.reteip: resd 1
|
||||||
|
.env: resd 1
|
||||||
|
.size: resd 1
|
||||||
|
.module: resd 1
|
||||||
|
.outputType: resd 1
|
||||||
|
.dest: resd 1
|
||||||
|
.skip: resd 1
|
||||||
|
[section .text]
|
||||||
|
[global _decode0_BMP]
|
||||||
|
_decode0_BMP:
|
||||||
|
push ebx
|
||||||
|
push ebp
|
||||||
|
push esi
|
||||||
|
push edi
|
||||||
|
mov esi, [esp+decode.module]
|
||||||
|
mov eax, [esp+decode.size]
|
||||||
|
call bmpHeader
|
||||||
|
;ret:eax=width, ecx=hegiht, edx=paletteSize, ebx=palette
|
||||||
|
; ebp=bpp, esi=endOfImage, edi=successFlag
|
||||||
|
test edi,edi
|
||||||
|
jz .error
|
||||||
|
mov edi, [esp+decode.dest]
|
||||||
|
push dword[esp+decode.outputType]
|
||||||
|
push dword[esp+4+decode.skip]
|
||||||
|
push ecx ;height
|
||||||
|
push eax
|
||||||
|
push edx
|
||||||
|
mul ebp
|
||||||
|
add eax, byte 31
|
||||||
|
shr eax, 3
|
||||||
|
and al, -4
|
||||||
|
push eax
|
||||||
|
mov edx, ebp
|
||||||
|
mov ebp, esp
|
||||||
|
call bmp2beta ;ecx!=0 for error
|
||||||
|
add esp, byte bb.size
|
||||||
|
mov eax, ecx
|
||||||
|
test ecx, ecx
|
||||||
|
jz .ret
|
||||||
|
.error: push byte 1
|
||||||
|
pop eax
|
||||||
|
.ret: pop edi
|
||||||
|
pop esi
|
||||||
|
pop ebp
|
||||||
|
pop ebx
|
||||||
|
ret
|
||||||
|
|
||||||
|
[absolute -4*2]
|
||||||
|
bb:
|
||||||
|
.col0: resd 1 ;bpp1で使う
|
||||||
|
.reteip: resd 1
|
||||||
|
.sw: resd 1 ;byte
|
||||||
|
.paletteSize: resd 1 ;byte
|
||||||
|
.w: resd 1 ;pixel
|
||||||
|
.h: resd 1
|
||||||
|
.s: resd 1
|
||||||
|
.t: resd 1
|
||||||
|
.size: equ $-$$
|
||||||
|
[section .text]
|
||||||
|
;eax=?, ecx=height, edx=bpp, ebx=palette
|
||||||
|
;ebp=bb, esi=endOfImage, edi=dest
|
||||||
|
bmp2beta:
|
||||||
|
mov al, [ebp+bb.t]
|
||||||
|
and al, 0x7f
|
||||||
|
cmp al, 2
|
||||||
|
je near buf16
|
||||||
|
cmp al, 4
|
||||||
|
je buf32
|
||||||
|
mov ecx, esp ;!=0
|
||||||
|
ret
|
||||||
|
;===============================================================
|
||||||
|
; Buffer mode 4
|
||||||
|
;===============================================================
|
||||||
|
buf32:
|
||||||
|
dec edx
|
||||||
|
je near .bpp1
|
||||||
|
sub edx, byte 4-1
|
||||||
|
je .bpp4
|
||||||
|
sub edx, byte 8-4
|
||||||
|
je .bpp8
|
||||||
|
sub edx, byte 24-8
|
||||||
|
je .bpp24
|
||||||
|
mov ecx, esp ;!=0
|
||||||
|
ret
|
||||||
|
;---------------------------------------------------
|
||||||
|
; 24bpp BMP to 4byte bufer
|
||||||
|
;---------------------------------------------------
|
||||||
|
.bpp24:
|
||||||
|
;ecx=height, edx=0, ebx=palette
|
||||||
|
;esi=endOfImage, edi=destinationBuffer
|
||||||
|
;bb.w=width(pixel), bb.s=skipByte, bb.h=height
|
||||||
|
;bb.t=outputType, bb.sw=sourceWidthByte
|
||||||
|
|
||||||
|
.do24.1:
|
||||||
|
sub esi, [ebp+bb.sw] ;esi=startOfLine
|
||||||
|
push ecx
|
||||||
|
push esi
|
||||||
|
mov ecx, [ebp+bb.w]
|
||||||
|
.do24.2:
|
||||||
|
mov al, [esi]
|
||||||
|
mov [edi+3], dl
|
||||||
|
mov [edi], al
|
||||||
|
mov al, [esi+1]
|
||||||
|
mov [edi+1], al
|
||||||
|
mov al, [esi+2]
|
||||||
|
mov [edi+2], al
|
||||||
|
add esi, byte 3
|
||||||
|
add edi, byte 4
|
||||||
|
dec ecx
|
||||||
|
jnz .do24.2
|
||||||
|
pop esi
|
||||||
|
pop ecx
|
||||||
|
add edi, [ebp+bb.s]
|
||||||
|
dec ecx
|
||||||
|
jnz .do24.1
|
||||||
|
ret
|
||||||
|
|
||||||
|
;---------------------------------------------------
|
||||||
|
; 8bpp BMP to 4byte buffer
|
||||||
|
;---------------------------------------------------
|
||||||
|
.bpp8:
|
||||||
|
;ecx=height, edx=0, ebx=palette
|
||||||
|
;esi=endOfImage, edi=destinationBuffer
|
||||||
|
|
||||||
|
;pallete変換
|
||||||
|
mov dl, 255
|
||||||
|
mov eax, [ebp+bb.paletteSize]
|
||||||
|
sub ebx, eax
|
||||||
|
shl eax, 8
|
||||||
|
add ebx, eax ;ebx += paletteSize*255
|
||||||
|
.do8.1:
|
||||||
|
mov eax, [ebx]
|
||||||
|
sub ebx, [ebp+bb.paletteSize]
|
||||||
|
and eax, 0x00ffffff
|
||||||
|
dec edx
|
||||||
|
push eax
|
||||||
|
jns .do8.1
|
||||||
|
|
||||||
|
.do8.2:
|
||||||
|
sub esi, [ebp+bb.sw] ;esi=firstLineStart
|
||||||
|
push ecx
|
||||||
|
push esi
|
||||||
|
mov ecx, [ebp+bb.w]
|
||||||
|
.do8.3:
|
||||||
|
xor eax, eax
|
||||||
|
add edi, byte 4
|
||||||
|
mov al, [esi]
|
||||||
|
inc esi
|
||||||
|
;AGI stole
|
||||||
|
mov eax, [esp+eax*4+8]
|
||||||
|
dec ecx
|
||||||
|
mov [edi-4], eax
|
||||||
|
jnz .do8.3
|
||||||
|
pop esi
|
||||||
|
pop ecx
|
||||||
|
add edi, [ebp+bb.s]
|
||||||
|
dec ecx
|
||||||
|
jnz .do8.2
|
||||||
|
add esp, 256*4 ;palette
|
||||||
|
ret
|
||||||
|
|
||||||
|
;---------------------------------------------------
|
||||||
|
; 4bpp BMP to 4byte buffer
|
||||||
|
;---------------------------------------------------
|
||||||
|
.bpp4:
|
||||||
|
;ecx=height, edx=0, ebx=palette
|
||||||
|
;esi=endOfImage, edi=destinationBuffer
|
||||||
|
|
||||||
|
;pallete変換
|
||||||
|
mov dl, 16
|
||||||
|
mov eax, [ebp+bb.paletteSize]
|
||||||
|
sub ebx, eax
|
||||||
|
shl eax, 4
|
||||||
|
add ebx, eax ;ebx+=eax*15
|
||||||
|
.do4.1
|
||||||
|
mov eax, [ebx]
|
||||||
|
sub ebx, [ebp+bb.paletteSize]
|
||||||
|
and eax, 0x00ffffff
|
||||||
|
dec edx
|
||||||
|
push eax
|
||||||
|
jnz .do4.1
|
||||||
|
|
||||||
|
.do4.2:
|
||||||
|
sub esi, [ebp+bb.sw] ;esi=firstLineStart
|
||||||
|
push ecx
|
||||||
|
push esi
|
||||||
|
mov ecx, [ebp+bb.w]
|
||||||
|
.do4.3:
|
||||||
|
xor edx, edx
|
||||||
|
mov al, [esi]
|
||||||
|
mov dl, al
|
||||||
|
inc esi
|
||||||
|
shr dl, 4
|
||||||
|
and eax, byte 15
|
||||||
|
add edi, byte 4
|
||||||
|
dec ecx
|
||||||
|
mov edx, [esp+edx*4+8]
|
||||||
|
mov eax, [esp+eax*4+8]
|
||||||
|
mov [edi-4], edx
|
||||||
|
jz .wend
|
||||||
|
mov [edi], eax
|
||||||
|
add edi, byte 4
|
||||||
|
dec ecx
|
||||||
|
jnz .do4.3
|
||||||
|
.wend: pop esi
|
||||||
|
pop ecx
|
||||||
|
add edi, [ebp+bb.s]
|
||||||
|
dec ecx
|
||||||
|
jnz .do4.2
|
||||||
|
add esp, 16*4 ;palette
|
||||||
|
ret
|
||||||
|
|
||||||
|
;---------------------------------------------------
|
||||||
|
; 1bpp BMP to 4byte buffer
|
||||||
|
;---------------------------------------------------
|
||||||
|
.bpp1:
|
||||||
|
;ecx=height, edx=0, ebx=palette
|
||||||
|
;esi=endOfImage, edi=destinationBuffer
|
||||||
|
|
||||||
|
;pallete変換
|
||||||
|
mov eax, [ebx]
|
||||||
|
add ebx, [ebp+bb.paletteSize]
|
||||||
|
and eax, 0x00ffffff
|
||||||
|
mov ebx, [ebx]
|
||||||
|
and ebx, 0x00ffffff
|
||||||
|
xor ebx, eax
|
||||||
|
;push ebx
|
||||||
|
push eax
|
||||||
|
|
||||||
|
.do1.1:
|
||||||
|
sub esi, [ebp+bb.sw] ;esi=firstLineStart
|
||||||
|
push ecx
|
||||||
|
push esi
|
||||||
|
mov ecx, [ebp+bb.w]
|
||||||
|
.do1.2:
|
||||||
|
mov dl, [esi]
|
||||||
|
inc esi
|
||||||
|
push esi
|
||||||
|
mov esi, 8
|
||||||
|
.do1.3:
|
||||||
|
add edi, byte 4
|
||||||
|
add dl, dl
|
||||||
|
sbb eax, eax
|
||||||
|
and eax, ebx
|
||||||
|
xor eax, [ebp+bb.col0]
|
||||||
|
dec ecx
|
||||||
|
mov [edi-4], eax
|
||||||
|
jz .wend1bpp
|
||||||
|
dec esi
|
||||||
|
jnz .do1.3
|
||||||
|
pop esi
|
||||||
|
jmp short .do1.2
|
||||||
|
.wend1bpp:pop ecx
|
||||||
|
pop esi
|
||||||
|
pop ecx
|
||||||
|
add edi, [ebp+bb.s]
|
||||||
|
dec ecx
|
||||||
|
jnz .do1.1
|
||||||
|
pop eax
|
||||||
|
ret
|
||||||
|
|
||||||
|
;===============================================
|
||||||
|
; Buffer mode 2byte
|
||||||
|
;===============================================
|
||||||
|
buf16:
|
||||||
|
dec edx
|
||||||
|
je near .bpp1
|
||||||
|
sub edx, byte 4-1
|
||||||
|
je near .bpp4
|
||||||
|
sub edx, byte 8-4
|
||||||
|
je .bpp8
|
||||||
|
sub edx, byte 24-8
|
||||||
|
je .bpp24
|
||||||
|
mov ecx, esp
|
||||||
|
ret
|
||||||
|
;---------------------------------------------------
|
||||||
|
; 24bpp BMP to 2byte bufer
|
||||||
|
;---------------------------------------------------
|
||||||
|
.bpp24:
|
||||||
|
;ecx=height, edx=0, ebx=palette
|
||||||
|
;esi=endOfImage, edi=destinationBuffer
|
||||||
|
|
||||||
|
.do24.1:
|
||||||
|
sub esi, [ebp+bb.sw] ;esi=startOfLine
|
||||||
|
push ecx
|
||||||
|
push esi
|
||||||
|
mov ecx, [ebp+bb.w]
|
||||||
|
.do24.2:
|
||||||
|
mov al, [esi+2]
|
||||||
|
shl eax, 16
|
||||||
|
mov ax, [esi]
|
||||||
|
add esi, byte 3
|
||||||
|
;減色処理 eax=24bitColor, edx=work, ecx=counter, ebx=work
|
||||||
|
;川合さんの趣味で没ったルーチンを持ってくるもよし(ぉ
|
||||||
|
;誤差拡散ルーチンを持ってくるもよし
|
||||||
|
shr ah, 2 ;???????? RRRRRrrr 00GGGGGG BBBBBbbb
|
||||||
|
inc edi
|
||||||
|
shr eax, 3 ;000????? ???RRRRR rrr00GGG GGGBBBBB
|
||||||
|
shl ax, 5 ;000????? ???RRRRR GGGGGGBB BBB00000
|
||||||
|
inc edi
|
||||||
|
shr eax, 5 ;00000000 ???????? RRRRRGGG GGGBBBBB
|
||||||
|
dec ecx
|
||||||
|
mov [edi-2], ax
|
||||||
|
jnz .do24.2
|
||||||
|
pop esi
|
||||||
|
pop ecx
|
||||||
|
add edi, [ebp+bb.s]
|
||||||
|
dec ecx
|
||||||
|
jnz .do24.1
|
||||||
|
ret
|
||||||
|
|
||||||
|
;---------------------------------------------------
|
||||||
|
; 8bpp BMP to 2byte buffer
|
||||||
|
;---------------------------------------------------
|
||||||
|
.bpp8:
|
||||||
|
;ecx=height, edx=0, ebx=palette
|
||||||
|
;esi=endOfImage, edi=destinationBuffer
|
||||||
|
|
||||||
|
;pallete変換
|
||||||
|
mov dl, 255
|
||||||
|
mov eax, [ebp+bb.paletteSize]
|
||||||
|
sub ebx, eax
|
||||||
|
shl eax, 8
|
||||||
|
add ebx, eax ;ebx += paletteSize*255
|
||||||
|
.do8.1:
|
||||||
|
mov eax, [ebx]
|
||||||
|
sub ebx, [ebp+bb.paletteSize]
|
||||||
|
call .paletteConv
|
||||||
|
dec edx
|
||||||
|
push eax
|
||||||
|
jns .do8.1
|
||||||
|
|
||||||
|
.do8.2:
|
||||||
|
sub esi, [ebp+bb.sw] ;esi=firstLineStart
|
||||||
|
push ecx
|
||||||
|
push esi
|
||||||
|
mov ecx, [ebp+bb.w]
|
||||||
|
.do8.3:
|
||||||
|
xor eax, eax
|
||||||
|
add edi, byte 2
|
||||||
|
mov al, [esi]
|
||||||
|
inc esi
|
||||||
|
;AGI stole
|
||||||
|
mov eax, [esp+eax*4+8]
|
||||||
|
dec ecx
|
||||||
|
mov [edi-2], ax
|
||||||
|
jnz .do8.3
|
||||||
|
pop esi
|
||||||
|
pop ecx
|
||||||
|
add edi, [ebp+bb.s]
|
||||||
|
dec ecx
|
||||||
|
jnz .do8.2
|
||||||
|
add esp, 256*4 ;palette
|
||||||
|
ret
|
||||||
|
|
||||||
|
;---------------------------------------------------
|
||||||
|
; 4bpp BMP to 2byte buffer
|
||||||
|
;---------------------------------------------------
|
||||||
|
.bpp4:
|
||||||
|
;ecx=height, edx=0, ebx=palette
|
||||||
|
;esi=endOfImage, edi=destinationBuffer
|
||||||
|
|
||||||
|
;pallete変換
|
||||||
|
mov dl, 16
|
||||||
|
mov eax, [ebp+bb.paletteSize]
|
||||||
|
sub ebx, eax
|
||||||
|
shl eax, 4
|
||||||
|
add ebx, eax ;ebx+=eax*15
|
||||||
|
.do4.1:
|
||||||
|
mov eax, [ebx]
|
||||||
|
sub ebx, [ebp+bb.paletteSize]
|
||||||
|
call .paletteConv
|
||||||
|
dec edx
|
||||||
|
push eax
|
||||||
|
jnz .do4.1
|
||||||
|
|
||||||
|
.do4.2:
|
||||||
|
sub esi, [ebp+bb.sw] ;esi=firstLineStart
|
||||||
|
push ecx
|
||||||
|
push esi
|
||||||
|
mov ecx, [ebp+bb.w]
|
||||||
|
.do4.3:
|
||||||
|
xor edx, edx
|
||||||
|
mov al, [esi]
|
||||||
|
mov dl, al
|
||||||
|
inc esi
|
||||||
|
shr dl, 4
|
||||||
|
and eax, byte 15
|
||||||
|
add edi, byte 2
|
||||||
|
dec ecx
|
||||||
|
mov edx, [esp+edx*4+8]
|
||||||
|
mov eax, [esp+eax*4+8]
|
||||||
|
mov [edi-2], dx
|
||||||
|
jz .wend
|
||||||
|
mov [edi], ax
|
||||||
|
add edi, byte 2
|
||||||
|
dec ecx
|
||||||
|
jnz .do4.3
|
||||||
|
.wend: pop esi
|
||||||
|
pop ecx
|
||||||
|
add edi, [ebp+bb.s]
|
||||||
|
dec ecx
|
||||||
|
jnz .do4.2
|
||||||
|
add esp, 16*4 ;palette
|
||||||
|
ret
|
||||||
|
|
||||||
|
;---------------------------------------------------
|
||||||
|
; 1bpp BMP to 2byte buffer
|
||||||
|
;---------------------------------------------------
|
||||||
|
.bpp1:
|
||||||
|
;ecx=height, edx=0, ebx=palette
|
||||||
|
;esi=endOfImage, edi=destinationBuffer
|
||||||
|
|
||||||
|
;pallete変換
|
||||||
|
mov eax, [ebx]
|
||||||
|
add ebx, [ebp+bb.paletteSize]
|
||||||
|
call .paletteConv
|
||||||
|
push eax
|
||||||
|
mov eax, [ebx]
|
||||||
|
call .paletteConv
|
||||||
|
pop ebx
|
||||||
|
xchg eax, ebx
|
||||||
|
xor ebx, eax
|
||||||
|
push eax
|
||||||
|
|
||||||
|
.do1.1:
|
||||||
|
sub esi, [ebp+bb.sw] ;esi=firstLineStart
|
||||||
|
push ecx
|
||||||
|
push esi
|
||||||
|
mov ecx, [ebp+bb.w]
|
||||||
|
.do1.2:
|
||||||
|
mov dl, [esi]
|
||||||
|
inc esi
|
||||||
|
push esi
|
||||||
|
mov esi, 8
|
||||||
|
.do1.3:
|
||||||
|
add dl, dl
|
||||||
|
inc edi
|
||||||
|
sbb eax, eax
|
||||||
|
inc edi
|
||||||
|
and eax, ebx
|
||||||
|
xor eax, [ebp+bb.col0]
|
||||||
|
dec ecx
|
||||||
|
mov [edi-2], ax
|
||||||
|
jz .wend1bpp
|
||||||
|
dec esi
|
||||||
|
jnz .do1.3
|
||||||
|
pop esi
|
||||||
|
jmp short .do1.2
|
||||||
|
.wend1bpp:
|
||||||
|
pop ecx
|
||||||
|
pop esi
|
||||||
|
pop ecx
|
||||||
|
add edi, [ebp+bb.s]
|
||||||
|
dec ecx
|
||||||
|
jnz .do1.1
|
||||||
|
pop eax
|
||||||
|
ret
|
||||||
|
|
||||||
|
.paletteConv:
|
||||||
|
shr ah, 2
|
||||||
|
shr eax, 3
|
||||||
|
shl ax, 5
|
||||||
|
shr eax, 5
|
||||||
|
ret
|
||||||
BIN
30_day/gview/bmp.obj
Normal file
BIN
30_day/gview/bmp.obj
Normal file
Binary file not shown.
121
30_day/gview/gview.c
Normal file
121
30_day/gview/gview.c
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
#include "apilib.h"
|
||||||
|
|
||||||
|
struct DLL_STRPICENV { /* 64KB */
|
||||||
|
int work[64 * 1024 / 4];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RGB {
|
||||||
|
unsigned char b, g, r, t;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* bmp.nasm */
|
||||||
|
int info_BMP(struct DLL_STRPICENV *env, int *info, int size, char *fp);
|
||||||
|
int decode0_BMP(struct DLL_STRPICENV *env, int size, char *fp, int b_type, char *buf, int skip);
|
||||||
|
|
||||||
|
/* jpeg.c */
|
||||||
|
int info_JPEG(struct DLL_STRPICENV *env, int *info, int size, char *fp);
|
||||||
|
int decode0_JPEG(struct DLL_STRPICENV *env, int size, char *fp, int b_type, char *buf, int skip);
|
||||||
|
|
||||||
|
unsigned char rgb2pal(int r, int g, int b, int x, int y);
|
||||||
|
void error(char *s);
|
||||||
|
|
||||||
|
void HariMain(void)
|
||||||
|
{
|
||||||
|
struct DLL_STRPICENV env;
|
||||||
|
char filebuf[512 * 1024], winbuf[1040 * 805];
|
||||||
|
char s[32], *p;
|
||||||
|
int win, i, j, fsize, xsize, info[8];
|
||||||
|
struct RGB picbuf[1024 * 768], *q;
|
||||||
|
|
||||||
|
/*命令行解析*/
|
||||||
|
api_cmdline(s, 30);
|
||||||
|
for (p = s; *p > ' '; p++) { } /*一直读到空格为止*/
|
||||||
|
for (; *p == ' '; p++) { } /*跳过空格*/
|
||||||
|
|
||||||
|
/*文件载入*/
|
||||||
|
i = api_fopen(p); if (i == 0) { error("file not found.\n"); }
|
||||||
|
fsize = api_fsize(i, 0);
|
||||||
|
if (fsize > 512 * 1024) {
|
||||||
|
error("file too large.\n");
|
||||||
|
}
|
||||||
|
api_fread(filebuf, fsize, i);
|
||||||
|
api_fclose(i);
|
||||||
|
|
||||||
|
/*检查文件类型*/
|
||||||
|
if (info_BMP(&env, info, fsize, filebuf) == 0) {
|
||||||
|
/*不是BMP */
|
||||||
|
if (info_JPEG(&env, info, fsize, filebuf) == 0) {
|
||||||
|
/*也不是JPEG */
|
||||||
|
api_putstr0("file type unknown.\n");
|
||||||
|
api_end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*上面其中一个info函数调用成功的话,info中包含以下信息 */
|
||||||
|
/*info[0]:文件类型(1:BMP、2:JPEG)*/
|
||||||
|
/*info[1]:颜色数信息*/
|
||||||
|
/*info[2]:xsize */
|
||||||
|
/* info[3] : ysize */
|
||||||
|
|
||||||
|
if (info[2] > 1024 || info[3] > 768) {
|
||||||
|
error("picture too large.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*窗口准备*/
|
||||||
|
xsize = info[2] + 16;
|
||||||
|
if (xsize < 136) {
|
||||||
|
xsize = 136;
|
||||||
|
}
|
||||||
|
win = api_openwin(winbuf, xsize, info[3] + 37, -1, "gview");
|
||||||
|
|
||||||
|
/*将文件内容转换为图像数据*/
|
||||||
|
if (info[0] == 1) {
|
||||||
|
i = decode0_BMP (&env, fsize, filebuf, 4, (char *) picbuf, 0);
|
||||||
|
} else {
|
||||||
|
i = decode0_JPEG(&env, fsize, filebuf, 4, (char *) picbuf, 0);
|
||||||
|
}
|
||||||
|
/*b_type = 4表示struct RGB格式*/
|
||||||
|
/*skip设为0即可*/
|
||||||
|
if (i != 0) {
|
||||||
|
error("decode error.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*显示*/
|
||||||
|
for (i = 0; i < info[3]; i++) {
|
||||||
|
p = winbuf + (i + 29) * xsize + (xsize - info[2]) / 2;
|
||||||
|
q = picbuf + i * info[2];
|
||||||
|
for (j = 0; j < info[2]; j++) {
|
||||||
|
p[j] = rgb2pal(q[j].r, q[j].g, q[j].b, j, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
api_refreshwin(win, (xsize - info[2]) / 2, 29, (xsize - info[2]) / 2 + info[2], 29 + info[3]);
|
||||||
|
|
||||||
|
/*等待结束*/
|
||||||
|
for (;;) {
|
||||||
|
i = api_getkey(1);
|
||||||
|
if (i == 'Q' || i == 'q') {
|
||||||
|
api_end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char rgb2pal(int r, int g, int b, int x, int y)
|
||||||
|
{
|
||||||
|
static int table[4] = { 3, 1, 0, 2 };
|
||||||
|
int i;
|
||||||
|
x &= 1; /*判断是偶数还是奇数*/
|
||||||
|
y &= 1;
|
||||||
|
i = table[x + y * 2]; /*用于生成中间色的常量*/
|
||||||
|
r = (r * 21) / 256; /*结果为0~20*/
|
||||||
|
g = (g * 21) / 256;
|
||||||
|
b = (b * 21) / 256;
|
||||||
|
r = (r + i) / 4; /*结果为0~5*/
|
||||||
|
g = (g + i) / 4;
|
||||||
|
b = (b + i) / 4;
|
||||||
|
return 16 + r + g * 6 + b * 36;
|
||||||
|
}
|
||||||
|
|
||||||
|
void error(char *s)
|
||||||
|
{
|
||||||
|
api_putstr0(s);
|
||||||
|
api_end();
|
||||||
|
}
|
||||||
733
30_day/gview/jpeg.c
Normal file
733
30_day/gview/jpeg.c
Normal file
@@ -0,0 +1,733 @@
|
|||||||
|
/*
|
||||||
|
* JPEG decoding engine for DCT-baseline
|
||||||
|
*
|
||||||
|
* copyrights 2003 by nikq | nikq::club.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
typedef unsigned char UCHAR;
|
||||||
|
|
||||||
|
struct DLL_STRPICENV { int work[16384]; };
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int elem;
|
||||||
|
unsigned short code[256];
|
||||||
|
unsigned char size[256];
|
||||||
|
unsigned char value[256];
|
||||||
|
}HUFF;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
// SOF
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
// MCU
|
||||||
|
int mcu_width;
|
||||||
|
int mcu_height;
|
||||||
|
|
||||||
|
int max_h,max_v;
|
||||||
|
int compo_count;
|
||||||
|
int compo_id[3];
|
||||||
|
int compo_sample[3];
|
||||||
|
int compo_h[3];
|
||||||
|
int compo_v[3];
|
||||||
|
int compo_qt[3];
|
||||||
|
|
||||||
|
// SOS
|
||||||
|
int scan_count;
|
||||||
|
int scan_id[3];
|
||||||
|
int scan_ac[3];
|
||||||
|
int scan_dc[3];
|
||||||
|
int scan_h[3];
|
||||||
|
int scan_v[3];
|
||||||
|
int scan_qt[3];
|
||||||
|
|
||||||
|
// DRI
|
||||||
|
int interval;
|
||||||
|
|
||||||
|
int mcu_buf[32*32*4];
|
||||||
|
int *mcu_yuv[4];
|
||||||
|
int mcu_preDC[3];
|
||||||
|
|
||||||
|
// DQT
|
||||||
|
int dqt[3][64];
|
||||||
|
int n_dqt;
|
||||||
|
|
||||||
|
// DHT
|
||||||
|
HUFF huff[2][3];
|
||||||
|
|
||||||
|
|
||||||
|
// FILE i/o
|
||||||
|
unsigned char *fp, *fp1;
|
||||||
|
unsigned long bit_buff;
|
||||||
|
int bit_remain;
|
||||||
|
int width_buf;
|
||||||
|
|
||||||
|
int base_img[64][64];
|
||||||
|
|
||||||
|
/* for dll
|
||||||
|
|
||||||
|
JPEG *jpeg = (JPEG *)malloc(sizeof(JPEG) + 256);
|
||||||
|
*/
|
||||||
|
int dummy[64];
|
||||||
|
|
||||||
|
}JPEG;
|
||||||
|
|
||||||
|
/* for 16bit */
|
||||||
|
#ifndef PIXEL16
|
||||||
|
#define PIXEL16(r, g, b) ((r) << 11 | (g) << 5 | (b))
|
||||||
|
/* 0 <= r <= 31, 0 <= g <= 63, 0 <= b <= 31 */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int info_JPEG(struct DLL_STRPICENV *env, int *info, int size, UCHAR *fp);
|
||||||
|
int decode0_JPEG(struct DLL_STRPICENV *env, int size, UCHAR *fp, int b_type, UCHAR *buf, int skip);
|
||||||
|
|
||||||
|
void jpeg_idct_init(int base_img[64][64]);
|
||||||
|
int jpeg_init(JPEG *jpeg);
|
||||||
|
// int jpeg_header(JPEG *jpge);
|
||||||
|
void jpeg_decode(JPEG *jpeg, unsigned char *rgb,int b_type);
|
||||||
|
|
||||||
|
/* ----------------- start main section ----------------- */
|
||||||
|
|
||||||
|
int info_JPEG(struct DLL_STRPICENV *env,int *info, int size, UCHAR *fp0)
|
||||||
|
{
|
||||||
|
JPEG *jpeg = (JPEG *) (((int *) env) + 128);
|
||||||
|
jpeg->fp = fp0;
|
||||||
|
jpeg->fp1 = fp0 + size;
|
||||||
|
|
||||||
|
// if (512 + sizeof (JPEG) > 64 * 1024)
|
||||||
|
// return 0;
|
||||||
|
|
||||||
|
if (jpeg_init(jpeg))
|
||||||
|
return 0;
|
||||||
|
// jpeg_header(jpeg);
|
||||||
|
|
||||||
|
if (jpeg->width == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
info[0] = 0x0002;
|
||||||
|
info[1] = 0x0000;
|
||||||
|
info[2] = jpeg->width;
|
||||||
|
info[3] = jpeg->height;
|
||||||
|
|
||||||
|
/* OK */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int decode0_JPEG(struct DLL_STRPICENV *env,int size, UCHAR *fp0, int b_type, UCHAR *buf, int skip)
|
||||||
|
{
|
||||||
|
JPEG *jpeg = (JPEG *) (((int *) env) + 128);
|
||||||
|
jpeg->fp = fp0;
|
||||||
|
jpeg->fp1 = fp0 + size;
|
||||||
|
|
||||||
|
jpeg_idct_init(jpeg->base_img);
|
||||||
|
jpeg_init(jpeg);
|
||||||
|
// jpeg_header(jpeg);
|
||||||
|
|
||||||
|
// if (jpeg->width == 0)
|
||||||
|
// return 8;
|
||||||
|
/* decode*/
|
||||||
|
|
||||||
|
jpeg->width_buf = skip / (b_type & 0x7f) + jpeg->width;
|
||||||
|
jpeg_decode(jpeg, buf, b_type);
|
||||||
|
|
||||||
|
/* OK */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------- I/O ----------------------------
|
||||||
|
|
||||||
|
unsigned short get_bits(JPEG *jpeg, int bit)
|
||||||
|
{
|
||||||
|
unsigned char c, c2;
|
||||||
|
unsigned short ret;
|
||||||
|
unsigned long buff;
|
||||||
|
int remain;
|
||||||
|
|
||||||
|
buff = jpeg->bit_buff;
|
||||||
|
remain = jpeg->bit_remain;
|
||||||
|
|
||||||
|
while (remain <= 16) {
|
||||||
|
if (jpeg->fp >= jpeg->fp1) {
|
||||||
|
ret = 0;
|
||||||
|
goto fin;
|
||||||
|
}
|
||||||
|
c = *jpeg->fp++;
|
||||||
|
if (c == 0xff) {
|
||||||
|
if (jpeg->fp >= jpeg->fp1) {
|
||||||
|
ret = 0;
|
||||||
|
goto fin;
|
||||||
|
}
|
||||||
|
jpeg->fp++; /* 00 skip */
|
||||||
|
}
|
||||||
|
buff = (buff << 8) | c;
|
||||||
|
remain += 8;
|
||||||
|
}
|
||||||
|
ret = (buff >> (remain - bit)) & ((1 << bit) - 1);
|
||||||
|
remain -= bit;
|
||||||
|
|
||||||
|
jpeg->bit_remain = remain;
|
||||||
|
jpeg->bit_buff = buff;
|
||||||
|
fin:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------ JPEG -----------------
|
||||||
|
|
||||||
|
// start of frame
|
||||||
|
int jpeg_sof(JPEG *jpeg)
|
||||||
|
{
|
||||||
|
unsigned char c;
|
||||||
|
int i, h, v, n;
|
||||||
|
|
||||||
|
if (jpeg->fp + 8 > jpeg->fp1)
|
||||||
|
goto err;
|
||||||
|
/* fp[2] ‚Í bpp */
|
||||||
|
jpeg->height = jpeg->fp[3] << 8 | jpeg->fp[4];
|
||||||
|
jpeg->width = jpeg->fp[5] << 8 | jpeg->fp[6];
|
||||||
|
n = jpeg->compo_count = jpeg->fp[7]; // Num of compo, nf
|
||||||
|
jpeg->fp += 8;
|
||||||
|
if (jpeg->fp + n * 3 > jpeg->fp1)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
jpeg->compo_id[i] = jpeg->fp[0];
|
||||||
|
|
||||||
|
jpeg->compo_sample[i] = c = jpeg->fp[1];
|
||||||
|
h = jpeg->compo_h[i] = (c >> 4) & 0x0f;
|
||||||
|
v = jpeg->compo_v[i] = c & 0x0f;
|
||||||
|
|
||||||
|
if (jpeg->max_h < h)
|
||||||
|
jpeg->max_h = h;
|
||||||
|
if (jpeg->max_v < v)
|
||||||
|
jpeg->max_v = v;
|
||||||
|
|
||||||
|
jpeg->compo_qt[i] = jpeg->fp[2];
|
||||||
|
jpeg->fp += 3;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
err:
|
||||||
|
jpeg->fp = jpeg->fp1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// define quantize table
|
||||||
|
int jpeg_dqt(JPEG *jpeg)
|
||||||
|
{
|
||||||
|
unsigned char c;
|
||||||
|
int i, j, v, size;
|
||||||
|
|
||||||
|
if (jpeg->fp + 2 > jpeg->fp1)
|
||||||
|
goto err;
|
||||||
|
size = (jpeg->fp[0] << 8 | jpeg->fp[1]) - 2;
|
||||||
|
jpeg->fp += 2;
|
||||||
|
if (jpeg->fp + size > jpeg->fp1)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
while (size > 0) {
|
||||||
|
c = *jpeg->fp++;
|
||||||
|
size--;
|
||||||
|
j = c & 7;
|
||||||
|
if (j > jpeg->n_dqt)
|
||||||
|
jpeg->n_dqt = j;
|
||||||
|
|
||||||
|
if (c & 0xf8) {
|
||||||
|
// 16 bit DQT
|
||||||
|
for (i = 0; i < 64; i++) {
|
||||||
|
jpeg->dqt[j][i] = jpeg->fp[0];
|
||||||
|
jpeg->fp += 2;
|
||||||
|
}
|
||||||
|
size += -64 * 2;
|
||||||
|
} else {
|
||||||
|
// 8 bit DQT
|
||||||
|
for (i = 0; i < 64; i++)
|
||||||
|
jpeg->dqt[j][i] = *jpeg->fp++;
|
||||||
|
size -= 64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
err:
|
||||||
|
jpeg->fp = jpeg->fp1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// define huffman table
|
||||||
|
int jpeg_dht(JPEG *jpeg)
|
||||||
|
{
|
||||||
|
unsigned tc, th;
|
||||||
|
unsigned code = 0;
|
||||||
|
unsigned char val;
|
||||||
|
int i, j, k, num, Li[17];
|
||||||
|
int len, max_val;
|
||||||
|
HUFF *table;
|
||||||
|
|
||||||
|
if (jpeg->fp + 2 > jpeg->fp1)
|
||||||
|
goto err;
|
||||||
|
len = (jpeg->fp[0] << 8 | jpeg->fp[1]) - 2;
|
||||||
|
jpeg->fp += 2;
|
||||||
|
|
||||||
|
while (len > 0) {
|
||||||
|
if (jpeg->fp + 17 > jpeg->fp1)
|
||||||
|
goto err;
|
||||||
|
val = jpeg->fp[0];
|
||||||
|
|
||||||
|
tc = (val >> 4) & 0x0f;
|
||||||
|
th = val & 0x0f;
|
||||||
|
table = &(jpeg->huff[tc][th]);
|
||||||
|
|
||||||
|
num = 0;
|
||||||
|
k = 0;
|
||||||
|
for (i = 1; i <= 16; i++) {
|
||||||
|
Li[i] = jpeg->fp[i];
|
||||||
|
num += Li[i];
|
||||||
|
for (j = 0; j < Li[i]; j++)
|
||||||
|
table->size[k++] = i;
|
||||||
|
}
|
||||||
|
table->elem = num;
|
||||||
|
jpeg->fp += 17;
|
||||||
|
|
||||||
|
k=0;
|
||||||
|
code=0;
|
||||||
|
i = table->size[0];
|
||||||
|
while (k < num) {
|
||||||
|
while (table->size[k] == i)
|
||||||
|
table->code[k++] = code++;
|
||||||
|
if (k >= num)
|
||||||
|
break;
|
||||||
|
do {
|
||||||
|
code <<= 1;
|
||||||
|
i++;
|
||||||
|
} while (table->size[k] != i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jpeg->fp + num > jpeg->fp1)
|
||||||
|
goto err;
|
||||||
|
for (k = 0; k < num; k++)
|
||||||
|
table->value[k] = jpeg->fp[k];
|
||||||
|
jpeg->fp += num;
|
||||||
|
|
||||||
|
len -= 18 + num;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
err:
|
||||||
|
jpeg->fp = jpeg->fp1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int jpeg_init(JPEG *jpeg)
|
||||||
|
{
|
||||||
|
unsigned char c;
|
||||||
|
int r = 0, i;
|
||||||
|
jpeg->width = 0;
|
||||||
|
jpeg->mcu_preDC[0] = 0;
|
||||||
|
jpeg->mcu_preDC[1] = 0;
|
||||||
|
jpeg->mcu_preDC[2] = 0;
|
||||||
|
jpeg->n_dqt = 0;
|
||||||
|
jpeg->max_h = 0;
|
||||||
|
jpeg->max_v = 0;
|
||||||
|
jpeg->bit_remain = 0;
|
||||||
|
jpeg->bit_buff = 0;
|
||||||
|
|
||||||
|
jpeg->interval = 0;
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//int jpeg_header(JPEG *jpeg)
|
||||||
|
//{
|
||||||
|
// unsigned char c;
|
||||||
|
// int r = 0, i;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
if (jpeg->fp + 2 > jpeg->fp1)
|
||||||
|
goto err;
|
||||||
|
if (jpeg->fp[0] != 0xff)
|
||||||
|
goto err0;
|
||||||
|
c = jpeg->fp[1];
|
||||||
|
jpeg->fp += 2;
|
||||||
|
if (c == 0xd8)
|
||||||
|
continue; /* SOI */
|
||||||
|
if (c == 0xd9)
|
||||||
|
goto err; /* EOI */
|
||||||
|
|
||||||
|
if (c == 0xc0)
|
||||||
|
jpeg_sof(jpeg);
|
||||||
|
else if (c == 0xc4)
|
||||||
|
jpeg_dht(jpeg);
|
||||||
|
else if (c == 0xdb)
|
||||||
|
jpeg_dqt(jpeg);
|
||||||
|
else if (c == 0xdd) {
|
||||||
|
if (jpeg->fp + 4 > jpeg->fp1)
|
||||||
|
goto err;
|
||||||
|
jpeg->interval = jpeg->fp[2] << 8 | jpeg->fp[3];
|
||||||
|
jpeg->fp += 4;
|
||||||
|
} else if (c == 0xda) {
|
||||||
|
if (jpeg->fp + 3 > jpeg->fp1)
|
||||||
|
goto err;
|
||||||
|
jpeg->scan_count = jpeg->fp[2];
|
||||||
|
jpeg->fp += 3;
|
||||||
|
if (jpeg->fp + jpeg->scan_count * 2 > jpeg->fp1)
|
||||||
|
goto err;
|
||||||
|
for (i = 0; i < jpeg->scan_count; i++) {
|
||||||
|
jpeg->scan_id[i] = jpeg->fp[0];
|
||||||
|
jpeg->scan_dc[i] = jpeg->fp[1] >> 4; // DC Huffman Table
|
||||||
|
jpeg->scan_ac[i] = jpeg->fp[1] & 0x0F; // AC Huffman Table
|
||||||
|
jpeg->fp += 2;
|
||||||
|
}
|
||||||
|
jpeg->fp += 3; /* 3bytes skip */
|
||||||
|
goto fin;
|
||||||
|
} else {
|
||||||
|
if (jpeg->fp + 2 > jpeg->fp1)
|
||||||
|
goto err;
|
||||||
|
jpeg->fp += jpeg->fp[0] << 8 | jpeg->fp[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err:
|
||||||
|
jpeg->fp = jpeg->fp1;
|
||||||
|
err0:
|
||||||
|
r++;
|
||||||
|
fin:
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MCU decode
|
||||||
|
|
||||||
|
void jpeg_decode_init(JPEG *jpeg)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
for (i = 0; i < jpeg->scan_count; i++) {
|
||||||
|
// i:scan
|
||||||
|
for (j = 0; j < jpeg->compo_count; j++) {
|
||||||
|
// j:frame
|
||||||
|
if (jpeg->scan_id[i] == jpeg->compo_id[j]) {
|
||||||
|
jpeg->scan_h[i] = jpeg->compo_h[j];
|
||||||
|
jpeg->scan_v[i] = jpeg->compo_v[j];
|
||||||
|
jpeg->scan_qt[i] = jpeg->compo_qt[j];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if (j >= jpeg->compo_count)
|
||||||
|
// return 1;
|
||||||
|
}
|
||||||
|
jpeg->mcu_width = jpeg->max_h * 8;
|
||||||
|
jpeg->mcu_height = jpeg->max_v * 8;
|
||||||
|
|
||||||
|
for (i = 0; i < 32 * 32 * 4; i++)
|
||||||
|
jpeg->mcu_buf[i] = 0x80;
|
||||||
|
|
||||||
|
for (i = 0; i < jpeg->scan_count; i++)
|
||||||
|
jpeg->mcu_yuv[i] = jpeg->mcu_buf + (i << 10);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int jpeg_huff_decode(JPEG *jpeg,int tc,int th)
|
||||||
|
{
|
||||||
|
HUFF *h = &(jpeg->huff[tc][th]);
|
||||||
|
int code,size,k,v;
|
||||||
|
code = 0;
|
||||||
|
size = 0;
|
||||||
|
k = 0;
|
||||||
|
while( size < 16 ){
|
||||||
|
size++;
|
||||||
|
v = get_bits(jpeg,1);
|
||||||
|
if(v < 0){
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
code = (code << 1) | v;
|
||||||
|
|
||||||
|
while(h->size[k] == size){
|
||||||
|
if(h->code[k] == code){
|
||||||
|
return h->value[k];
|
||||||
|
}
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void jpeg_idct_init(int base_img[64][64])
|
||||||
|
{
|
||||||
|
int u, v, m, n;
|
||||||
|
int tmpm[8], tmpn[8];
|
||||||
|
int cost[32];
|
||||||
|
cost[ 0] = 32768; cost[ 1] = 32138; cost[ 2] = 30274; cost[ 3] = 27246; cost[ 4] = 23170; cost[ 5] = 18205; cost[ 6] = 12540; cost[ 7] = 6393;
|
||||||
|
cost[ 8] = 0; cost[ 9] = -6393; cost[10] = -12540; cost[11] = -18205; cost[12] = -23170; cost[13] = -27246; cost[14] = -30274; cost[15] = -32138;
|
||||||
|
for (u = 0; u < 16; u++)
|
||||||
|
cost[u + 16] = - cost[u];
|
||||||
|
|
||||||
|
for (u = 0; u < 8; u++) {
|
||||||
|
{
|
||||||
|
int i=u, d=u*2;
|
||||||
|
if (d == 0)
|
||||||
|
i = 4;
|
||||||
|
for (m = 0; m < 8; m++){
|
||||||
|
tmpm[m] = cost[i];
|
||||||
|
i=(i+d)&31;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (v = 0; v < 8; v++) {
|
||||||
|
{
|
||||||
|
int i=v,d=v*2;
|
||||||
|
if (d == 0)
|
||||||
|
i=4;
|
||||||
|
for (n = 0; n < 8; n++){
|
||||||
|
tmpn[n] = cost[i];
|
||||||
|
i=(i+d)&31;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (m = 0; m < 8; m++) {
|
||||||
|
for (n = 0; n < 8; n++) {
|
||||||
|
base_img[u * 8 + v][m * 8 + n] = (tmpm[m] * tmpn[n])>>15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void jpeg_idct(int *block, int *dest, int base_img[64][64])
|
||||||
|
{
|
||||||
|
int i, j ,k;
|
||||||
|
|
||||||
|
for (i = 0; i < 64; i++)
|
||||||
|
dest[i] = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 64; i++) {
|
||||||
|
k = block[i];
|
||||||
|
if(k) {
|
||||||
|
for (j = 0; j < 64; j++) {
|
||||||
|
dest[j] += k * base_img[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 64; i++)
|
||||||
|
dest[i] >>= 17;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int jpeg_get_value(JPEG *jpeg,int size)
|
||||||
|
{
|
||||||
|
int val = 0;
|
||||||
|
if (size) {
|
||||||
|
val = get_bits(jpeg,size);
|
||||||
|
if (val < 0)
|
||||||
|
val = 0x10000 | (0 - val);
|
||||||
|
else if (!(val & (1<<(size-1))))
|
||||||
|
val -= (1 << size) - 1;
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
int jpeg_decode_huff(JPEG *jpeg,int scan,int *block, UCHAR *zigzag_table)
|
||||||
|
{
|
||||||
|
int size, len, val, run, index;
|
||||||
|
int *pQt = (int *)(jpeg->dqt[jpeg->scan_qt[scan]]);
|
||||||
|
|
||||||
|
// DC
|
||||||
|
size = jpeg_huff_decode(jpeg,0,jpeg->scan_dc[scan]);
|
||||||
|
if(size < 0)
|
||||||
|
return 0;
|
||||||
|
val = jpeg_get_value(jpeg,size);
|
||||||
|
jpeg->mcu_preDC[scan] += val;
|
||||||
|
block[0] = jpeg->mcu_preDC[scan] * pQt[0];
|
||||||
|
|
||||||
|
//AC
|
||||||
|
index = 1;
|
||||||
|
while(index<64)
|
||||||
|
{
|
||||||
|
size = jpeg_huff_decode(jpeg,1,jpeg->scan_ac[scan]);
|
||||||
|
if(size < 0)
|
||||||
|
break;
|
||||||
|
// EOB
|
||||||
|
if(size == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// RLE
|
||||||
|
run = (size>>4)&0xF;
|
||||||
|
size = size & 0x0F;
|
||||||
|
|
||||||
|
val = jpeg_get_value(jpeg,size);
|
||||||
|
if(val>=0x10000) {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ZRL
|
||||||
|
while (run-- > 0)
|
||||||
|
block[ zigzag_table[index++] ] = 0;
|
||||||
|
|
||||||
|
block[ zigzag_table[index] ] = val * pQt[index];
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
while(index<64)
|
||||||
|
block[zigzag_table[index++]]=0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void jpeg_mcu_bitblt(int *src, int *dest, int width,
|
||||||
|
int x0, int y0, int x1, int y1)
|
||||||
|
{
|
||||||
|
int w, h;
|
||||||
|
int x, y, x2, y2;
|
||||||
|
w = x1 - x0;
|
||||||
|
h = y1 - y0;
|
||||||
|
dest += y0 * width + x0;
|
||||||
|
width -= w;
|
||||||
|
|
||||||
|
for (y = 0; y < h; y++) {
|
||||||
|
y2 = (y * 8 / h) * 8;
|
||||||
|
for (x = 0; x < w; x++)
|
||||||
|
*dest++ = src[y2 + (x * 8 / w)];
|
||||||
|
dest += width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int jpeg_decode_mcu(JPEG *jpeg, UCHAR *zigzag_table)
|
||||||
|
{
|
||||||
|
int scan, val;
|
||||||
|
int unit, i, h, v;
|
||||||
|
int *p, hh, vv;
|
||||||
|
int block[64], dest[64];
|
||||||
|
|
||||||
|
// mcu_width x mcu_height
|
||||||
|
for (scan = 0; scan < jpeg->scan_count; scan++) {
|
||||||
|
hh = jpeg->scan_h[scan];
|
||||||
|
vv = jpeg->scan_v[scan];
|
||||||
|
for (v = 0; v < vv; v++) {
|
||||||
|
for (h = 0; h < hh; h++) {
|
||||||
|
// ƒuƒƒbƒN(8x8)‚̃fƒR[ƒh
|
||||||
|
val = jpeg_decode_huff(jpeg, scan, block, zigzag_table);
|
||||||
|
// if(val>=0x10000){
|
||||||
|
// printf("marker found:%02x\n",val);
|
||||||
|
// }
|
||||||
|
|
||||||
|
jpeg_idct(block, dest, jpeg->base_img);
|
||||||
|
|
||||||
|
p = jpeg->mcu_buf + (scan << 10);
|
||||||
|
|
||||||
|
jpeg_mcu_bitblt(dest, p, jpeg->mcu_width,
|
||||||
|
jpeg->mcu_width * h / hh, jpeg->mcu_height * v / vv,
|
||||||
|
jpeg->mcu_width * (h + 1) / hh, jpeg->mcu_height * (v + 1) / vv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// YCrCb=>RGB
|
||||||
|
|
||||||
|
int jpeg_decode_yuv(JPEG *jpeg, int h, int v, unsigned char *rgb, int b_type)
|
||||||
|
{
|
||||||
|
int x0, y0, x, y, x1, y1;
|
||||||
|
int *py;
|
||||||
|
int Y12, V;
|
||||||
|
int mw, mh, w;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
mw = jpeg->mcu_width;
|
||||||
|
mh = jpeg->mcu_height;
|
||||||
|
|
||||||
|
x0 = h * jpeg->max_h * 8;
|
||||||
|
y0 = v * jpeg->max_v * 8;
|
||||||
|
|
||||||
|
x1 = jpeg->width - x0;
|
||||||
|
if (x1 > mw)
|
||||||
|
x1 = mw;
|
||||||
|
y1 = jpeg->height - y0;
|
||||||
|
if (y1 > mh)
|
||||||
|
y1 = mh;
|
||||||
|
|
||||||
|
py = jpeg->mcu_buf;
|
||||||
|
rgb += (y0 * jpeg->width_buf + x0) * (b_type & 0x7f);
|
||||||
|
w = (jpeg->width_buf - x1) * (b_type & 0x7f);
|
||||||
|
|
||||||
|
for (y = 0; y < y1; y++) {
|
||||||
|
for (x = 0; x < x1; x++) {
|
||||||
|
int b, g, r;
|
||||||
|
Y12 = py[0] << 12;
|
||||||
|
// U = py[1024]; /* pu */
|
||||||
|
V = py[2048]; /* pv */
|
||||||
|
|
||||||
|
/* blue */
|
||||||
|
b = 128 + ((Y12 - V * 4 + py[1024] /* pu */ * 0x1C59) >> 12);
|
||||||
|
if (b & 0xffffff00)
|
||||||
|
b = (~b) >> 24;
|
||||||
|
|
||||||
|
/* green */
|
||||||
|
g = 128 + ((Y12 - V * 0x0B6C) >> 12);
|
||||||
|
if (g & 0xffffff00)
|
||||||
|
g = (~g) >> 24;
|
||||||
|
|
||||||
|
/* red */
|
||||||
|
r = 128 + ((Y12 + V * 0x166E) >> 12);
|
||||||
|
if (r & 0xffffff00)
|
||||||
|
r = (~r) >> 24;
|
||||||
|
if (b_type == 0x0004) {
|
||||||
|
rgb[0] = b;
|
||||||
|
rgb[1] = g;
|
||||||
|
rgb[2] = r;
|
||||||
|
py++;
|
||||||
|
rgb += 4;
|
||||||
|
} else if (b_type == 0x0002) {
|
||||||
|
r &= 0xff;
|
||||||
|
g &= 0xff;
|
||||||
|
b &= 0xff;
|
||||||
|
*(short *) rgb = PIXEL16(r >> 3, g >> 2, b >> 3);
|
||||||
|
rgb += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
py += mw - x1;
|
||||||
|
rgb += w;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define INIT_ZTABLE(i, b0, b1, b2, b3) *(int *) &zigzag_table[i] = b0 | b1 << 8 | b2 << 16 | b3 << 24
|
||||||
|
|
||||||
|
void jpeg_decode(JPEG *jpeg, UCHAR *rgb, int b_type)
|
||||||
|
{
|
||||||
|
int h_unit, v_unit;
|
||||||
|
int mcu_count, h, v;
|
||||||
|
int val;
|
||||||
|
unsigned char m;
|
||||||
|
|
||||||
|
UCHAR zigzag_table[64];
|
||||||
|
|
||||||
|
INIT_ZTABLE( 0, 0, 1, 8, 16); INIT_ZTABLE( 4, 9, 2, 3, 10);
|
||||||
|
INIT_ZTABLE( 8, 17, 24, 32, 25); INIT_ZTABLE(12, 18, 11, 4, 5);
|
||||||
|
INIT_ZTABLE(16, 12, 19, 26, 33); INIT_ZTABLE(20, 40, 48, 41, 34);
|
||||||
|
INIT_ZTABLE(24, 27, 20, 13, 6); INIT_ZTABLE(28, 7, 14, 21, 28);
|
||||||
|
INIT_ZTABLE(32, 35, 42, 49, 56); INIT_ZTABLE(36, 57, 50, 43, 36);
|
||||||
|
INIT_ZTABLE(40, 29, 22, 15, 23); INIT_ZTABLE(44, 30, 37, 44, 51);
|
||||||
|
INIT_ZTABLE(48, 58, 59, 52, 45); INIT_ZTABLE(52, 38, 31, 39, 46);
|
||||||
|
INIT_ZTABLE(56, 53, 60, 61, 54); INIT_ZTABLE(60, 47, 55, 62, 63);
|
||||||
|
|
||||||
|
jpeg_decode_init(jpeg);
|
||||||
|
|
||||||
|
h_unit = (jpeg->width + jpeg->mcu_width - 1) / jpeg->mcu_width;
|
||||||
|
v_unit = (jpeg->height + jpeg->mcu_height - 1) / jpeg->mcu_height;
|
||||||
|
|
||||||
|
mcu_count = 0;
|
||||||
|
for (v = 0; v < v_unit; v++) {
|
||||||
|
for (h = 0; h < h_unit; h++) {
|
||||||
|
mcu_count++;
|
||||||
|
jpeg_decode_mcu(jpeg, zigzag_table);
|
||||||
|
jpeg_decode_yuv(jpeg, h, v, rgb, b_type & 0x7fff);
|
||||||
|
if (jpeg->interval > 0 && mcu_count >= jpeg->interval) {
|
||||||
|
jpeg->bit_remain -= (jpeg->bit_remain & 7);
|
||||||
|
jpeg->bit_remain -= 8;
|
||||||
|
jpeg->mcu_preDC[0] = 0;
|
||||||
|
jpeg->mcu_preDC[1] = 0;
|
||||||
|
jpeg->mcu_preDC[2] = 0;
|
||||||
|
mcu_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
1
30_day/gview/make.bat
Normal file
1
30_day/gview/make.bat
Normal file
@@ -0,0 +1 @@
|
|||||||
|
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||||
BIN
30_day/pictdata/fujisan.jpg
Normal file
BIN
30_day/pictdata/fujisan.jpg
Normal file
Binary file not shown.
BIN
30_day/pictdata/fujisan_.jpg
Normal file
BIN
30_day/pictdata/fujisan_.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
BIN
30_day/pictdata/night.bmp
Normal file
BIN
30_day/pictdata/night.bmp
Normal file
Binary file not shown.
BIN
30_day/pictdata/night_.bmp
Normal file
BIN
30_day/pictdata/night_.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.1 KiB |
Reference in New Issue
Block a user