I have loaded an image with this
Object * LoadInternalImage(STRPTR Render) { return(IIntuition->NewObject(BitMapClass,NULL, BITMAP_SourceFile, Render, BITMAP_Screen, DefaultPubScreen, BITMAP_Precision, PRECISION_EXACT, BITMAP_Masking, TRUE, TAG_DONE)); }
Now I am trying to make a copy of it to keep the original and do some modifying to the copy. Everything I have tried loses the alpha transparency and it shows up pink. The image body is fine.
Object * CopyImage(Object *SourceImg) { Object *Img; struct BitMap *SourceBM, *DestBM; uint32 Width, Height, Depth, PixelFormat; if (SourceImg==NULL) return(NULL); IIntuition->GetAttrs(SourceImg, BITMAP_BitMap, &SourceBM, TAG_DONE); Width=IGraphics->GetBitMapAttr(SourceBM,BMA_WIDTH); Height=IGraphics->GetBitMapAttr(SourceBM,BMA_HEIGHT); Depth=IGraphics->GetBitMapAttr(SourceBM,BMA_DEPTH); // Depth=IGraphics->GetBitMapAttr(SourceBM,BMA_BITSPERPIXEL); PixelFormat=IGraphics->GetBitMapAttr(SourceBM,BMA_PIXELFORMAT); // I am forcing it to this format. Either way has same result. if (!(DestBM=IGraphics->AllocBitMapTags(Width,Height,32,//Depth, BMATags_PixelFormat, PIXF_A8R8G8B8,//PixelFormat, BMATags_Clear, TRUE, BMATags_Displayable, TRUE, TAG_DONE))) { return(NULL); } // I have tried every combination, plus others. if (IGraphics->CompositeTags( COMPOSITE_Src, SourceBM, DestBM, // COMPOSITE_Src_Over_Dest, SourceBM, DestBM, // COMPTAG_Flags, COMPFLAG_IgnoreDestAlpha, // COMPTAG_Flags, COMPFLAG_SrcAlphaOverride | COMPFLAG_IgnoreDestAlpha, // COMPTAG_Flags, COMPFLAG_SrcAlphaOverride, TAG_DONE) != COMPERR_Success) { IGraphics->FreeBitMap(DestBM); return(NULL); } if (!(Img=IIntuition->NewObject(BitMapClass,NULL, BITMAP_BitMap, DestBM, BITMAP_Width, Width, BITMAP_Height, Height, BITMAP_HasAlpha, TRUE, BITMAP_Screen, DefaultPubScreen, BITMAP_Precision, PRECISION_EXACT, BITMAP_Masking, TRUE, TAG_DONE))) { IGraphics->FreeBitMap(DestBM); return(NULL); } return(Img); }
What is happening to the transparency? The original image displays just fine, the copy does not (pink).
The problem is the probably Composite call. CompoisteTags does a composite operation not a copy. Thus the alpha channel is not preserved, rather it's used to control the composite. A few people have been caught out by this.
It's not obvious to me what specific change you are trying to make with the Composite operation?
That's the weird thing: CompositeTags() does "save" the alpha channel when loaded from a datatype. I use it a lot in my program. I load a BitMapClass with BITMAP_Render,"path", and such; AllocBitMapTags() a new bitmap; lock it and IDoMethod() pdtBlitPixelArrayBuffer to it, unlock it; AllocBitMapTags() another bitmap (destination); CompositeTags() with a scale down; create BitMapClass with destination bitmap and all it good.
I have tried with a mix and match of these tags with no luck, or worse results:
But above I have already loaded the image to a BitMapClass and am copying the BITMAP_BitMap from it and the transparency gets lost; end up violet.
I am using CompositeTags() because I may need to scale it, so just have it ready to go (currently just copying it). I also tried to use BltBitMapTags() but has the same result: alpha is violet.
So I would say it has something to do with the way GetAttrs() BITMAP_BitMap is getting the data, losing the alpha data along the way. ??????
BLITA_UseSrcAlpha, TRUE,
will alpha blend the src with the destination, that *will* lose the alpha component of the src, you want a straight copy with no blending.
But I have to say your approach is wrong. bitmap.image is not for loading images but displaying them (naturally it supports loading too, as a convenience).
If you want to load an image them modify it, use the datatype directly, then extact the 32bit bitmap, modify as required and create your new bitmap.image from it.
I hear what you are saying about using datatypes to load the image, will try that later. For now, I I found another way to do what I need. I still need/want to get the copy to work, not giving up on it.
I used the "traditional" method of loading the image with datatypes and BltBitMapTags(), got success.
Just out of interest, did you also try copying the bitmap by grabbing a pointer to it and passing that along with BITMAP_BitMap as the source instead? Thus avoiding all the duplicating you were doing. If that could work.