News:

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

Main Menu

24 bits reading

Started by gelatine1, January 18, 2015, 05:59:56 AM

Previous topic - Next topic

gelatine1

unfortunately im reading a file (bmp image file) which has its data packed in 3 bytes. So my question is how should I read this ? I have the file mapped into my memory so I have a pointer to it but I can't use dword ptr [esi] or word ptr [esi] or anything similar right ?

dedndave

you can, if ESI is set to the pointer   :P

gelatine1

I don't really get what you mean ?  :icon_confused:

dedndave

Quote from: gelatine1 on January 18, 2015, 05:59:56 AM
I have the file mapped into my memory so I have a pointer to it but I can't use...

you say you have the pointer - let's say it's lpView
    mov     esi,lpView
now, you can use ESI   :biggrin:

truthfully, though.....
BMP images are never so large that file mapping is needed
you can probably fit the entire file in memory at once

you could use HeapAlloc to allocate a large block of memory, then read it in
or, you could use LoadImage and set the LR_CREATEDIBSECTION flag

a DIB section is a bitmap with a pointer and direct access to the image data bits

after using LoadImage to create a DIB section,
use GetObject to fill a DIBSECTION structure to get the data pointer

http://msdn.microsoft.com/en-us/library/windows/desktop/ms648045%28v=vs.85%29.aspx

http://msdn.microsoft.com/en-us/library/dd144904%28v=vs.85%29.aspx

http://msdn.microsoft.com/en-us/library/dd183567%28v=vs.85%29.aspx

gelatine1

Well wait I think I asked my question in a wrong way. So I guess I'll rephrase my question. I meant to ask if there is some kind of way to subtract 3 bytes from memory and move it to a 4 byte register. Something that would look like movzx eax,word ptr [esi] to subtract 2 bytes from memory and get it in a 4 bytes register.

I guess I'll take a look a look into the functions you gave me there. thank you

KeepingRealBusy

You just set a pointer to the lowest byte, then move a dword to a register and mask out the most significant byte and advance the pointer by the 3 bytes you already have

Dave.

dedndave

right - as Dave mentioned...
    mov     eax,[esi]
    and     eax,0FFFFFFh


the address in ESI is calculated, based on the location of the desired pixel
image base address + ( line number * bytes per line) + ( 3 * column number)
notice that most BMP images are upside-down (top image line is last in file)
the sign of the height value in the header tells you if it is right-side up   :P

bytes per line is always some multiple of 4
so, if you have a 24-bit image that is 3 pixels wide, the bytes per line will be 12

Tedd

@@:
mov eax,[esi]       ;get 4 bytes
and eax,00ffffffh   ;mask out the top one, leaving the 3 bytes you want
...                 ;do stuff
add esi,3           ;move to the next 3 bytes
jmp @B              ;repeat..
Potato2