Dark Bit Factory & Gravity
PROGRAMMING => Other languages => ASM => Topic started by: ViL on July 02, 2018
-
Hii!
i've stumbled on PNGlib like it's the only png decoder for masm, it is the only one out there? this is the site of PNGlib
http://www.madwizard.org/programming/projects/pnglib
while it's considerably small, uPNG on C output is even smaller, counting kb; but some pairs of kb makes the difference on tiny intros :)
may i ask if anyone knows another png decoder for masm? :D
any idea is very welcome! x3
-
Hi Vil,
No need for bloated 3th party image libraries.
You can use GDIplus for that with a few lines of code.
It can load bmp, gif, jpeg, png, tiff and ico files from disk ( or from memory or from resource section ) and decompress it to memory as uncompressed raw ARGB data.
Here is an example to load a bitmap image from disk in Masm. ( and it's very very small. ;D)
include \masm32\include\gdiplus.inc
includelib \masm32\lib\gdiplus.lib
.const
; GDI+ info
ImageLockModeRead equ 1
PixelFormat32bppARGB equ 26200Ah
GdiplusStartupInput struct
GdiplusVersion dd ?
DebugEventCallback dd ?
SuppressBackgroundThread dd ?
SuppressExternalCodecs dd ?
GdiplusStartupInput ends
BitmapData struct
dwWidth dd ?
dwHeight dd ?
Stride dd ?
PixelFormat dd ?
Scan0 dd ?
Reserved dd ?
BitmapData ends
GdiplusInput GdiplusStartupInput <1,NULL,FALSE,FALSE>
.data?
; GDI+ data
align 4
pImage dd ?
ReturnMessage dd ?
GdiplusToken dd ?
GDIplusBitmapData BitmapData <?>
FilenameW dw MAX_PATH dup (?)
ARGB_raw_buffer dd 640 * 480 dup (?) ; memory to hold a raw 32bit bitmap of 640*480
.data
NicePicture db "NicePicture.png",0
.code
align 4
GDIp_LoadBitmap proc uses ebx esi edi ImageName:DWORD,pBitmap:DWORD
mov ReturnMessage,FALSE
invoke GdiplusStartup,offset GdiplusToken,offset GdiplusInput,NULL
test eax,eax
jnz Exit_LoadBitmap
invoke MultiByteToWideChar,CP_ACP,0,ImageName,-1,offset FilenameW,MAX_PATH-1
invoke GdipCreateBitmapFromFile,offset FilenameW,addr pImage
test eax,eax
jnz ShutdownGDIplus
invoke GdipBitmapLockBits,pImage,NULL,ImageLockModeRead,PixelFormat32bppARGB,offset GDIplusBitmapData
test eax,eax
jnz Close_Image
mov esi,GDIplusBitmapData.Scan0 ; pointer to the bitmap data
mov edi,offset ARGB_raw_buffer ; pointer to the output bitmap data
mov ecx,GDIplusBitmapData.dwHeight
Height_lp:
mov edx,GDIplusBitmapData.dwWidth
xor ebx,ebx
Width_lp:
mov eax,dword ptr [esi+ebx]
mov dword ptr [edi],eax
add edi,4
add ebx,4
dec edx
jnz Width_lp
add esi,GDIplusBitmapData.Stride
dec ecx
jnz Height_lp
mov ReturnMessage,TRUE
invoke GdipBitmapUnlockBits,pImage,offset GDIplusBitmapData
Close_Image:
invoke GdipDisposeImage,pImage
ShutdownGDIplus:
invoke GdiplusShutdown,GdiplusToken
Exit_LoadBitmap:
mov eax,ReturnMessage
ret
GDIp_LoadBitmap endp
; load bmp, gif, jpeg, png, tiff and ico files from disk and decompress to memory as uncompressed raw ARGB data.
invoke GDIp_LoadBitmap,offset NicePicture,offset ARGB_raw_buffer