void PTRecolorAction::DoIt() { if ( mTable ) { SUOffscreen *currentBuffer = mSettings.currentBuffer; mSettings.thePaintView->CopyToUndo(); mSettings.thePaintView->SelectNone(); /* create a new buffer the same size as the image but with a depth of 8-bits. use the specified color table as the color table. */ SInt32 width = currentBuffer->GetWidth(); SInt32 height = currentBuffer->GetHeight(); SUOffscreen *newBuffer = SUOffscreen::CreateBuffer( width, height, kRecolorDepth, mTable ); /* increase the inverse table size from 4 to 5 bits. this gives substantially better color matching. */ newBuffer->IncreaseInverseTableSize(); /* Copy the image to the 8-bit buffer to downsample the colors and then back to the original 32-bit one */ newBuffer->CopyFrom( currentBuffer ); currentBuffer->CopyFrom( newBuffer ); delete newBuffer; // update the canvas mSettings.theCanvas->DrawFrom( currentBuffer ); } this->PostAsAction(); }
/*=============================================== InitializeFromResource ================================================*/ void PTPatternView::InitializeFromResource( RFMap *inMap, ResType inResType, ResIDT inResID ) { StSaveGWorld aSaver; StSaveResFile aSaver2; SUOffscreen *colorImage = nil, *bwImage = nil; Handle h = nil; try { mResourceType = inResType; /************************************************** get the raw resource handle **************************************************/ RFResource *theRes = inMap->FindResource( inResType, inResID, false ); ThrowIfNil_( theRes ); h = theRes->GetResData(); ThrowIfNil_( h ); /************************************************** draw the pattern(s) into bitmaps **************************************************/ switch( inResType ) { case ImageType_PixPat: this->ParseColorPattern( h, &colorImage, &bwImage ); mAllowImageResizing = true; break; case ImageType_Pattern: this->ParseBWPattern( h, &bwImage ); break; default: LException::Throw( err_UnknownDataType ); } /************************************************** resize the sample well if the color pattern is bigger than 8x8 **************************************************/ if ( colorImage ) { SInt32 width = colorImage->GetWidth(); SInt32 height = colorImage->GetHeight(); // save these _now_ because SetImage() will trigger a call to // GetZoomFactor() mPixPatWidth = width; mPixPatHeight = height; this->ResizeSampleWell( width, height ); this->SetImage( colorImage, PTResize_All, redraw_Later ); mColorSample->SetBuffer( colorImage, redraw_Dont ); colorImage = nil; // because it belongs to the sample pane now mColorSample->SetTarget( true, redraw_Dont ); mCurrentSamplePane = mColorSample; } else { this->SetImage( bwImage, PTResize_All, redraw_Later ); mCurrentSamplePane = mBWSample; mBWSample->SetTarget( true, redraw_Dont ); } mBWSample->SetBuffer( bwImage, redraw_Dont ); bwImage = nil; // because it belongs to the sample pane now } catch( ... ) { delete( colorImage ); delete( bwImage ); SUMiscUtils::DisposeHandle( h ); throw; } SUMiscUtils::DisposeHandle( h ); }