Hi,
This my little MASM32 dll, that resizes a Picture smoothly. Im using it from out VB. In my litte TestApplication I'm creating a DIB-Collection from an Image and than Pass the Properties of the Source and Destination Image to my ASM-DLL.
It took me a while... But it works now. This is just for scaling a picture to a smaller size. It works with scaling it bigger, but without Interpolation.
I did the same thing in VB before... But compared to ASM it's of course real slow!

If there was anybody who wants to test it or performing the whole thing I would be glad. - The comments are all German... I'm sorry!

(Oh, If you want to use the testApplication you need to copy ma dll into the winnt or windows Directory... Or correct the Path in VB directly. - you need the vb-Runtimelibrarys)
Posted on 2001-10-19 03:57:12 by Butch77
Bi Butch77

Works like a charm, except when down sizeing the window.
Btw, is'nt there api calls that does this well?

KetilO
Posted on 2001-10-19 05:01:05 by KetilO
The down sizeing problem is some kind of an event-bug... I don't get any PaintEvent when down sizeing the window. But only on my win 2000 Server installation. Not on the win 2000 Professional.... whatever.

I haven't found any API call, that does it smoothy (the AverageCalculationThing) Resizing, but if you find any please let me know. So that I can see which one is faster. :)
Posted on 2001-10-19 06:14:19 by Butch77
Hi,
API "StretchDIBits" does it.
Here is a Subroutine.
We must also create a device context on WM_Create.
On WM_Paint we display the bitmap via BitBlt.




