[V4MD] 32-bit picture fix
Martin Kloss
martin.kloss at gmx.de
Tue Jan 6 11:58:26 CST 2004
Hi all,
for those who are interested, here's some code to prevent V4MD
from messing up your 32-bit pictures when storing them in a picture field.
What's the problem:
--------------------------------------------
When storing 32-bit Director bitmap members in a Valentina picture
field, the JPEG-lib that V4MD uses somehow moves the first 1-pixel
column from the left to the right and then moves it 1-pixel down.
After retrieving the picture from the DB again, it looks pretty bad.
Apparently, this does not happen with 16-bit images.
The solution:
--------------------------------------------
If you just store your images once and then display them, you
can fix the image upon display, using Imaging Lingo:
-- get image
myImg = pMem.image.duplicate()
myWidth = myImg.width
myHeight = myImg.height
-- copy right 1-pixel column to the left side
srcRect = rect(myWidth-1, 0, myWidth, myHeight)
destRect = rect(-1, 0, 0, myHeight)
myImg.copyPixels(myImg, destRect, srcRect)
-- set image
pMem.image = myImg.crop(rect(-1, 0, myWidth-1, myHeight))
BUT you can also prepare the image before it gets stored in
the picture field, so that it will look right when retrieved. The
trick is simply to do the opposite of what V4MD does with
the picture, so that storing it in the picture field actually "repairs"
the picture, because we messed it up before so that the
"bug" actually gets reversed. Here's the code:
Let's assume you have a bitmap member reference stored
in "pictMember".
-- get image
myImg = pictMember.image.duplicate()
myWidth = myImg.width
myHeight = myImg.height
myNewImg = image(myWidth, myHeight, 32)
-- copy last pixel col to first pixel col
srcRect = rect(myWidth-1, 0, myWidth, myHeight)
destRect = rect(0, -1, 1, myHeight-1)
myNewImg.copyPixels(myImg, destRect, srcRect)
-- copy rest of image
srcRect = rect(0, 0, myWidth, myHeight)
destRect = rect(1, 0, myWidth, myHeight)
myNewImg.copyPixels(myImg, destRect, srcRect)
-- assign image
pictMember.image = myNewImg
So at first we copy the original image and create a new 32-bit
image with the same dimension. Then we copy the last pixel
column from the right to the first column on the left. Additionally,
the pixel columns needs to be shifted one pixel up, because V4MD
shifts the pixel one down. Finally, we copy the rest of the source
image and re-assign it to the member.
Now you can store the member using SetPicture() or SQL with
binded values and everything will stay as expected :-)
Important: if you're using the fix before you store the image,
you don't have to use the "display fix" mentioned before, because
otherwise you will mess up the now fixed picture. So use either
fix, but not both.
Martin.
Martin Kloss
Like the author? Buy the book:
http://www.amazon.de/exec/obidos/ASIN/3934358322/lingmmugd
Need music? http://www.selling-sound.com
Get your daily dose of Lingo: http://www.lingopark.de
More information about the Valentina
mailing list