saving pngs with BaseBitmap Save
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/07/2011 at 07:35, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 12
Platform: Windows ;
Language(s) : C++ ;---------
I'm making a BitmapSaver plugin to save images along with metadata about the scene and it all works fine until alpha channels get involved. I'm just saving the png using the BaseBitmap class and I'm passing the savebits from the BitmapSaverData Save function. When I save an image with an alpha the BitmapSaverData Save function gets called twice, the first time writes a blank image, the second time writes and image with an A_ prefix but gives an "IMAGERESULT_WRONGTYPE" error.Here's my code such that it is minus all the metadata writing:
IMAGERESULT PNGMetaSaverData::Save(const Filename &name;, BaseBitmap *bm, BaseContainer *data, SAVEBIT savebits) { IMAGERESULT result; BaseBitmap *bmp = BaseBitmap::Alloc(); bmp = bm->GetClone();// cinema crashes if I don't use a clone result = bmp->Save(name,FILTER_PNG,data,savebits); BaseBitmap::Free(bmp); return result; }
I'm still very new to c++ and I'm learning as I go so it's quite possible I made a stupid c++ mistake.
- Carter
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 02/08/2011 at 10:01, xxxxxxxx wrote:
I finally got this working so I thought I'd post it in case anyone else ran into the issue. I'm still new to c++ so I apologize if there are any glaring bugs in this.
IMAGERESULT result; BaseBitmap *bmp = BaseBitmap::Alloc(); BaseBitmap *alpha; LONG bw,bh; UCHAR *line = NULL; bw=bm->GetBw(); bh=bm->GetBh(); bmp->Init(bw,bh); BaseContainer rdata = GetActiveDocument()->GetActiveRenderData()->GetData(); LONG x,y; if(savebits & SAVEBIT_ALPHA) { alpha = bmp->GetInternalChannel(); if(!alpha)alpha = bmp->AddChannel(TRUE,rdata.GetBool(RDATA_STRAIGHTALPHA)); // you have to copy the alpha over for(y=0; y<bh; y++) { for(x=0; x<bw; x++) { UWORD value = 0; bm->GetAlphaPixel(bm->GetChannelNum(0),x,y,&value;); bmp->SetAlphaPixel(alpha,x,y,value); } } }// end of alpha check // images with straight alpha require color conversion for some reason ColorProfileConvert* converter = ColorProfileConvert::Alloc(); converter->PrepareTransform(COLORMODE_RGB,ColorProfile::GetDefaultLinearRGB(),COLORMODE_RGB,ColorProfile::GetDefaultSRGB(),false); line = GeAllocType(UCHAR,3*bw); if (!line) { GeFree(line); return IMAGERESULT_OUTOFMEMORY; } // copy the image for (y=0; y<bh; y++) { bm->GetPixelCnt(0,y,bw,line,COLORBYTES_RGB,COLORMODE_RGB,PIXELCNT_0,converter); bmp->SetPixelCnt(0,y,bw,line,COLORBYTES_RGB,COLORMODE_RGB,PIXELCNT_0); } GeFree(line); ColorProfileConvert::Free(converter); result = bmp->Save(name,FILTER_PNG,data,savebits); BaseBitmap::Free(bmp); return result;