本文整理汇总了C++中CImage::GetDepth方法的典型用法代码示例。如果您正苦于以下问题:C++ CImage::GetDepth方法的具体用法?C++ CImage::GetDepth怎么用?C++ CImage::GetDepth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CImage
的用法示例。
在下文中一共展示了CImage::GetDepth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteImage
//
// WriteImage()
// write an image to a file in PNG format
// This version writes the entire image
//
void CImageIOPng::WriteImage(const CImage& image, CNcbiOstream& ostr,
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,
image.GetWidth(), image.GetHeight(), 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, line-by-line
unsigned char* row_ptr = const_cast<unsigned char*> (image.GetData());
size_t width = image.GetWidth();
size_t height = image.GetHeight();
size_t depth = image.GetDepth();
for (size_t i = 0; i < height; ++i) {
png_write_row(png_ptr, row_ptr);
row_ptr += width * depth;
}
// 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: 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);
}
}
示例3: CodeToFile
void CDevILCodec::CodeToFile(const nstring & filename, const CImage &image)
{
ILuint imageid;
CDevILFormats informat;
informat.SetExFormat(image.GetPixelFormat());
// Generate the main image name to use.
ilGenImages(1, &imageid);
// Bind this image name.
ilBindImage(imageid);
ilTexImage(image.GetWidth(), image.GetHeight(), image.GetDepth(), informat.GetInternalChannels(),
informat.GetFormat(), IL_UNSIGNED_BYTE, image.GetBitsPtr());
ilSaveImage(filename.c_str());
ilDeleteImages(1, &imageid);
ILenum Error = 0;
if((Error = ilGetError()) != NULL)
{
nstring str("CDevILCodec::CodeToFile: ");
str.append(iluErrorString(Error));
throw NOVA_EXP(str.c_str(), BAD_OPERATION);
}
}
示例4: CodeToBuffer
void CDevILCodec::CodeToBuffer(CMemoryBuffer & out, const CImage &image,
ESaveFormats ext)
{
ILuint imageid;
CDevILFormats informat;
informat.SetExFormat(image.GetPixelFormat());
// Generate the main image name to use.
ilGenImages(1, &imageid);
// Bind this image name.
ilBindImage(imageid);
ilTexImage(image.GetWidth(), image.GetHeight(), image.GetDepth(), informat.GetInternalChannels(),
informat.GetFormat(), IL_UNSIGNED_BYTE, image.GetBitsPtr());
ILenum type = 0;
switch(ext)
{
case SF_BMP:
type = IL_BMP;
break;
case SF_ICO:
type = IL_ICO;
break;
case SF_JPG:
type = IL_JPG;
break;
case SF_PCX:
type = IL_PCX;
break;
case SF_PIC:
type = IL_PIC;
break;
case SF_PNG:
type = IL_PNG;
break;
case SF_TGA:
type = IL_TGA;
break;
case SF_TIF:
type = IL_TIF;
break;
case SF_GIF:
type = IL_GIF;
break;
case SF_DDS:
type = IL_DDS;
break;
case SF_PIX:
type = IL_PIX;
break;
case SF_HDR:
type = IL_HDR;
break;
default:
return;
}
out.AllocBuffer(image.GetSize()+0xff);
ilSaveL(type, out.GetBegin(), out.GetBufferSize());
ilDeleteImages(1, &imageid);
ILenum Error = 0;
if((Error = ilGetError()) != NULL)
{
nstring str("CDevILCodec::CodeToStream: ");
str.append(iluErrorString(Error));
throw NOVA_EXP(str.c_str(), BAD_OPERATION);
}
}