News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

GdipLoadImageFromFile example

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

Previous topic - Next topic

LiaoMi

Hi,

FASM mandeldb + MASM Example + TGALib
http://www.dca.fee.unicamp.br/~martino/disciplinas/ea978/tgaffs.pdf



; 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
    break
   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


Gunther

LiaoMi,

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.

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

Gunther

Steve,

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.

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

LiaoMi

Hi Gunther,

no, this is an example from the fasm forum.. https://board.flatassembler.net/topic.php?t=4381

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 https://www.fileformat.info/format/tga/sample/8fcef46a9229460cae03d41f89ef5287/MARBLES.TGA, 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" - https://www.codeproject.com/Articles/21084/Decoding-OpenGL-Textures-in-Targa-Format-from-an-S
Framework for loading TGA image data from an SQLite table, decoding this data and binding it to OpenGL textures.

hutch--

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.

HSE

Quote from: LiaoMi on February 20, 2021, 09:05:52 PM
no, this is an example from the fasm forum.. https://board.flatassembler.net/topic.php?t=4381
Apparently only read correctly 32bit format

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

Vortex

New attachment at the top. Corrected some minor bugs.

TouEnMasm

Fa is a musical note to play with CL

Gunther

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


TouEnMasm

The "DirectXTex texture processing library"  https://github.com/Microsoft/DirectXTex
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 https://github.com/microsoft/DirectXTex/wiki/DirectXTex
Sample of use for the function
Quote
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
Quote
I have try to add the 32 bit lib,too large


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

.data
Oneimage image <>
.code
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

jj2007

Quote from: TouEnMasm on February 21, 2021, 07:51:19 PM
The "DirectXTex texture processing library"  https://github.com/Microsoft/DirectXTex

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?

TimoVJL

http://www.dhpoware.com/source/bitmap.html
May the source be with you

TouEnMasm

Fa is a musical note to play with CL

jj2007