My_LoadBitmap:
;------------------------------------------------------------------------------
; API "GetOpenFileName" creates a system-defined dialog box that enables the
; user to select a file to open.
;------------------------------------------------------------------------------
mov lStructSize,4Ch ;length in bytes of structure
mov eax,WP1_hWnd
mov hWndOwner,eax ;id window that owns dialog box
mov eax,hInstance
mov hInstance1,eax ;handle, our program id
mov lpstrFilter,OFFSET FileFilterBMP ;pointer to string + filter, 0= no
mov lpstrCustomFilter,0h ;pointer to user defined filter
mov nMaxCustFilter,0h ;size bytes/characters of above
mov nFilterIndex,0h ;filter index of lpstrFilter
mov lpstrFile,OFFSET FileNameBuffer ;pointer initialize filename, 0=no
mov nMaxFile,104h ;max size bytes/characters of above
mov lpstrFileTitle,0h ;pointer title of the selected file
mov nMaxFileTitle,0h ;size of the lpstrFileTitle buffer
mov lpstrInitialDir,0h ;pointer init file dir,0=default
mov lpstrTitle,OFFSET LoadFileTitelBMP ;pointer title of the box
mov Flags,00281804h ;the dialog box creation flags
mov nFileOffset,0h ;offset filename in string lpstrFile
mov nFileExtension,0h ;offset extension in string lpstrFile
mov lCustData,0h ;?
mov lpfnHook,0h ;? used if flag is OFN_ENABLETEMPLATE
mov lpTemplateName,0h ;? used if flag is OFN_ENABLETEMPLATE
mov lpstrDefExt,OFFSET FileDefExtBMP ;pointer default extension file, 0=no
push OFFSET lStructSize ;pointer to OPENFILENAME Structure
call GetOpenFileNameA ;- API Function -
cmp eax,0h ;
je My_LoadBitmap_Return ;Error
;------------------------------------------------------------------------------
; API "CreateFileA" creates or opens a file, it returns a handle.
;------------------------------------------------------------------------------
push 0h ;hTemplateFile,
push 80h ;dwFlagsAndAttributes, 80h = normal
push 3h ;dwCreationDistribution, OPEN_EXISTING
push 0h ;lpSecurityAttributes,
push 1h ;dwShareMode, FILE_SHARE_READ
push 80000000h ;dwDesiredAccess, GENERIC_READ
push OFFSET FileNameBuffer ;lpFileName,pointer to filename
call CreateFileA ;- API Function -
cmp eax,-1 ;
je My_LoadBitmap_Return ;Error
mov handleFile,eax ;store handle in variable
;------------------------------------------------------------------------------
; API "GetFileSize" retrieves the size, in bytes, of the specified file.
;------------------------------------------------------------------------------
push 0h ;lpFileSizeHigh, highword file size
push handleFile ;hFile, handle of file to get size of
call GetFileSize ;- API Function -
cmp eax,-1 ;
je My_LoadBitmap_Return ;Error
mov totalBytesFile,eax ;store size in variable
;------------------------------------------------------------------------------
; API "GlobalAlloc" allocates the specified number of bytes
;------------------------------------------------------------------------------
push totalBytesFile ;dwBytes, number of bytes to allocate
push 0h ;uFlags, alloc attributes 0=GMEM_FIXED
call GlobalAlloc ;- API Function -
cmp eax,0h ;
je My_LoadBitmap_Return ;Error
mov pGlobalMemFile,eax ;store memory pointer in variable
;------------------------------------------------------------------------------
; API "ReadFile" reads data from a file, starting at the position file pointer
;------------------------------------------------------------------------------
push 0h ;lpOverlapped,address data structure
push OFFSET FileBytesReturn ;lpNumberOfBytesRead, readed bytes
push totalBytesFile ;nNumberOfBytesToRead, bytes to read
push pGlobalMemFile ;lpBuffer, address buffer receives data
push handleFile ;hFile, handle of file to read
call ReadFile ;- API Function -
cmp eax,0h ;
je My_LoadBitmap_Return ;Error
;------------------------------------------------------------------------------
; Calculate the pointer to the BITMAPINFO structure and to the bitmap data.
; Also receive the biHeight and biWidth values for future use.
;------------------------------------------------------------------------------
mov eax,pGlobalMemFile ;first byte in global memory
add eax,14 ;calculate pointer to BITMAPINFOHEADER
mov pointerBMI,eax ;
mov eax,pGlobalMemFile ;first byte in global memory
mov ebx,pGlobalMemFile ;first byte in global memory
add ebx,10 ;offset to bitmap data
add eax,[ebx] ;calculate pointer to bitmap data
mov pointerDAT,eax ;
mov eax,pGlobalMemFile ;pointer to global memory
add eax,18 ;member biWidth of BITMAPINFO
mov ebx,[eax] ;
mov widthBMP,ebx ;
add eax,4h ;member biHeight of BITMAPINFO
mov ebx,[eax] ;
mov heightBMP,ebx ;
;------------------------------------------------------------------------------
; API "SetStretchBltMode" sets the bitmap stretching mode in the specified DC.
;------------------------------------------------------------------------------
push 3h ;iStretchMode, COLORONCOLOR
push h_DC_Memory ;hdc, handle of device context
call SetStretchBltMode ;- API Function -
;------------------------------------------------------------------------------
; API "SetMapMode" sets the mapping mode of the specified device context. The
; mapping mode defines the unit of measure used to transform page-space units
; into device-space units and the orientation of the device's x and y axes.
;------------------------------------------------------------------------------
push 1h ;fnMapMode, mapping mode, MM_TEXT
push h_DC_Memory ;hdc, handle of device context
call SetMapMode ;- API Function -
;------------------------------------------------------------------------------
; API "StretchDIBits" copies the color data for a rectangle of pixels in a
; device-independent bitmap (DIB) to the specified destination rectangle.
; If the destination rectangle is larger than the source rectangle, this API
; stretches the rows and columns of color data to fit the destination rectangle
; If the destination rectangle is smaller than the source rectangle, this API
; compresses the rows and columns by using the specified raster operation.
;------------------------------------------------------------------------------
push 0CC0020h ;dwRop, raster operation code
push 0h ;iUsage, DIB_RGB_COLORS
push pointerBMI ;lpBitsInfo, address of bitmap data
push pointerDAT ;lpBits, address of bitmap bits
push heightBMP ;nSrcHeight, height of src rectangle
push widthBMP ;nSrcWidth, width of source rectangle
push 0h ;YSrc, y=src. rect. up-left
push 0h ;XSrc, x=src. rect. up-left
push Ypos_max ;nDestHeight, height dest. rectangle
push Xpos_max ;nDestWidth, width dest. rectangle
push 0h ;YDest, y=dest. rect. up-left
push 0h ;XDest, x=dest. rect. up-left
push h_DC_Memory ;hdc, handle of destination DC
call StretchDIBits ;- API Function -
;------------------------------------------------------------------------------
; API "GlobalFree" frees the global memory object and invalidates its handle.
;------------------------------------------------------------------------------
push pGlobalMemFile ;hMem, handle to global memory object
call GlobalFree ;- API Function -
;------------------------------------------------------------------------------
; API "InvalidateRect" adds a rectangle to specified window's update region.
; This function performs a WM_PAINT message.
;------------------------------------------------------------------------------
push 0h ;bErase, erase-background flag
push 0h ;lpRect, rect structure, 0h=client area
push WP1_hWnd ;hWnd, handle window update region
call InvalidateRect ;- API Function -
My_LoadBitmap_Return:
;------------------------------------------------------------------------------
; API "CloseHandle" closes an open object handle.
;------------------------------------------------------------------------------
push handleFile ;hObject, handle of object to close
call CloseHandle ;- API Function -
ret



TD
Posted on 2001-10-20 02:48:29 by Test Department