News:

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

Main Menu

BmpMem.asm

Started by Magnum, September 26, 2015, 08:15:38 AM

Previous topic - Next topic

Magnum

I am looking for BmpMem.asm.

I looked in the old forum but did not find it.

I need it to display a bmp that is embedded in the .exe.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

zedd151

from masm32.lib


;-------------------------------------------------------------------------------
;  BitmapFromMemory.ASM
;
;  Image file loading routines for the MASM32 library
;
;  This source and assosciated binary code is
;  Copyright © 2001 by M Stoller Enterprises
;
;  Written by Ernest Murphy
;
;  Not for commercial reproduction. No fee whatsoever may be imposed for
;  transfering this file. Source files may be coppied only for educational use
;  on a free basis.
;
;  Binary object files may be included in any work be it private, public or
;  a commercial application without payment necessary, however, it would be
;  appreciated to add a note to the effect "certain routines used in this program
;  were produced by Ernest Murphy" in the program documentation. Burried deep in
;  the help file is just fine.
;
;  There is no 'LZW' code contained in these routines.
;
;  Corrections have been made to this module by
;  f0dder, El_Choni, lamer, KetilO, QvasiModo and Vortex.
;
;-------------------------------------------------------------------------------

.486
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\comctl32.inc
include \masm32\include\ole32.inc
include \masm32\include\oleaut32.inc

.data
BitmapFromPicture PROTO   :DWORD

sIID_IPicture       TEXTEQU <{07BF80980H, 0BF32H, 0101AH,   \
                             {08BH, 0BBH, 000H, 0AAH, 000H, 030H, 00CH, 0ABH}}>
                             
IID_IPicture        GUID    sIID_IPicture

IPicture STRUCT
    ; IUnknown methods
    QueryInterface          DWORD   ?
    AddRef                  DWORD   ?
    Release                 DWORD   ?
    ; IPicture methods
    get_Handle              DWORD   ?
    get_hPal                DWORD   ?
    get_Type                DWORD   ?
    get_Width               DWORD   ?
    get_Height              DWORD   ?
    Render                  DWORD   ?
    set_hPal                DWORD   ?
    get_CurDC               DWORD   ?
    SelectPicture           DWORD   ?
    get_KeepOriginalFormat  DWORD   ?
    put_KeepOriginalFormat  DWORD   ?
    PictureChanged          DWORD   ?
    SaveAsFile              DWORD   ?
    get_Attributes          DWORD   ?
IPicture ENDS

HIMETRIC_INCH       EQU     2540

.code
;-------------------------------------------------------------------------------
align 4

_MemCopy proc public uses esi edi Source:PTR BYTE,Dest:PTR BYTE,ln:DWORD

    ; ---------------------------------------------------------
    ; Copy ln bytes of memory from Source buffer to Dest buffer
    ;      ~~                      ~~~~~~           ~~~~
    ; USAGE:
    ; invoke _MemCopy,ADDR Source,ADDR Dest,4096
    ;
    ; NOTE: Dest buffer must be at least as large as the source
    ;       buffer otherwise a page fault will be generated.
    ; ---------------------------------------------------------

    cld
    mov esi, [Source]
    mov edi, [Dest]
    mov ecx, [ln]

    shr ecx, 2
    rep movsd

    mov ecx, [ln]
    and ecx, 3
    rep movsb

    ret

_MemCopy endp

BitmapFromMemory  PROC  pMemory:DWORD, dwFileSize:DWORD

    LOCAL hResource:DWORD,  pGlobal:DWORD,      pStream:DWORD
    LOCAL hImage:DWORD,     pPicture:DWORD,     hBitmap:DWORD

   ;invoke CoInitialize, NULL
    mov pStream, NULL
    mov pPicture, NULL    ; NULL pointers for later use
    invoke CoTaskMemAlloc, dwFileSize   ; copy picture into task memory
    .if !eax
        ; oops! we didn't get the memory
        ; the last error code was set for us, and EAX is zero, so just return
        ret
    .endif
    mov pGlobal, eax
    invoke _MemCopy, pMemory, pGlobal, dwFileSize

    ; create a stream for the picture object's creator
    invoke CreateStreamOnHGlobal, pGlobal, TRUE, ADDR pStream
    or eax,eax
    jz @f
    invoke CoTaskMemFree,pGlobal
    xor eax,eax
    ret
   
