int main(int, char*[])
{
const int xDimension = 200;
const int yDimension = 100;
typedef unsigned char ComponentType;
TraitsType;
RGBAConverterType;
RGBImageType::Pointer rgbImg = RGBImageType::New();
RGBAImageType::Pointer rgbaImg = RGBAImageType::New();
RGBAImageType::IndexType rgbaStart;
rgbaStart[0] = 0;
rgbaStart[1] = 0;
RGBAImageType::SizeType rgbaSize;
rgbaSize[0] = xDimension;
rgbaSize[1] = yDimension;
rgbaImg->SetRegions(rgbaRegion);
rgbaImg->Allocate();
RGBAPixelType rgbaDefault;
rgbaDefault[0] = 127;
rgbaDefault[1] = 100;
rgbaDefault[2] = 230;
rgbaDefault[3] = 255;
rgbaImg->FillBuffer(rgbaDefault);
rgbImg->SetRegions(rgbRegion);
rgbImg->Allocate();
size_t numberOfPixels =
RGBAConverterType::Convert(
rgbaImg->GetBufferPointer()->GetDataPointer(),
rgbaImg->GetNumberOfComponentsPerPixel(),
rgbImg->GetBufferPointer(),
numberOfPixels);
rgbIterator(rgbImg, rgbImg->GetLargestPossibleRegion());
rgbIterator.GoToBegin();
while(!rgbIterator.IsAtEnd())
{
if (rgbImg->GetPixel(rgbIterator.GetIndex())[0] !=
rgbaImg->GetPixel(rgbIterator.GetIndex())[0] ||
rgbImg->GetPixel(rgbIterator.GetIndex())[1] !=
rgbaImg->GetPixel(rgbIterator.GetIndex())[1] ||
rgbImg->GetPixel(rgbIterator.GetIndex())[2] !=
rgbaImg->GetPixel(rgbIterator.GetIndex())[2])
{
std::cout << "Copy failed for index " << rgbIterator.GetIndex()
<< " got " << rgbImg->GetPixel(rgbIterator.GetIndex())
<< " but expected " << rgbaImg->GetPixel(rgbIterator.GetIndex())
<< std::endl;
}
++rgbIterator;
}
return EXIT_SUCCESS;
}