本文整理汇总了C++中CImage::GetData方法的典型用法代码示例。如果您正苦于以下问题:C++ CImage::GetData方法的具体用法?C++ CImage::GetData怎么用?C++ CImage::GetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CImage
的用法示例。
在下文中一共展示了CImage::GetData方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteImage
//
// WriteImage()
// write an image to a file in PNG format
// This version writes only a subpart of the image
//
void CImageIOPng::WriteImage(const CImage& image, CNcbiOstream& ostr,
size_t x, size_t y, size_t w, size_t h,
CImageIO::ECompress compress)
{
// make sure we've got an image
if ( !image.GetData() ) {
NCBI_THROW(CImageException, eWriteError,
"CImageIOPng::WriteImage(): "
"attempt to write an empty image");
}
// validate our image - we need RGB or RGBA images
if (image.GetDepth() != 3 && image.GetDepth() != 4) {
string msg("CImageIOPng::WriteImage(): invalid image depth: ");
msg += NStr::NumericToString(image.GetDepth());
NCBI_THROW(CImageException, eWriteError, msg);
}
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
try {
// initialize png stuff
s_PngWriteInit(png_ptr, info_ptr,
w, h, image.GetDepth(),
compress);
// begin writing data
png_set_write_fn(png_ptr, &ostr, s_PngWrite, s_PngFlush);
png_write_info(png_ptr, info_ptr);
// write our image
// we plan to march through only part of our image
// get a pointer to the start of our scan line
//
// NB: the const cast is necessary as png_write_row takes a non-const
// pointer (go figure...)
unsigned char* from_data = const_cast<unsigned char*>(image.GetData());
from_data += (y * image.GetWidth() + x) * image.GetDepth();
size_t from_stride = w * image.GetDepth();
// march out h scan lines
for (size_t i = 0; i < h; ++i) {
png_write_row(png_ptr, from_data);
from_data += from_stride;
}
// standard clean-up
png_write_end(png_ptr, info_ptr);
s_PngWriteFinalize(png_ptr, info_ptr);
}
catch (...) {
s_PngWriteFinalize(png_ptr, info_ptr);
throw;
}
}
示例2: TestImageModifierStack
void TestImageModifierStack(void)
{
BeginTests();
CImage cImage;
CImageModifierStack cStack;
BOOL bResult;
CImageRGBToGrey* pcGrey;
CImageHeightToNormals* pcNormals;
CImageResampler* pcSmall;
CImage cBak;
bResult = ReadImage(&cBak, "Input/Adelle.png");
AssertBool(TRUE, bResult);
cImage.Copy(&cBak);
cStack.Init(&cImage);
pcGrey = cStack.AddModifier<CImageRGBToGrey>();
pcGrey->Init(RGBTGS_UseRed);
cStack.ApplyAll();
WriteImage(&cImage, "Output/AdelleGrey.raw");
AssertFileMemory("Input/AdelleGrey.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
pcNormals = cStack.AddModifier<CImageHeightToNormals>();
pcNormals->Init(IMAGE_DIFFUSE_GREY);
cImage.Copy(&cBak);
cStack.ApplyAll();
WriteImage(&cImage, "Output/AdelleNormal.raw");
AssertFileMemory("Input/AdelleNormal.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
pcSmall = cStack.AddModifier<CImageResampler>();
pcSmall->Init(IR_NearestNeighbour, 21, 16);
cImage.Copy(&cBak);
cStack.ApplyAll();
WriteImage(&cImage, "Output/AdelleSmall.raw");
AssertFileMemory("Input/AdelleSmall.raw", cImage.GetData(), cImage.GetByteSize());
AssertInt(3, cStack.NumModifiers());
cStack.Kill();
cImage.Kill();
cBak.Kill();
TestStatistics();
}
示例3: WriteImage
void CImageIORaw::WriteImage(const CImage& image, CNcbiOstream& ostr,
size_t /* x */, size_t y,
size_t width, size_t height,
CImageIO::ECompress)
{
// write the header
ostr.write(reinterpret_cast<const char*>(sc_Header), 4);
// write dimensions
size_t depth = image.GetDepth();
ostr.write(reinterpret_cast<const char*>(&width), sizeof(size_t));
ostr.write(reinterpret_cast<const char*>(&height), sizeof(size_t));
ostr.write(reinterpret_cast<const char*>(&depth), sizeof(size_t));
// calculate the bytes per line for our sub-image anf dor the input image
const size_t input_bpl = image.GetWidth() * depth;
const size_t output_bpl = width * depth;
// write the image data
const unsigned char* data = image.GetData();
data += input_bpl * y;
for (size_t i = 0; i < height; ++i, data += input_bpl) {
ostr.write(reinterpret_cast<const char*>(data), output_bpl);
}
}
示例4: TestImageReaderRAD
void TestImageReaderRAD(void)
{
CImage cImage;
BOOL bResult;
bResult = ReadImage(&cImage, "Input\\readrad.rad");
AssertBool(TRUE, bResult);
WriteImage(&cImage, "Output\\readrad.raw");
AssertFileMemory("input\\readrad.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
//Read raw is a special case. Because the size and the channels aren't known the image must be initialised before hand.
cImage.Init(32, 48, PT_uchar, IMAGE_DIFFUSE_RED, IMAGE_DIFFUSE_GREEN, IMAGE_DIFFUSE_BLUE, CHANNEL_ZERO);
bResult = ReadImage(&cImage, "Input\\readrad.raw");
AssertBool(TRUE, bResult);
WriteImage(&cImage, "Output\\readraw.raw");
AssertFileMemory("input\\readraw.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
}
示例5: TestImageReaderTGA
void TestImageReaderTGA(void)
{
CImage cImage;
ReadImage(&cImage, "Input\\tar32un.tga");
WriteImage(&cImage, "Output\\tar32un.raw");
AssertFileMemory("input\\tar32un.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
ReadImage(&cImage, "Input\\tar24un.tga");
WriteImage(&cImage, "Output\\tar24un.raw");
AssertFileMemory("input\\tar24un.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
ReadImage(&cImage, "Input\\tar16un.tga");
WriteImage(&cImage, "Output\\tar16un.raw");
AssertFileMemory("input\\tar16un.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
}
示例6: TestImageSwizzle
void TestImageSwizzle(void)
{
BeginTests();
CImage cImage;
CImageModifierStack cStack;
CImageRGBToGrey* pcRGBToGrey;
CImageChannelRename* pcChannelRename;
CImageChannelAdd* pcChannelAdd;
CImageDrawBox* pcDrawBox;
CImageColourRGB cRGB;
ReadImage(&cImage, "Input\\swizzel.png");
cStack.Init(&cImage);
pcRGBToGrey = cStack.AddModifier<CImageRGBToGrey>();
pcRGBToGrey->Init(RGBTGS_OnlyIfChannelsSame);
pcChannelRename = cStack.AddModifier<CImageChannelRename>();
pcChannelRename->Init(IMAGE_DIFFUSE_GREY, IMAGE_OPACITY);
pcChannelAdd = cStack.AddModifier<CImageChannelAdd>();
pcChannelAdd->Init(IMAGE_DIFFUSE_RED, PT_uchar);
pcChannelAdd->AddChannel(IMAGE_DIFFUSE_GREEN);
pcChannelAdd->AddChannel(IMAGE_DIFFUSE_BLUE);
pcDrawBox = cStack.AddModifier<CImageDrawBox>();
cRGB.Init(1.0f, 1.0f, 1.0f);
pcDrawBox->Init(NULL, &cRGB);
cStack.ApplyAll();
cStack.Kill();
WriteImage(&cImage, "Output\\swizzle.raw");
AssertFileMemory("input\\swizzle.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
TestStatistics();
}
示例7: TestImageGreyToRGB
void TestImageGreyToRGB(void)
{
BeginTests();
CImage cImage;
CImageGreyToRGB cGreyToRGB;
ReadImage(&cImage, "Input/basn0g08.png");
cGreyToRGB.Init();
cGreyToRGB.Modify(&cImage);
cGreyToRGB.Kill();
WriteImage(&cImage, "Output/GreyToRGB.raw");
AssertFileMemory("input/GreyToRGB.raw", cImage.GetData(), cImage.GetByteSize());
cGreyToRGB.Kill();
cImage.Kill();
TestStatistics();
}
示例8: LoadCubeMapFromFiles
void COGLCubeMap::LoadCubeMapFromFiles(
const char* pos_x, const char* neg_x,
const char* pos_y, const char* neg_y,
const char* pos_z, const char* neg_z)
{
const char* paths[6] = { pos_x, neg_x, pos_y, neg_y, pos_z, neg_z };
COGLBindLock lock(this, COGL_TEXTURE0_SLOT);
for (int i = 0; i < 6; ++i)
{
CImage* image = new CImage(m_Width, m_Height);
image->LoadFromFile(paths[i], false);
glm::vec4* pData = image->GetData();
glTexImage2D(cube[i], 0, m_InternalFormat, m_Width, m_Height, 0, GL_RGBA, GL_FLOAT, pData);
delete image;
}
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
}
示例9: Update
/////////////////////////////////////////////////////////////
/// Met à jour les pixels de la texture
///
/// \param Rect : Rectangle à mettre à jour dans la texture
///
////////////////////////////////////////////////////////////
void GLTexture::Update(const CRectangle& Rect)
{
CA_ASSERT(CRectangle(0, 0, m_Size.x, m_Size.y).Intersects(Rect) != INT_OUT, "GLTexture::Update() : rectangle out of bounds");
GLCheck(glBindTexture(GL_TEXTURE_2D, m_Texture));
GLEnum::TPixelFmt TexFmt = GLEnum::Get(m_Format);
GLEnum::TPixelFmt ImgFmt = GLEnum::Get(m_Data.GetFormat());
if (FormatCompressed(m_Data.GetFormat()))
{
#if CA_PLATFORM_DESKTOP
// Format de pixel compressé - on utilise une extension pour uploader les pixels
unsigned long DataSize = Rect.Width() * Rect.Height() * GetBytesPerPixel(m_Data.GetFormat());
if (Rect.Width() == m_Size.x && Rect.Height() == m_Size.y)
{
// Le rectangle source couvre la totalité de l'image : on envoie directement les données
GLRenderer::glCompressedTexSubImage2DARB(GL_TEXTURE_2D, 0, Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, DataSize, m_Data.GetData());
}
else
{
// Le rectangle source ne couvre qu'une partie de l'image : on envoie une sous-image de l'image en mémoire
CImage SubData = m_Data.SubImage(Rect);
GLRenderer::glCompressedTexSubImage2DARB(GL_TEXTURE_2D, 0, Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, DataSize, SubData.GetData());
}
#else
throw NEW_AO CNotImplementedException("GLTexture::Update() : compressed format is not supported\n");
#endif // CA_PLATFORM_DESKTOP
}
else
{
GLint pixelStore = 0;
switch (m_Data.GetFormat())
{
case PixelFormat::L_8: ///< Luminosity 8 bits (1 byte)
pixelStore = 1;
break;
case PixelFormat::AL_88: ///< Alpha and luminosity 16 bits (2 bytes)
case PixelFormat::ARGB_1555: ///< RGB 16 bits 1555 (2 bytes)
case PixelFormat::ARGB_4444: ///< RGB 16 bits 4444 (2 bytes)
case PixelFormat::PVRTC2: ///< PVR texture compression. Each pixel is 2 bits.
pixelStore = 2;
break;
case PixelFormat::RGB_888: ///< RGB 24 bits 888 (3 bytes)
case PixelFormat::RGB_DXT1: ///< S3 DXT1 texture compression (RGB)
//
case PixelFormat::ARGB_8888: ///< ARGB 32 bits 8888 (4 bytes)
case PixelFormat::PVRTC4: ///< PVR texture compression. Each pixel is 4 bits.
case PixelFormat::RGBA_DXT1: ///< S3 DXT1 texture compression (RGBA)
case PixelFormat::RGBA_DXT3: ///< S3 DXT3 texture compression (RGBA)
case PixelFormat::RGBA_DXT5: ///< S3 DXT5 texture compression (RGBA)
pixelStore = 4;
break;
}
GLCheck(glPixelStorei(GL_PACK_ALIGNMENT, pixelStore));
if (!m_HasMipmaps || m_AutoMipmaps)
{
// Pas de mipmap ou génération hardware : on ne met à jour que le premier niveau
if ((Rect.Width() == m_Size.x) && (Rect.Height() == m_Size.y))
{
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0,
0, 0, Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, m_Data.GetData()));
}
else
{
CImage SubData = m_Data.SubImage(Rect);
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0,
Rect.Left(), Rect.Top(), Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, SubData.GetData()));
}
}
else
{
#if CA_PLATFORM_DESKTOP
// Plusieurs niveaux de mipmapping et génération software : on met à jour tous les niveaux
GLCheck(gluBuild2DMipmaps(GL_TEXTURE_2D, TexFmt.Internal, m_Size.x, m_Size.y, ImgFmt.Format, ImgFmt.Type, m_Data.GetData()));
#else
if ((Rect.Width() == m_Size.x) && (Rect.Height() == m_Size.y))
{
GLCheck(glTexSubImage2D(GL_TEXTURE_2D, 0,
0, 0, Rect.Width(), Rect.Height(), ImgFmt.Format, ImgFmt.Type, m_Data.GetData()));
}
else
//.........这里部分代码省略.........
示例10: TestImageReaderPNG
void TestImageReaderPNG(void)
{
CImage cImage;
ReadImage(&cImage, "Input\\basn0g01.png");
WriteImage(&cImage, "Output\\basn0g01.raw");
AssertFileMemory("input\\basn0g01.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
ReadImage(&cImage, "Input\\basn0g02.png");
WriteImage(&cImage, "Output\\basn0g02.raw");
AssertFileMemory("input\\basn0g02.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
ReadImage(&cImage, "Input\\basn0g04.png");
WriteImage(&cImage, "Output\\basn0g04.raw");
AssertFileMemory("input\\basn0g04.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
ReadImage(&cImage, "Input\\basn0g08.png");
WriteImage(&cImage, "Output\\basn0g08.raw");
AssertFileMemory("input\\basn0g08.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
ReadImage(&cImage, "Input\\basn0g16.png");
WriteImage(&cImage, "Output\\basn0g16.raw");
AssertFileMemory("input\\basn0g16.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
ReadImage(&cImage, "Input\\basn2c08.png");
WriteImage(&cImage, "Output\\basn2c08.raw");
AssertFileMemory("input\\basn2c08.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
ReadImage(&cImage, "Input\\basn2c16.png");
WriteImage(&cImage, "Output\\basn2c16.raw");
AssertFileMemory("input\\basn2c16.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
ReadImage(&cImage, "Input\\basn4a08.png");
AssertInt(32, cImage.GetWidth());
AssertInt(32, cImage.GetHeight());
AssertInt(2048, cImage.GetByteSize());
WriteImage(&cImage, "Output\\basn4a08.raw");
AssertFileMemory("input\\basn4a08.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
ReadImage(&cImage, "Input\\basn4a16.png");
WriteImage(&cImage, "Output\\basn4a16.raw");
AssertFileMemory("input\\basn4a16.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
ReadImage(&cImage, "Input\\basn6a08.png");
WriteImage(&cImage, "Output\\basn6a08.raw");
AssertFileMemory("input\\basn6a08.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
ReadImage(&cImage, "Input\\basn6a16.png");
WriteImage(&cImage, "Output\\basn6a16.raw");
AssertFileMemory("input\\basn6a16.raw", cImage.GetData(), cImage.GetByteSize());
cImage.Kill();
}