Ejemplo n.º 1
0
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();
}