On 26/08/2014 at 04:45, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R14
Platform: Windows ;
Language(s) : C++ ;
---------
Hi folks,
I've been running some experiments with bitmaps and have come across some odd behaviour during a custom 'copy-pixel' loop. The following is for all intents and purposes a full function that is called via a button command press:
// Note: the MyStruct.Str_Bitmap used in the loop is
// valid and does display in the picture viewer
BaseBitmap *Copied_BMP = BaseBitmap::Alloc();
BaseBitmap *Alpha = NULL;
Alpha = Copied_BMP->GetInternalChannel();
Alpha = Copied_BMP->AddChannel(TRUE,TRUE);
Copied_BMP->Init(100,100,32,INITBITMAPFLAGS_0);
LONG rr,gg,bb,aa;
UWORD Ru,Gu,Bu,Au;
for(int h = 0; h <= Copied_BMP->GetBh()-1;)
{
for(int w = 0; w <= Copied_BMP->GetBw()-1;)
{
MyStruct.Str_Bitmap->GetPixel(w,h,&Ru;,&Gu;,&Bu;);
MyStruct.Str_Bitmap->GetAlphaPixel(MyStruct.Str_Bitmap_Alpha,w,h,&Au;);
if(h == 23 && w == 14)
{
GePrint("In-loop 14x23 alpha pixel = " + LongToString(Au)); // correct
}
rr = Ru;
gg = Gu;
bb = Bu;
aa = Au;
if(h == 23 && w == 14)
{
GePrint("In-loop 14x23 alpha pixel = " + LongToString(aa)); // correct
}
Copied_BMP->SetPixel(w,h,rr,gg,bb);
Copied_BMP->SetAlphaPixel(Alpha,w,h,aa);
if(h == 22 && w == 13) // previous pixel test
{
Copied_BMP->GetAlphaPixel(Alpha,12,21,&Au;);
aa = Au;
GePrint("Post-set: 12x21 alpha LONG = " + LongToString(aa)); // wrong
GePrint("Post-set: 12x21 alpha UWORD = " + LongToString(Au)); // wrong
}
else if(h == 23 && w == 14)
{
Copied_BMP->GetAlphaPixel(Alpha,14,23,&Au;);
aa = Au;
GePrint("Post-set: 14x23 alpha LONG = " + LongToString(aa)); // correct
GePrint("Post-set: 14x23 alpha UWORD = " + LongToString(Au)); // correct
}
else if(h == 26 && w == 4)
{
Copied_BMP->GetAlphaPixel(Alpha,4,26,&Au;);
aa = Au;
GePrint("Post-set: 4x26 alpha LONG = " + LongToString(aa)); // correct
GePrint("Post-set: 4x26 alpha UWORD = " + LongToString(Au)); // correct
}
w++;
}
h++;
}
// Now test pixel value at 14x23 again
Copied_BMP->GetAlphaPixel(Alpha,14,23,&Au;);
aa = Au;
GePrint("Post-loop: 14x23 alpha LONG = " + LongToString(aa)); // wrong
GePrint("Post-loop: 14x23 alpha UWORD = " + LongToString(Au)); // wrong
//... I hope the above is all correct, from here the
// code is mainly changing some pixel colours and
// freeing bitmaps etc.
The issue is that the printed values after the for loop are all null, but the printed values inside the loop are correct (once the alpha value is set). The only time one of the prints in the loop doesn't print correct values is when trying to print a previous pixels value (so if h=10 and w=10, printing h=9 and w=9 values are also null). It's like the alpha data is erased as soon as the loops' skopes are left.
I've tested the above in both a dialog and object plugin, and both are running into the same problem. Sending either pictures to the picture viewer also seems to ignore the alpha data (including the original image!), but the colour data in both seems fine. Images are all in 32-bit form.
Is anyone with a beady eye able to spot what I'm doing wrong here? Or has anyone else come across this behaviour before?
WP.
P.s. just for note's sake, I'm aware of the bitmap->CopyTo() and bitmap->SetPixelCnt(), but I can't use these in the above because the routine will be expanded on and the operation will need to be on a per-pixel basis.