Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

GdipLoadImageFromFile example

Started by Vortex, February 19, 2021, 03:32:20 AM

Previous topic - Next topic



FASM mandeldb + MASM Example + TGALib

; DON'T _RUN_ this file, just COMPILE it and view it with any
; image program that supports 8-bit paletted TGA-images (many does).

; usage: "fasm mandeldb.asm"

format  binary as ".tga"

; Some basic image properties. Feel free to modify
Width  equ 120
Height       equ 120
IterLim equ 256
Prec      equ 29; don't set above 29 nor to low, else image may be scrambled

; TGA-header: 8-bit paletted image
dw 256,1
db 0,0,1,24
dw 0,0,Width,Height
db 8,8

; palette: 256*3bytes (RGB)
repeat 256
db (%+54h) and 0FFh
db (%+0A9h) and 0FFh
db % - 1
end repeat

; actual image (Mandelbrot fractal)
PrecScale = 1 shl (Prec-1)

StepR = (5 shl (Prec-1) +Width       shr 1) / Width; = 2.5/Width
StepI = (5 shl (Prec-1) +Height shr 1) / Height; = 3/Height

PosI = -5 shl (Prec-2); = -1.25
repeat Height
PosR = -2 shl Prec; = -2
repeat Width
  R = PosR
  I = PosI
  RR = (PosR*PosR) shr Prec
  II = (PosI*PosI) shr Prec

  Color = IterLim - 1; Color is also the current iteration number
  repeat IterLim
   if (RR + II) > 4 shl Prec
   end if
   Tmp = (RR - II) + PosR
   I = (R*I) / PrecScale + PosI
   R = Tmp
   RR = (Tmp*Tmp) shr Prec
   II = (I*I) shr Prec
   Color = Color - 1; discounting Color
  end repeat
  if Color < 0
   Color = 0
  end if
  db Color

  PosR = PosR + StepR
end repeat
PosI = PosI + StepI
end repeat



thank you for your distribution. I know the C library from Mr. Brueckner.

Is it your assembly language code? The program did crash. First I've loaded a 24 Bit True Color Image and it was displayed as greyscale image but upside down and torn quite obliquely.
By loading a large True Color Image (20 MB) the application crashed.

You have to know the facts before you can distort them.



Quote from: hutch-- on February 20, 2021, 09:48:46 AM
24 bit BMP format is lossless but TGA is not supported in GDI+ so I would be looking for a library or even an app that will convert TGA to 24 bit BMP.

I found a couple of links that may be useful to you.

that doesn't help. I think that I'm on the right way, but it'll take some time. If I am successful, I will open a new thread.

You have to know the facts before you can distort them.


Hi Gunther,

no, this is an example from the fasm forum..

Quotebut upside down

mov     [bmi.bmiHeader.biHeight], ecx

must be

push ecx
neg ecx
mov     [bmi.bmiHeader.biHeight], ecx
pop ecx

For testing I took the file, it was displayed, but the picture has a diagonal separator. The color of the picture is displayed very well.

Another interesting example is "Decoding OpenGL Textures in Targa Format from an SQLite Database" -
Framework for loading TGA image data from an SQLite table, decoding this data and binding it to OpenGL textures.


There has to code around to do the conversion, my ancient Micrografx Picture Publisher converts both ways, I guess its finding some code that has been posted that will do the conversion.


Quote from: LiaoMi on February 20, 2021, 09:05:52 PM
no, this is an example from the fasm forum..
Apparently only read correctly 32bit format

You can check file format inserting in line 358 (LoadTGA): movsx eax, byte  ptr [edx+8*2]  ; <--- bitsPerPixel
        print str$(eax),13,10
Equations in Assembly: SmplMath


New attachment at the top. Corrected some minor bugs.


Fa is a musical note to play with CL


You have to know the facts before you can distort them.


The "DirectXTex texture processing library"
Seem to be done by microsoft,so I have translated the DirectXTex.h  with the LoadFromTGAFile function.
doc of the library can be found here
Sample of use for the function
auto image = std::make_unique<ScratchImage>();
HRESULT hr = LoadFromTGAFile( L"ROCKS.TGA", TGA_FLAGS_NONE, nullptr, *image );
if ( FAILED(hr) )
    // error
image is a structure defined in directxtex.sdk
I have try to add the 32 bit lib,too large

   awidth XMASM ?
   height XMASM ?
   format DWORD ?
   rowPitch XMASM ?
   slicePitch XMASM ?
pixels XMASM ?
Image      ENDS

Oneimage image <>
invoke LoadFromTGAFile,TXT( "ROCKS.TGA"), TGA_FLAGS_NONE,NULL, addr Oneimage           ;perhaps name must be in unicode
Fa is a musical note to play with CL


Quote from: TouEnMasm on February 21, 2021, 07:51:19 PM
The "DirectXTex texture processing library"

I've tried the ...\DirectXTex-master\DirectXTex_Desktop_2017.sln with VS Express 2010, but obviously it throws loads of errors (so much to portability etc). Could you build the DLL, Yves, can you post it?

May the source be with you


Fa is a musical note to play with CL