7,29 → 7,161 |
; Graphics |
; Libary |
; |
; Ver 0.18 By Pavlushin Evgeni (RUSSIA) |
; www.waptap@mail.ru |
; Ver 0.18 |
; |
|
;InfoList |
;0.01 LoadImage |
;0.02 SetBmp |
;0.03 Bmptoimg, Setimg ~01.03.2004 |
;0.04 Bug deleted, copyimg ~03.05.2004 |
;0.05 fullimg, collimg ~05.05.2004 |
;0.06 getimg ~09.05.2004 |
;0.07 convbmp ~13.05.2004 |
;0.08 fps ~14.05.2004 |
;0.09 drawfbox ~03.06.2004 |
;0.10 all macros optimized by halyavin, add at ~07.06.2004 |
;0.11 many macros optimized by halyavin, add at ~30.08.2004 |
;0.12 bmptoimg ~07.09.2004 |
;0.13 imgtoimg ~08.09.2004 |
;0.14 imgtoimg modify not brake bmp pict! ~09.09.2004 |
;0.15 giftoimg, giftoani ~10.09.2004 |
;0.16 setframe, rgbtobgr, setbmp deleted ~20.09.2004 |
;0.17 modification giftoimg, giftoani, getframeoff ~01.10.2004 |
;0.18 aframetoimg,aimgtoimg,frametoimg ~03.10.2004 |
; draw image into image with alpha color mask |
; image_draw_acimage dest, source, x, y, alpha_color |
; |
macro image_draw_acimage dest, source, x, y, alpha_color |
{ |
local next_pix,next_line,skip_pix,no_skip |
push dest |
push source |
push x |
push y |
push alpha_color |
pop ebp ; alpha color |
pop eax ; y |
pop ebx ; x |
pop esi ; src |
pop edi ; dest |
call image_draw_acimage_proc |
|
if ~ defined image_draw_acimage_used |
image_draw_acimage_used equ 1 |
|
jmp end_image_draw_acimage_proc |
image_draw_acimage_proc: |
mov ecx,dword [edi] ; ecx = canvas width |
mul ecx ; edx:eax = ypos * canvas width |
add eax,ebx ; eax = (ypos * canvas width) + xpos |
lea eax,[eax+eax*2+8] ; eax=(y*xsize+x)*3+8 (8=skip xy size dwords) |
|
mov edx,[esi] ; edx = img width |
sub ecx,edx ; ecx = canvas width - img width |
lea ebx,[ecx*2+ecx] ; ebx = how many pixels skip for new line |
mov ecx,[esi+4] ; ecx = img height |
add esi,8 ; esi + 8 for skip xy size dwords |
add edi,eax ; edi = dest position |
shl ebp,8 ; for fast compare with alpha color |
cld ; set movs direction flag |
next_line: |
push edx |
next_pix: |
mov eax,[esi] |
shl eax,8 |
cmp eax,ebp |
je skip_pix |
movsw |
movsb |
jmp no_skip |
skip_pix: |
add esi,3 |
add edi,3 |
no_skip: |
dec edx |
jnz next_pix |
pop edx |
add edi,ebx |
dec ecx |
jnz next_line |
ret |
end_image_draw_acimage_proc : |
end if |
|
} |
|
macro image_set_size image,width,height |
{ |
mov dword [image],width |
mov dword [image+4],height |
} |
|
; label - draw label on window |
; example: |
; label 10,12,'Hello World!',cl_Green+font_size_x4+utf16 |
|
macro image_draw_label image,x,y,text,color |
{ |
local label_text |
draw_to_buffer equ 00001000b shl 24 |
jmp @f |
label_text db text |
@@: |
words2reg ebx,x,y ; ebx - position |
dword2reg ecx,color+draw_to_buffer ; ecx - color |
mov edi,image |
mov edx,label_text ; edx - address of label text |
mov esi,@b-label_text ; esi - size of libel in bytes |
mov eax,4 |
mcall |
} |
|
; draw_frect - draw filled rect |
macro draw_frect x,y,xs,ys,color |
{ |
wordstoreg ebx,x,xs ;x*65536+xs |
wordstoreg ecx,y,ys ;y*65536+ys |
mov edx,color |
mov eax,13 |
mcall |
} |
|
; draw_label - Draw label in window |
; example: |
; draw_label 10,12,'Hello World!',cl_Green+font_size_x4+utf16 |
|
macro draw_label x,y,text,color |
{ |
local label_text |
words2reg ebx,x,y ; ebx - position |
if text eqtype 123 | text eqtype eax |
movt edx,text |
mov ecx,color+(1 shl 31) ; ecx - color |
else |
mov edx,label_text ; edx - address of label text |
jmp @f |
label_text db text |
@@: |
mov esi,@b-label_text ; esi - size of libel in bytes |
movt ecx,color ; ecx - color |
end if |
mov eax,4 |
mcall |
} |
|
hide_zeros equ (1 shl 31) |
use_bg_color equ (1 shl 30) |
use_big_font equ (1 shl 28) |
|
macro draw_number data, x, y, color, numtype, bg_color |
{ |
movt ecx,data |
movt ebx,numtype |
mov bl,0 ; if bl = 0, ecx is contain number |
words2reg edx,x,y |
if bg_color eq |
movt esi,color |
else |
movt esi,color+use_bg_color |
movt edi,bg_color |
end if |
mov eax,47 |
mcall |
} |
|
; draw_image - macro for draw image on window area |
macro draw_image x, y, image |
{ |
mov ecx,[image-2] ; -2 for except shl ecx,16 |
mov cx,[image+4] ; ecx = xsize*65536+ysize |
wordstoreg edx, x, y ; edx = x*65536+y |
lea ebx,[image+8] ; ebx = image data address |
mov eax,7 ; eax = 7 is draw image function |
mcall |
} |
|
aframetoimg_use_count=0 |
macro aframetoimg img, x, y, canvas,acol |
{ |
81,7 → 213,6 |
add ebp,3 |
jmp nx |
yx: |
|
mov al,byte [edx] |
mov byte [ebp],al |
inc ebp |
205,97 → 336,6 |
} |
|
|
aimgtoimg_use_count=0 |
macro aimgtoimg img, x, y, canvas,acol |
{ |
local loo,loo2,acolor |
aimgtoimg_use_count=aimgtoimg_use_count+1 |
if aimgtoimg_use_count = 1 |
|
jmp end_aimgtoimg_proc |
|
acolor dd 0 |
aimgtoimg_proc: |
;getout coord |
mov [acolor],ebp |
|
mov eax,esi ;y cor |
mul dword [ecx] ;canvas xsize |
add eax,edi ;x cor |
mov ebp,eax |
shl eax,1 |
add ebp,eax |
add ebp,ecx ;canvas+8;start |
add ebp,8 |
;get img size |
mov eax,ebx ;img ;xsize |
mov esi,[eax] |
add ebx,4 |
mov eax,ebx ; img+4 ;ysize |
mov edi,[eax] |
add ebx,4 |
mov edx,ebx ;img+8 |
loo2: |
push esi |
loo: |
|
;test on alpha color |
mov eax,[edx] |
shl eax,8 |
shr eax,8 |
cmp eax,[acolor] |
jne yx |
add edx,3 |
add ebp,3 |
jmp nx |
yx: |
|
mov al,byte [edx] |
mov byte [ebp],al |
inc ebp |
inc edx |
mov al,byte [edx] |
mov byte [ebp],al |
inc ebp |
inc edx |
mov al,byte [edx] |
mov byte [ebp],al |
inc ebp |
inc edx |
nx: |
dec esi |
jnz loo |
pop esi |
sub ebp,3 |
mov eax,[ecx] ;offset = offset+((canxsize-imgxsize)*3) |
sub eax,esi |
add ebp,eax |
shl eax,1 |
add ebp,eax |
|
add ebp,3 |
|
dec edi |
jnz loo2 |
ret |
end_aimgtoimg_proc: |
end if |
push img |
push canvas |
push x |
push y |
push acol |
pop ebp |
pop esi |
pop edi |
pop ecx |
pop ebx |
call aimgtoimg_proc |
} |
|
|
|
|
imgtoimg_use_count=0 |
macro imgtoimg img, x, y, canvas |
{ |
346,9 → 386,7 |
add ebp,eax |
shl eax,1 |
add ebp,eax |
|
add ebp,3 |
|
dec edi |
jnz loo2 |
ret |
365,17 → 403,6 |
call imgtoimg_proc |
} |
|
|
;DrawBox |
macro drawfbox x,y,xs,ys,color |
{ |
wordstoreg ebx,x,xs ;x*65536+xs |
wordstoreg ecx,y,ys ;y*65536+ys |
mov edx,color |
mov eax,13 |
mcall |
} |
|
; FPS - Set Frame Per Second Display |
fps_show_frequency=40 |
macro fps x,y,color,delcolor |
422,60 → 449,13 |
no_out_fps: |
} |
|
; COLLIMG - Collusion image's |
_1dbounce_count=0; |
macro collimg img1_off,x1,y1,img2_off,x2,y2,otv |
{ |
local bounce,exit,anot,bc,nbc |
mov esi,[img1_off] ;xs1 |
mov edi,[img2_off] ;ys2 |
mov eax,x1 ; |
mov ebx,x2 ; |
call _1dbounce |
mov edx,ecx |
mov esi,[img1_off+4] ;ys1 |
mov edi,[img2_off+4] ;ys2 |
mov eax,y1 ; |
mov ebx,y2 ; |
call _1dbounce |
add edx,ecx |
cmp edx,2 |
je bounce |
mov otv,0 |
jmp exit |
_1dbounce_count=_1dbounce_count+1 |
if _1dbounce_count = 1 |
_1dbounce: |
cmp ebx,eax |
jb anot |
add eax,esi |
cmp eax,ebx |
jbe nbc |
bc: |
mov ecx,1 |
ret |
anot: |
add ebx,edi |
cmp ebx,eax |
ja bc |
nbc: |
xor ecx,ecx |
ret |
end if |
bounce: |
mov otv,1 |
exit: |
} |
|
macro rgbtobgr image |
{ |
local loo |
mov eax,[image] |
mul dword [image+4] |
mov ecx,eax |
mov esi,image+8 |
; add esi,8 |
loo: |
@@: |
mov al,[esi] |
mov bl,[esi+2] |
mov [esi],bl |
482,23 → 462,9 |
mov [esi+2],al |
add esi,3 |
dec ecx |
jnz loo |
jnz @b |
} |
|
|
macro setimg x , y ,arg3 |
{ |
mov eax,7 |
mov ebx,arg3 |
add ebx,8 |
mov cx,[arg3] |
shl ecx,16 |
add cx,[arg3+4] |
; wordstoreg ecx,[arg3],[arg3+4] |
wordstoreg edx, x , y ;arg1*65536+arg2 |
mcall |
} |
|
macro setframe x , y ,arg3 |
{ |
mov eax,7 |
513,57 → 479,47 |
|
macro getimg imgsrc,x,y,xs,ys,imgdest |
{ |
local cyc |
if xs eqtype 0 |
local next_pixel,next_line |
; store image size |
if xs eqtype 0 | xs eqtype eax |
mov dword [imgdest],xs |
else |
mov eax,xs |
mov dword [imgdest],eax |
end if |
if ys eqtype 0 |
if ys eqtype 0 | ys eqtype eax |
mov dword [imgdest+4],ys |
else |
;push ys |
;pop dword [imgdest+4] |
mov eax,ys |
mov dword [imgdest+4],eax |
end if |
|
mov eax,dword [imgsrc] ;getx size |
; lea ecx,[eax+2*eax] |
mov ecx,eax |
shl ecx,1 |
add ecx,eax |
|
mov ebx,y |
mul ebx |
lea edi,[8+imgdest] ; edi = destinaton address |
mov eax,dword [imgsrc] ; eax = xsize of source image in pixels |
push eax ; store eax before mul operation |
mov edx,y |
mul edx ; edx:eax = eax*edx |
add eax,x |
mov edx,ecx |
lea eax,[eax+2*eax] ;eax=offset on imsrc |
; mov ebp,eax |
; shl eax,1 |
; add eax,ebp |
lea esi,[imgsrc+8+eax+2*eax] ; esi = start offset on img src |
pop eax ; restore eax |
sub eax,xs ; eax = src image xsize - crop fragment xsize |
lea eax,[eax+eax*2] ; eax = eax * 3 (bytes per pixel) |
|
mov ecx,xs |
mov ebx,ys |
|
mov edi,8+imgdest |
lea esi,[eax+8+imgsrc] |
; mov esi,eax |
; add esi,8 |
; add esi,imgsrc |
|
cld |
cyc: |
; this loop used esi,edi,ecx,edx,eax registers |
mov edx,ys ; edx = ysize in pixels |
cld ; set direction |
next_line: |
mov ecx,xs ; ecx = xsize in pixels |
next_pixel: |
movsw |
movsb |
movsb ; write 3 bytes pixel |
dec ecx |
jne cyc |
add esi,edx |
mov ecx,xs |
sub esi,ecx |
sub esi,ecx |
sub esi,ecx |
dec ebx |
jne cyc |
jnz next_pixel |
add esi,eax |
dec edx |
jnz next_line |
} |
|
macro copyimg img2_off,img1_off |
604,8 → 560,6 |
jne cop |
} |
|
|
|
; number of frame in ecx |
; callculatin offset of raw data |
|
630,13 → 584,11 |
mov dword offset_of_frame,esi |
} |
|
|
; BMPTOIMG -Convert BMP format TO IMG format |
; (SYNTAX) BMPTOIMG BMP_source_offset,IMG_dest_ofset |
; (SAMPLE) View BMPLS.ASM sample. |
; ( NOTE ) This is macros is not brake bmp structure! Tested in 32,8,4 bits |
; ( NOTE ) This is macro is not brake bmp structure! Tested in 32,8,4 bits |
|
|
bmptoimg_data_area_count=0 |
macro bmptoimg bmp_load_area,img_dest_area |
{ |
725,9 → 677,7 |
cmp esi,dword [bmptoimg_data_area_eos] |
jae convert1 |
add edi,3 |
|
add ebp,3 |
|
jmp nextelem |
|
convert4bpp: |
737,9 → 687,7 |
movzx eax,ah |
call converttable |
add edi,3 |
|
add ebp,3 |
|
pop ax |
movzx eax,al |
call converttable |
760,11 → 708,8 |
dec edx |
js convert2 |
add edi,3 |
|
add ebp,3 |
|
jmp nextbit |
|
converttable: |
shl eax,2 |
add eax,ebx |