Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6327 → Rev 6328

/programs/media/animage/trunk/bmplib.inc
1,236 → 1,4
;**************************************************************************
;**********************DECODING BMP FILE(1,4,8,24 bits)*********************
;***************************************************************************
; BMPTOIMG -Convert BMP format TO IMG format
;***************************************************************************
bmptoimg:
 
mov [bmp_load_area],esi
mov [img_dest_area],edi
xor eax,eax
mov ax,word[esi+28]
mov ebx,[esi+14]
mov ecx,[esi+18]
mov edx,[esi+22]
mov [bmp_bits_per_pixel],ax
mov [bmp_first_structure_size],ebx
mov [Bmp_SizeY],edx
mov [Bmp_SizeX],ecx
 
xor eax,eax
mov ax,[esi+28]
mul dword [esi+18]
add eax,31
shr eax,5
mov dword [bmptoimg_data_area_dwps],eax ;dwps-doublewords per string
shl eax,2
mov dword [bmptoimg_data_area_bps],eax ;bps-bytes per string
 
cmp dword [esi+34],0
jne yespicsize ;if picture size is defined
mul dword [esi+22]
mov dword [esi+34],eax
 
yespicsize:
 
mov eax,[bmp_load_area]
add eax, [esi+10] ;how mach bytes to begin bitmap
add eax, [esi+34] ;size of bitmap in BMP file
mov dword [bmptoimg_data_area_eop],eax ;eop-end of picture in file
;calculate bytes per string
mov eax, [esi+18]
lea eax,[eax+2*eax] ;3x pixels in eax
mov [bmp_bytes_per_string],eax
 
mov esi,dword [bmptoimg_data_area_eop]
sub esi,dword [bmptoimg_data_area_bps]
 
mov ebp,[img_dest_area]
mov edi,[img_dest_area]
mov ebx,[bmp_load_area]
add ebx, [bmp_first_structure_size]
add ebx,14 ;in ebx start of color table
 
 
cmp [bmp_bits_per_pixel],24
je convert_to_24bpp
 
cmp [bmp_bits_per_pixel],8
je convert_to_8bpp
 
cmp [bmp_bits_per_pixel],4
je convert_to_4bpp
 
cmp [bmp_bits_per_pixel],1
je convert_to_1bpp
 
jmp end_bmp
 
;--------------------------------------------------
;-----------Decoding 24 bit BMP file---------------
;--------------------------------------------------
convert_to_24bpp:
 
mov ebx,[Bmp_SizeY]
loop_convert_to_24bpp_y:
 
mov edi,ebp
mov ecx,[bmptoimg_data_area_dwps]
 
cld
rep movsd
 
sub esi,[bmptoimg_data_area_bps]
sub esi,[bmptoimg_data_area_bps]
 
add ebp,eax
dec ebx
jnz loop_convert_to_24bpp_y
 
jmp end_bmp
;-----------------------------------------------------
;--------------Decoding 8 bits BMP file---------------
;-----------------------------------------------------
convert_to_8bpp:
 
mov ebp,[Bmp_SizeY]
loop_convert_8bpp_y:
 
mov ecx,[bmptoimg_data_area_bps]
push edi
 
loop_convert_8bpp_x:
 
xor eax,eax
mov al,byte [esi]
call converttable
inc esi
add edi,3
 
dec ecx
jnz loop_convert_8bpp_x
 
pop edi
 
add edi,[bmp_bytes_per_string]
sub esi,[bmptoimg_data_area_bps]
sub esi,[bmptoimg_data_area_bps]
 
dec ebp
jnz loop_convert_8bpp_y
 
jmp end_bmp
;-----------------------------------------------------
;--------------Decoding 4 bits BMP file---------------
;-----------------------------------------------------
convert_to_4bpp:
 
mov ebp,[Bmp_SizeY]
loop_convert_4bpp_y:
 
mov ecx,[bmptoimg_data_area_bps]
push edi
 
loop_convert_4bpp_x:
 
mov [Bmp_save1],ecx
xor eax,eax
mov al,byte [esi]
xor ecx,ecx
mov cl,al
shr al,4 ;first pixel in byte
and cl,0xf ;second pixel in byte
call converttable ;draw first pixel of byte
mov eax,ecx ;move second pixel to register al and draw
add edi,3
call converttable ;draw second pixel of byte
add edi,3
mov ecx,[Bmp_save1]
inc esi
 
dec ecx
jnz loop_convert_4bpp_x
 
pop edi
 
add edi,[bmp_bytes_per_string]
sub esi,[bmptoimg_data_area_bps]
sub esi,[bmptoimg_data_area_bps]
 
dec ebp
jnz loop_convert_4bpp_y
 
jmp end_bmp
;-----------------------------------------------------
;---------------Decoding 1 bit BMP file---------------
;-----------------------------------------------------
convert_to_1bpp:
 
mov ebp,[Bmp_SizeY]
loop_convert_1bpp_y:
 
mov ecx,[bmptoimg_data_area_bps]
push edi
 
loop_convert_1bpp_x:
 
xor eax,eax
mov al,byte [esi]
mov [Bmp_save1],ecx
mov ecx,eax
mov edx,7
nextbit:
xor eax,eax
bt ecx,edx
jnc noaddelem
inc eax
noaddelem:
 
push edx
call converttable
pop edx
 
add edi,3
dec edx
jns nextbit
mov ecx,[Bmp_save1]
inc esi
dec ecx
jnz loop_convert_1bpp_x
 
pop edi
 
add edi,[bmp_bytes_per_string]
sub esi,[bmptoimg_data_area_bps]
sub esi,[bmptoimg_data_area_bps]
 
dec ebp
jnz loop_convert_1bpp_y
 
jmp end_bmp
;-----------------------------------------------------
converttable:
shl eax,2
add eax,ebx
mov edx, dword [eax]
mov [edi],edx
ret
;-----------------------------------------------------
; DATA AREA
bmptoimg_data_area_bps dd 0
bmptoimg_data_area_dwps dd 0
bmptoimg_data_area_eop dd 0
bmp_load_area dd 0
img_dest_area dd 0
bmp_bits_per_pixel dw 0
bmp_first_structure_size dd 0
bmp_bytes_per_string dd 0
 
end_bmp:
 
ret
 
;***************************************************************************
;*******************CODING BMP FILE(1,4,8,24 bits)**************************
;***************************************************************************