@@:
    invoke OleLoadPicture, pStream, NULL, TRUE, ADDR IID_IPicture, ADDR pPicture
    or eax,eax
    jz @f
    mov eax, pStream
    call release_pStream
    xor eax,eax
    ret

@@:   
    ; now we are ready to get the hBipmap, we farm this out for reuseability
    invoke BitmapFromPicture, pPicture
    mov hBitmap, eax 

    mov eax, pStream
    call release_pStream

    mov eax, pPicture
    call release_pPicture

    mov eax, hBitmap                ; hBitmap is our return value, stuff it

    ret                             ; we're all done

BitmapFromMemory ENDP

; release the stream
release_pStream PROC
    push eax
    mov eax, [eax]
    call [eax].IPicture.Release   
    ret
release_pStream ENDP

; release the Picture object
release_pPicture PROC
    push eax
    mov eax, [eax]
    call [eax].IPicture.Release   
    ret
release_pPicture ENDP

END



is that what you need??

There is another one there to load bmp from resource as well

Magnum

Thanks.

I need the one for a resource.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

zedd151

Quote from: Magnum on September 26, 2015, 08:48:22 AM
Thanks.

I need the one for a resource.

It's in masm32.lib

;; by ernie murphy
;; see the file in masm32.lib for full notice
.486
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\comctl32.inc
include \masm32\include\ole32.inc
include \masm32\include\oleaut32.inc

.data

szImage             BYTE    "IMAGE", 0

.code
;-------------------------------------------------------------------------------
BitmapFromResource  PROC hModule: dword, ResNumber:DWORD
    LOCAL hResource:DWORD,  dwFileSize:DWORD, hImage:DWORD

    ; get a resource handle (address) and resource length from the executable
    invoke FindResource, hModule, ResNumber, ADDR szImage
    or eax,eax
    jnz @f
    invoke SetLastError, ERROR_FILE_NOT_FOUND
    xor eax,eax
    ret
@@:
    mov hResource, eax
    invoke LoadResource, hModule, eax
    invoke LockResource, eax
    mov hImage, eax
    invoke SizeofResource, hModule, hResource
    mov dwFileSize, eax
    .IF dwFileSize      ; we use the resource size to determine if we got a
                        ; legit image file to open
        invoke BitmapFromMemory, hImage, dwFileSize
    .ELSE
        invoke SetLastError, ERROR_FILE_NOT_FOUND
        xor eax,eax
    .ENDIF

    ; everything's been done for us now, just return
    ret                     ; we're all done

BitmapFromResource  ENDP   

Magnum

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

I also need bin2o to convert my bitmap to a resource.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

BMP's are easily added via resource file
but, if you prefer, it can be converted to a binary resource OBJ
i think Erol has such a tool on his page
i think Hutch has one in the masm32 package, too - fda.exe i guess

Vortex

Hi Magnum,

Attached are my bitmap from memory and bitmap from file examples. The BmpFromMem project uses the file data assembler ( \masm32\fda.exe ) to convert the bitmap to an object file.

TouEnMasm

#8
Here is one (see image_create_object.asm) who put BMP,gif,jpeg .. in memory.
Can be load from resource or files

http://masm32.com/board/index.php?topic=1917.msg19916#msg19916
Fa is a musical note to play with CL

dedndave

i wrote a routine a while back that was also nice for loading objects from resource
as i recall, i used it in the "group icon" demo program

for BMP's, that's all unneccessary
just put it in a rsrc.rc file and add it that way - very simple