Author Topic: Re: JpgTool application  (Read 331 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7294
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: JpgTool application
« Reply #15 on: June 03, 2020, 04:33:21 PM »
Thanks timo,

That worked perfectly.
Code: [Select]
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

LoadResImage proc ResID:QWORD

    LOCAL MemStream :QWORD
    LOCAL pBMP      :QWORD
    LOCAL hBMP      :QWORD
    LOCAL pRes      :QWORD
    LOCAL rSiz      :QWORD
    LOCAL rDat      :QWORD
    LOCAL stream    :QWORD

    LOCAL var   :QWORD

    mov MemStream, rvcall(GetProcAddress,rvcall(GetModuleHandle,"shlwapi.dll"),"SHCreateMemStream")

    mov pRes, rvcall(FindResource,0,ResID,RT_RCDATA)        ; find the resource
    mov rSiz, rvcall(SizeofResource,0,pRes)                 ; get its size
    mov rDat, rvcall(LoadResource,0,pRes)                   ; load the resource

    mov stream, rvcall(MemStream,rDat,rSiz)                 ; create the memory stream

    rcall GdipCreateBitmapFromStream,stream,ptr$(pBMP)      ; create a GDI+ bitmap
    rcall GdipCreateHBITMAPFromBitmap,pBMP,ptr$(hBMP),0     ; convert it to a Windows bitmap
    rcall GdipDisposeImage,pBMP                             ; delete the GDI+ bitmap

    mov rax, stream
    mov rax, [rax]
    call QWORD PTR [rax+16]                                 ; release the stream

    ; rcall MessageBox,hWnd,LastError$(),"Title",MB_ICONINFORMATION

    mov rax, hBMP                                           ; return the bitmap handle

    ret

LoadResImage endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Vortex

  • Member
  • *****
  • Posts: 2241
Re: JpgTool application
« Reply #16 on: June 03, 2020, 11:06:03 PM »
Hi Hutch,

I didn't use any other library. Also, my resource file defines only a bitmap. I will try to modify my example to simulate your project.

Vortex

  • Member
  • *****
  • Posts: 2241
Re: JpgTool application
« Reply #17 on: June 04, 2020, 05:19:34 AM »
Hi Hutch,

Could you try the attached new version? Here are the modifications :

Code: [Select]
start PROC

    mov     rax,OFFSET StartupInfo
    mov     GdiplusStartupInput.GdiplusVersion[rax],1
    invoke  GdiplusStartup,ADDR token,ADDR StartupInfo,0
.
.

Code: [Select]
    .ifeq edx,WM_CREATE

        invoke  LoadRsrcImage,1000
     
    .elseifeq edx,WM_PAINT

Code: [Select]
LoadRsrcImage PROC ResID:QWORD

LOCAL BmpImage  :QWORD

        invoke  GdipCreateBitmapFromResource,hInstance,ResID,\
                ADDR BmpImage

        invoke  GdipCreateHBITMAPFromBitmap,BmpImage,\
                ADDR hBitmap,0

        invoke  GdipDisposeImage,BmpImage

        mov     rax,hBitmap
        ret

LoadRsrcImage ENDP

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7294
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: JpgTool application
« Reply #18 on: June 04, 2020, 06:31:37 AM »
Hi Erol,

Your version worked as before but I have tracked it down using your working example. It seems that the GDI+ function will only work with a BMP file. I changed it to a PNG and it no longer worked.
Code: [Select]
// 1000 BITMAP logo.bmp

1000 RCDATA "logo.png"
This is unfortunate as the code was clean and simple.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 10318
  • Assembler is fun ;-)
    • MasmBasic
Re: JpgTool application
« Reply #19 on: June 04, 2020, 08:02:08 AM »
GdipCreateBitmapFromStream is much more flexible, as it just needs a pointer. That can come from InputFile or from an RCDATA resource, or even straight from the Internet. GuiImage can use all three modes.

Vortex

  • Member
  • *****
  • Posts: 2241
Re: JpgTool application
« Reply #20 on: June 05, 2020, 04:07:25 AM »
Here is a jpg loader from memory based on the cooperation of CreateStreamOnHGlobal and GdipCreateBitmapFromStream :

Code: [Select]
    invoke  CreateStreamOnHGlobal,hGlobal,\
            TRUE,ADDR pStream
           
    test    rax,rax
    jz      @f

    invoke  GlobalUnlock,hGlobal
    invoke  GlobalFree,hGlobal
    jmp     _exit
@@:
    invoke  GdipCreateBitmapFromStream,pStream,\
            ADDR BitmapImage

    invoke  GdipCreateHBITMAPFromBitmap,BitmapImage,\
            ADDR hBitmap,0

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7294
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: JpgTool application
« Reply #21 on: June 05, 2020, 05:22:47 AM »
Thanks Erol,

this looks good. I am up to my eyeballs in code at the moment but I will test it on different image formats soon as I need to be able to load JPG and PNG files from resources.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: