----- Original Message ----- 
From: "Glenn B. Lawler" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, May 25, 2005 5:27 PM
Subject: [list] RE: [delphi-en] Resample a TBitmap


> How do you "average" the pixels in the source rectangle? I have never
> had to deal with that since all the library scaling routines I have 
> written
> are for black and white images. I am sure others on the list have some
> ideas for us.

For 24bit RGB pixels you might try doing the 3 primaries (Red Green Blue) 
seperately, which should (mostly) provide reasonable results.

E.g. suppose we're reducing a 4x4 grid to 3x3, with Red pixels on a white 
background:

W,W,W,W
W,W,R, R
W,W,R, R

In primary terms, this is:

(255,255,255), (255,255, 255), (255, 255, 255), (255,255,255)
(255,255,255), (255,255, 255), (255,0,0), (255,0,0)
(255,255,255), (255,255, 255), (255,0,0), (255,0,0)

Thus for red the the averages are (first component from each tuple):
255, 255, 255
255, 255, 255
255, 255, 255

For blue and green both the result is (assuming we average pixel 2 and 3):
255, 255, 255
255, 128, 128
255, 128, 0

Thus, the combined result is:
(255,255,255), (255,255, 255), (255,255,255)
(255,255,255), (255,128,128), (255,128,128)
(255,255,255), (255,128, 128), (255,0,0)

The interpolated pixels will show up as greyish/redish (the interpolated 
value between red and black).  Which pixelse you choose to interpolate in 
this wat will dependend on the exact calculation to use to determine the 
size of the rectangle of pixels you're looking at as you step over the new 
image you're generating.  For simplicity I've obviously only interpolated 
the boundary above, to illustrate the concept.

15/16 bit colour values may be handled similarly (15 bit uses 5 bits per 
primary, and 16 bit 5/5/6 or some variant thereof)  For 256 bit or fewer 
(palettized) colour you will have to firstly find the primary components for 
each palette colour, then do the interpolation, then find the closest colour 
in your palette to the result....

Cheers

Walter 



-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to