Author Topic: GdipLoadImageFromFile example  (Read 1282 times)

LiaoMi

  • Member
  • ****
  • Posts: 797
Re: GdipLoadImageFromFile example
« Reply #15 on: February 20, 2021, 09:49:15 AM »
Hi,

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

Code: [Select]

; 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

  • Member
  • *****
  • Posts: 3720
  • Forgive your enemies, but never forget their names
Re: GdipLoadImageFromFile example
« Reply #16 on: February 20, 2021, 12:24:01 PM »
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
 
Get your facts first, and then you can distort them.

Gunther

  • Member
  • *****
  • Posts: 3720
  • Forgive your enemies, but never forget their names
Re: GdipLoadImageFromFile example
« Reply #17 on: February 20, 2021, 12:26:46 PM »
Steve,

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
Get your facts first, and then you can distort them.

LiaoMi

  • Member
  • ****
  • Posts: 797
Re: GdipLoadImageFromFile example
« Reply #18 on: February 20, 2021, 09:05:52 PM »
Hi Gunther,

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

Quote
but upside down

Code: [Select]
mov     [bmi.bmiHeader.biHeight], ecx
must be

Code: [Select]
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--

  • Administrator
  • Member
  • ******
  • Posts: 8233
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: GdipLoadImageFromFile example
« Reply #19 on: February 21, 2021, 12:46:04 AM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

HSE

  • Member
  • *****
  • Posts: 1612
  • <AMD>< 7-32>
Re: GdipLoadImageFromFile example
« Reply #20 on: February 21, 2021, 01:27:13 AM »
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):
Code: [Select]
movsx eax, byte  ptr [edx+8*2]  ; <--- bitsPerPixel
        pushad
        print str$(eax),13,10
       popad

Vortex

  • Member
  • *****
  • Posts: 2530
Re: GdipLoadImageFromFile example
« Reply #21 on: February 21, 2021, 01:42:05 AM »
New attachment at the top. Corrected some minor bugs.

TouEnMasm

  • Member
  • *****
  • Posts: 1615
    • EditMasm
Re: GdipLoadImageFromFile example
« Reply #22 on: February 21, 2021, 04:55:43 AM »

Library to read TGA files and other things
https://archive.codeplex.com/?p=directxtex
Fa is a musical note to play with CL

Gunther

  • Member
  • *****
  • Posts: 3720
  • Forgive your enemies, but never forget their names
Re: GdipLoadImageFromFile example
« Reply #23 on: February 21, 2021, 10:31:56 AM »
Good work Erol.  :thumbsup:

Yves,

Library to read TGA files and other things
https://archive.codeplex.com/?p=directxtex

thank you for the link.

Gunther
Get your facts first, and then you can distort them.

Mikl__

  • Member
  • *****
  • Posts: 1087
Re: GdipLoadImageFromFile example
« Reply #24 on: February 21, 2021, 01:19:03 PM »

TouEnMasm

  • Member
  • *****
  • Posts: 1615
    • EditMasm
Re: GdipLoadImageFromFile example
« Reply #25 on: February 21, 2021, 07:51:19 PM »
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

  • Member
  • *****
  • Posts: 11306
  • Assembler is fun ;-)
    • MasmBasic
Re: GdipLoadImageFromFile example
« Reply #26 on: February 21, 2021, 09:48:59 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

  • Member
  • ****
  • Posts: 695
Re: GdipLoadImageFromFile example
« Reply #27 on: February 22, 2021, 12:13:47 AM »
May the source be with you

TouEnMasm

  • Member
  • *****
  • Posts: 1615
    • EditMasm
Re: GdipLoadImageFromFile example
« Reply #28 on: February 22, 2021, 03:58:09 AM »
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 11306
  • Assembler is fun ;-)
    • MasmBasic
Re: GdipLoadImageFromFile example
« Reply #29 on: February 22, 2021, 05:14:31 AM »
Thanks, Yves :thumbsup: