The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: dedndave on April 24, 2012, 12:49:34 AM

Title: Zoom StretchBlt Darker Lighter Image
Post by: dedndave on April 24, 2012, 12:49:34 AM
when you reduce an image, it becomes darker and sharper
when you enlarge an image, it becomes lighter and softer

i am using StretchBlt to zoom the image
is there a simpe way to overcome this problem without totally processing the image with each zoom step ?

i thought, maybe, there was some flag to select
or, maybe, someone has dealt with this, before

at the moment, i am using
        INVOKE  SetStretchBltMode,eax,HALFTONE
;
;
;
        INVOKE  StretchBlt,...................,SRCCOPY


i am going from 5:1 to 1:5
the problem is not too bad when enlarging, but the image deteriorates rapidly when reducing
i can limit that range to ease the problem, but a better solution would be nice   :U
Title: Re: Zoom StretchBlt Darker Lighter Image
Post by: donkey on April 24, 2012, 01:19:26 AM
Hi Dave,

When reducing the image try COLORONCOLOR instead of HALFTONE, I use HALFTONE for enlarging and COLORONCOLOR for reducing, it seems to work for me. Also make sure you set the brush origin when using HALFTONE.

invoke SetStretchBltMode,[mdc1],HALFTONE
invoke SetBrushOrgEx,[mdc1],0,0,offset pt

invoke SelectObject,[mdc1],[hbmp]
mov [hbmp],eax

invoke SelectObject,[mdc2],[id3info.APIC]
mov [id3info.APIC],eax

invoke StretchBlt,[mdc1],0,0,[rect.right],[rect.bottom],[mdc2],0,0,[bmp.bmWidth],[bmp.bmHeight],SRCCOPY


Edgar
Title: Re: Zoom StretchBlt Darker Lighter Image
Post by: dedndave on April 24, 2012, 01:51:54 AM
Thanks, Edgar   :U

i had tried COLORONCOLOR, but it had little effect - at least, on my display system
i was not aware of the brush alignment thing, though   :P

a little digging, and i found the SetColorAdjustment function...
http://msdn.microsoft.com/en-us/library/dd162968%28v=vs.85%29.aspx

it sounds promising - although, i may have to learn more than i wanted to to use it - lol
ah well - you only have to learn it once... or twice
i have a little familiarity from playing with image enhancement, in the past
so - it might not be too bad
Title: Re: Zoom StretchBlt Darker Lighter Image
Post by: dedndave on April 24, 2012, 03:07:28 AM
doing a little reading on the subject...
http://www.4p8.com/eric.brasseur/gamma.html

Eric had an interesting test image i thought you might like   :P

(http://www.4p8.com/eric.brasseur/gamma-1.0-or-2.2.png)
Title: Re: Zoom StretchBlt Darker Lighter Image
Post by: dedndave on April 24, 2012, 03:22:27 AM
i sucks...

(http://www.masm32.com/board/index.php?action=dlattach;topic=18750.0;id=10624)
Title: Re: Zoom StretchBlt Darker Lighter Image
Post by: donkey on April 24, 2012, 05:19:08 AM
Hi Dave,

I tried GDI plus to get better scaling. The results are slightly better than with the GDI though still not great and I only tested it on a single size, for what its worth here's the picturebox subclass, you can try to play around with it if you like:

invoke GdipLoadImageFromFile,L"gamma-1.0-or-2.2.png",offset pPic1

StaticProc1 FRAME hwnd, uMsg, wParam, lParam, uIdSubclass, dwRefData
LOCAL ps:PAINTSTRUCT
LOCAL rect:RECT
LOCAL pGraphics:%PTR

.WM_PAINT
cmp D[uMsg],WM_PAINT
jne >>.DEFPROC
invoke BeginPaint,[hwnd],offset ps
invoke GetClientRect,[hwnd],offset rect
invoke GdipCreateFromHDC,[ps.hdc], offset pGraphics
invoke GdipSetPixelOffsetMode,[pGraphics],PixelOffsetModeDefault
invoke GdipSetInterpolationMode,[pGraphics],InterpolationModeHighQuality
invoke GdipDrawImageRectI,[pGraphics],[pPic1],0,0,[rect.right], [rect.bottom]
invoke GdipDeleteGraphics, [pGraphics]
invoke EndPaint,[hwnd],offset ps
xor eax,eax
ret

.DEFPROC
invoke DefSubclassProc, [hwnd], [uMsg], [wParam], [lParam]
RET
ENDF


Note that I use SetWindowSubclass to subclass windows, if you need to be compatible with Windows prior to XP define the CCUSEORDINALS switch in GoAsm and it will be available for all versions back to Win98.

Edgar
Title: Re: Zoom StretchBlt Darker Lighter Image
Post by: dedndave on April 24, 2012, 11:02:49 AM
thanks again, Edgar
i wonder if the SetWorldTransform function would help
a lot of stuff to try, i guess
i will play with some of it today

Title: Re: Zoom StretchBlt Darker Lighter Image
Post by: dedndave on April 25, 2012, 03:24:27 AM
grrrrr - lol

all i did was get it double-buffered so i could play with it, and it fixed itself

previous code, 1:5 reduction

(http://www.masm32.com/board/index.php?action=dlattach;topic=18750.0;id=10626)

current code, 1:5 reduction

(http://www.masm32.com/board/index.php?action=dlattach;topic=18750.0;id=10627)

image at 1:1, for comparison

(http://www.masm32.com/board/index.php?action=dlattach;topic=18750.0;id=10628)

i must have been doing something wrong
now, i have to try and figure it out, so i know what not to do   :P
Title: Re: Zoom StretchBlt Darker Lighter Image
Post by: dedndave on April 25, 2012, 02:09:32 PM
my current test code looks like this
        INVOKE  BeginPaint,hWnd,addr ps

invoke CreateCompatibleDC,ps.hdc
mov    hdcMem1,eax
invoke SelectObject,hdcMem1,hBitmap
mov    hbmpPrev1,eax
invoke CreateCompatibleDC,ps.hdc
mov    hdcMem2,eax

invoke CreateSolidBrush,757A6Bh
mov    hbrMem2,eax
invoke SetBkMode,hdcMem2,OPAQUE
invoke SelectObject,hdcMem2,hbrMem2         ;not doing what i want :-)
mov    hbrPrev2,eax

invoke CreateCompatibleBitmap,ps.hdc,200,200
mov    hbmpMem2,eax
invoke SelectObject,hdcMem2,hbmpMem2
mov    hbmpPrev2,eax
invoke SetStretchBltMode,hdcMem2,COLORONCOLOR
invoke StretchBlt,hdcMem2,50,50,100,100,hdcMem1,0,0,500,500,SRCCOPY
invoke BitBlt,ps.hdc,0,0,200,200,hdcMem2,0,0,SRCCOPY
invoke SelectObject,hdcMem2,hbmpPrev2
invoke DeleteObject,hbmpMem2
invoke SelectObject,hdcMem2,hbrPrev2
invoke DeleteObject,hbrMem2
invoke DeleteDC,hdcMem2
invoke SelectObject,hdcMem1,hbmpPrev1
invoke DeleteDC,hdcMem1

        INVOKE  EndPaint,hWnd,addr ps
        xor     eax,eax
        ret


the problem i am having now should be an easy one for you more experienced programmers   :P
i am trying to set the background color that surrounds the reduced bitmap
any help ???

(http://www.masm32.com/board/index.php?action=dlattach;topic=18750.0;id=10631)
Title: Re: Zoom StretchBlt Darker Lighter Image
Post by: dedndave on April 25, 2012, 02:47:49 PM
i changed the order to this, which seems to make more sense

        INVOKE  BeginPaint,hWnd,addr ps

invoke CreateCompatibleDC,ps.hdc
mov    hdcMem1,eax
invoke SelectObject,hdcMem1,hBitmap
mov    hbmpPrev1,eax
invoke CreateCompatibleDC,ps.hdc
mov    hdcMem2,eax
invoke CreateCompatibleBitmap,ps.hdc,200,200
mov    hbmpMem2,eax
invoke SelectObject,hdcMem2,hbmpMem2
mov    hbmpPrev2,eax

invoke CreateSolidBrush,757A6Bh
mov    hbrMem2,eax
invoke SetBkMode,hdcMem2,OPAQUE
invoke SelectObject,hdcMem2,hbrMem2
mov    hbrPrev2,eax

invoke SetStretchBltMode,hdcMem2,COLORONCOLOR
invoke StretchBlt,hdcMem2,50,50,100,100,hdcMem1,0,0,500,500,SRCCOPY
invoke BitBlt,ps.hdc,0,0,200,200,hdcMem2,0,0,SRCCOPY

invoke SelectObject,hdcMem2,hbrPrev2
invoke DeleteObject,hbrMem2
invoke SelectObject,hdcMem2,hbmpPrev2
invoke DeleteObject,hbmpMem2
invoke DeleteDC,hdcMem2
invoke SelectObject,hdcMem1,hbmpPrev1
invoke DeleteDC,hdcMem1

        INVOKE  EndPaint,hWnd,addr ps
        xor     eax,eax
        ret


still get black, though   :'(
Title: Re: Zoom StretchBlt Darker Lighter Image
Post by: dedndave on April 25, 2012, 03:04:29 PM
PatBlt works   :U
Title: Re: Zoom StretchBlt Darker Lighter Image
Post by: dedndave on May 04, 2012, 11:48:58 PM
thanks for your help, Edgar   :U

(http://www.masm32.com/board/index.php?action=dlattach;topic=18750.0;id=10703)