libs-dev: made test002 program (simple image viewer) not to crash

git-svn-id: svn://kolibrios.org@2405 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Ivan Baravy 2012-02-25 18:15:52 +00:00
parent 946e05cb81
commit 7a8e2e79f9

View File

@ -44,27 +44,19 @@ START:
inc eax inc eax
jz exit jz exit
invoke img.is_img, [img_data], [img_data_len] invoke img.decode, [img_data], [img_data_len], 0
or eax, eax
jz exit
invoke img.decode, [img_data], [img_data_len]
or eax, eax or eax, eax
jz exit jz exit
mov [image], eax mov [image], eax
invoke img.to_rgb, eax
or eax, eax
jz exit
mov [rgb_img], eax
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
red: redraw:
call draw_window call draw_window
still: still:
mcall 10 mcall 10
cmp eax, 1 cmp eax, 1
je red je redraw
cmp eax, 2 cmp eax, 2
je key je key
cmp eax, 3 cmp eax, 3
@ -84,35 +76,35 @@ still:
jne @f jne @f
invoke img.flip, [image], FLIP_HORIZONTAL invoke img.flip, [image], FLIP_HORIZONTAL
jmp redraw_image jmp redraw
; flip vertically ; flip vertically
@@: cmp eax, 'flv' @@: cmp eax, 'flv'
jne @f jne @f
invoke img.flip, [image], FLIP_VERTICAL invoke img.flip, [image], FLIP_VERTICAL
jmp redraw_image jmp redraw
; flip both horizontally and vertically ; flip both horizontally and vertically
@@: cmp eax, 'flb' @@: cmp eax, 'flb'
jne @f jne @f
invoke img.flip, [image], FLIP_BOTH invoke img.flip, [image], FLIP_BOTH
jmp redraw_image jmp redraw
; rotate left ; rotate left
@@: cmp eax, 'rtl' @@: cmp eax, 'rtl'
jne @f jne @f
invoke img.rotate, [image], ROTATE_90_CCW invoke img.rotate, [image], ROTATE_90_CCW
jmp redraw_image jmp redraw
; rotate right ; rotate right
@@: cmp eax, 'rtr' @@: cmp eax, 'rtr'
jne @f jne @f
invoke img.rotate, [image], ROTATE_90_CW invoke img.rotate, [image], ROTATE_90_CW
jmp redraw_image jmp redraw
@@: cmp eax, 1 @@: cmp eax, 1
jne still jne still
@ -120,28 +112,11 @@ still:
exit: exit:
mcall -1 mcall -1
redraw_image:
stdcall mem.Free, [rgb_img]
invoke img.to_rgb, [image]
or eax, eax
jz exit
mov [rgb_img], eax
jmp red
draw_window: draw_window:
invoke gfx.open, TRUE invoke gfx.open, TRUE
mov [ctx], eax mov [ctx], eax
@^
mov edi, [rgb_img]
mov ebx, 200 * 65536
mov bx, [edi + 0]
add bx, 9
mov ecx, 200 * 65536
mov cx, [edi + 4]
add cx, 5 + 21
mcall 0, , , 0x33FF0000, , s_header
^@
mcall 0, <100, 640>, <100, 480>, 0x33FFFFFF, , s_header mcall 0, <100, 640>, <100, 480>, 0x33FFFFFF, , s_header
invoke gfx.pen.color, [ctx], 0x007F7F7F invoke gfx.pen.color, [ctx], 0x007F7F7F
@ -156,12 +131,8 @@ draw_window:
mcall 8, <10 + 25 * 3, 20>, <5, 20>, 'rtl', 0x007F7F7F mcall 8, <10 + 25 * 3, 20>, <5, 20>, 'rtl', 0x007F7F7F
mcall 8, <10 + 25 * 4, 20>, <5, 20>, 'rtr', 0x007F7F7F mcall 8, <10 + 25 * 4, 20>, <5, 20>, 'rtr', 0x007F7F7F
mov ebx, [rgb_img] mov eax, [image]
mov ecx, [ebx + 0] stdcall [img.draw], eax, 5, 35, [eax + Image.Width], [eax + Image.Height], 0, 0
shl ecx, 16
mov cx, [ebx + 4]
add ebx, 4 * 2
mcall 7, , , <5, 35>
invoke gfx.close, [ctx] invoke gfx.close, [ctx]
ret ret
@ -231,25 +202,24 @@ library \
import libio , \ import libio , \
libio.init , 'lib_init' , \ libio.init , 'lib_init' , \
file.size , 'file.size' , \ file.size , 'file_size' , \
file.open , 'file.open' , \ file.open , 'file_open' , \
file.read , 'file.read' , \ file.read , 'file_read' , \
file.close , 'file.close' file.close , 'file_close'
import libgfx , \ import libgfx , \
libgfx.init , 'lib_init' , \ libgfx.init , 'lib_init' , \
gfx.open , 'gfx.open' , \ gfx.open , 'gfx_open' , \
gfx.close , 'gfx.close' , \ gfx.close , 'gfx_close' , \
gfx.pen.color , 'gfx.pen.color' , \ gfx.pen.color , 'gfx_pen_color' , \
gfx.line , 'gfx.line' gfx.line , 'gfx_line'
import libimg , \ import libimg , \
libimg.init , 'lib_init' , \ libimg.init , 'lib_init' , \
img.is_img , 'img.is_img' , \ img.draw , 'img_draw' , \
img.to_rgb , 'img.to_rgb' , \ img.decode , 'img_decode' , \
img.decode , 'img.decode' , \ img.flip , 'img_flip' , \
img.flip , 'img.flip' , \ img.rotate , 'img_rotate'
img.rotate , 'img.rotate'
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
@ -258,7 +228,6 @@ I_END:
img_data dd ? img_data dd ?
img_data_len dd ? img_data_len dd ?
fh dd ? fh dd ?
rgb_img dd ?
image dd ? image dd ?
ctx dd ? ctx dd ?