本文整理汇总了C++中osg::Image::getDataType方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::getDataType方法的具体用法?C++ Image::getDataType怎么用?C++ Image::getDataType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osg::Image
的用法示例。
在下文中一共展示了Image::getDataType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeImage
virtual WriteResult writeImage(const osg::Image& image,const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
// Only ppm format output supported
std::string ext = osgDB::getFileExtension(fileName);
if ( !osgDB::equalCaseInsensitive(ext, "ppm") ) return WriteResult::FILE_NOT_HANDLED;
// only support rgb images right now.
if (image.getPixelFormat()!=GL_RGB || image.getDataType()!=GL_UNSIGNED_BYTE) return WriteResult("Error image pixel format not supported by pnm writer.");
osgDB::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary);
if(!fout) return WriteResult::ERROR_IN_WRITING_FILE;
return writeImage(image,fout,options);
}
示例2: CreateCGImageFromOSGData
//.........这里部分代码省略.........
color_space = CGColorSpaceCreateDeviceRGB();
if(NULL == color_space)
{
OSG_WARN << "In CreateCGImageFromOSGData, CGColorSpaceCreateWithName failed" << std::endl;
return NULL;
}
// out_image_data = calloc(target_bytes_per_row, image_height);
out_image_data = malloc(target_bytes_per_row * image_height);
if(NULL == out_image_data)
{
OSG_WARN << "In CreateCGImageFromOSGData, malloc failed" << std::endl;
CGColorSpaceRelease(color_space);
return NULL;
}
vimage_buffer_out.data = out_image_data;
vimage_buffer_out.rowBytes = target_bytes_per_row;
// Invert the image
vimage_error_flag = vImageVerticalReflect_ARGB8888(
&vimage_buffer_in, // since the osg_image is const...
&vimage_buffer_out, // don't reuse the buffer
kvImageNoFlags
);
if(vimage_error_flag != kvImageNoError)
{
OSG_WARN << "In CreateCGImageFromOSGData, vImageAffineWarp_ARGB8888 failed with vImage Error Code: " << vimage_error_flag << std::endl;
free(out_image_data);
CGColorSpaceRelease(color_space);
return NULL;
}
break;
}
case GL_BGRA:
{
if(GL_UNSIGNED_INT_8_8_8_8_REV == osg_image.getDataType())
{
#if __BIG_ENDIAN__
bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big; /* XRGB Big Endian */
#else
bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little; /* XRGB Little Endian */
#endif
}
else
{
// FIXME: Don't know how to handle this case
bitmap_info = kCGImageAlphaPremultipliedLast;
}
target_bytes_per_row = osg_image.getRowSizeInBytes();
//color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
color_space = CGColorSpaceCreateDeviceRGB();
if(NULL == color_space)
{
OSG_WARN << "In CreateCGImageFromOSGData, CGColorSpaceCreateWithName failed" << std::endl;
return NULL;
}
// out_image_data = calloc(target_bytes_per_row, image_height);
out_image_data = malloc(target_bytes_per_row * image_height);
if(NULL == out_image_data)
{
OSG_WARN << "In CreateCGImageFromOSGData, malloc failed" << std::endl;
CGColorSpaceRelease(color_space);
return NULL;
}
vimage_buffer_out.data = out_image_data;
vimage_buffer_out.rowBytes = target_bytes_per_row;
// Invert the image
示例3: writeTIFStream
WriteResult::WriteStatus writeTIFStream(std::ostream& fout, const osg::Image& img, const osgDB::ReaderWriter::Options* options) const
{
int compressionType = COMPRESSION_PACKBITS;
if (options) {
std::istringstream iss(options->getOptionString());
std::string opt;
while (iss >> opt) {
opt = osgDB::convertToLowerCase(opt);
std::size_t eqInd = opt.find("=");
if (opt.substr(0, eqInd) == "tiff_compression") {
std::string compressTypeOpt;
compressTypeOpt = opt.substr(eqInd + 1);
compressTypeOpt = osgDB::convertToLowerCase(compressTypeOpt);
if (compressTypeOpt == "packbits") {
compressionType = COMPRESSION_PACKBITS;
}
else if (compressTypeOpt == "lzw") {
compressionType = COMPRESSION_LZW;
}
else if (compressTypeOpt == "jpeg") {
compressionType = COMPRESSION_JPEG;
}
}
}
}
//Code is based from the following article on CodeProject.com
//http://www.codeproject.com/bitmap/BitmapsToTiffs.asp
TIFF *image;
int samplesPerPixel;
int bitsPerSample;
uint16 photometric;
image = TIFFClientOpen("outputstream", "w", (thandle_t)&fout,
libtiffOStreamReadProc, //Custom read function
libtiffOStreamWriteProc, //Custom write function
libtiffOStreamSeekProc, //Custom seek function
libtiffStreamCloseProc, //Custom close function
libtiffOStreamSizeProc, //Custom size function
libtiffStreamMapProc, //Custom map function
libtiffStreamUnmapProc); //Custom unmap function
if(image == NULL)
{
return WriteResult::ERROR_IN_WRITING_FILE;
}
switch(img.getPixelFormat()) {
case GL_DEPTH_COMPONENT:
case GL_LUMINANCE:
case GL_ALPHA:
photometric = PHOTOMETRIC_MINISBLACK;
samplesPerPixel = 1;
break;
case GL_LUMINANCE_ALPHA:
photometric = PHOTOMETRIC_MINISBLACK;
samplesPerPixel = 2;
break;
case GL_RGB:
photometric = PHOTOMETRIC_RGB;
samplesPerPixel = 3;
break;
case GL_RGBA:
photometric = PHOTOMETRIC_RGB;
samplesPerPixel = 4;
break;
default:
return WriteResult::ERROR_IN_WRITING_FILE;
break;
}
switch(img.getDataType()){
case GL_FLOAT:
TIFFSetField(image, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, 1);
bitsPerSample = 32;
break;
case GL_SHORT:
TIFFSetField(image, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_INT);
bitsPerSample = 16;
break;
default:
bitsPerSample = 8;
break;
}
TIFFSetField(image, TIFFTAG_IMAGEWIDTH,img.s());
TIFFSetField(image, TIFFTAG_IMAGELENGTH,img.t());
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE,bitsPerSample);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL,samplesPerPixel);
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, photometric);
TIFFSetField(image, TIFFTAG_COMPRESSION, compressionType);
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
//uint32 rowsperstrip = TIFFDefaultStripSize(image, -1);
//TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
//.........这里部分代码省略.........
示例4: writeTIFStream
WriteResult::WriteStatus writeTIFStream(std::ostream& fout, const osg::Image& img) const
{
//Code is based from the following article on CodeProject.com
//http://www.codeproject.com/bitmap/BitmapsToTiffs.asp
TIFF *image;
int samplesPerPixel;
int bitsPerSample;
uint16 photometric;
image = TIFFClientOpen("outputstream", "w", (thandle_t)&fout,
libtiffOStreamReadProc, //Custom read function
libtiffOStreamWriteProc, //Custom write function
libtiffOStreamSeekProc, //Custom seek function
libtiffStreamCloseProc, //Custom close function
libtiffOStreamSizeProc, //Custom size function
libtiffStreamMapProc, //Custom map function
libtiffStreamUnmapProc); //Custom unmap function
if(image == NULL)
{
return WriteResult::ERROR_IN_WRITING_FILE;
}
switch(img.getPixelFormat()) {
case GL_LUMINANCE:
case GL_ALPHA:
photometric = PHOTOMETRIC_MINISBLACK;
samplesPerPixel = 1;
break;
case GL_LUMINANCE_ALPHA:
photometric = PHOTOMETRIC_MINISBLACK;
samplesPerPixel = 2;
break;
case GL_RGB:
photometric = PHOTOMETRIC_RGB;
samplesPerPixel = 3;
break;
case GL_RGBA:
photometric = PHOTOMETRIC_RGB;
samplesPerPixel = 4;
break;
default:
return WriteResult::ERROR_IN_WRITING_FILE;
break;
}
switch(img.getDataType()){
case GL_FLOAT:
TIFFSetField(image, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, 1);
bitsPerSample = 32;
break;
default:
bitsPerSample = 8;
break;
}
TIFFSetField(image, TIFFTAG_IMAGEWIDTH,img.s());
TIFFSetField(image, TIFFTAG_IMAGELENGTH,img.t());
TIFFSetField(image, TIFFTAG_BITSPERSAMPLE,bitsPerSample);
TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL,samplesPerPixel);
TIFFSetField(image, TIFFTAG_PHOTOMETRIC, photometric);
TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
TIFFSetField(image, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
//uint32 rowsperstrip = TIFFDefaultStripSize(image, -1);
//TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
// Write the information to the file
for(int i = 0; i < img.t(); ++i) {
TIFFWriteScanline(image,(tdata_t)img.data(0,img.t()-i-1),i,0);
}
// Close the file
TIFFClose(image);
return WriteResult::FILE_SAVED;
}
示例5: writeRGBStream
WriteResult writeRGBStream(const osg::Image& img, std::ostream &fout, const std::string& name) const
{
rawImageRec raw;
raw.imagic = 0732;
GLenum dataType = img.getDataType();
raw.type = dataType == GL_UNSIGNED_BYTE ? 1 :
dataType == GL_BYTE ? 1 :
dataType == GL_BITMAP ? 1 :
dataType == GL_UNSIGNED_SHORT ? 2 :
dataType == GL_SHORT ? 2 :
dataType == GL_UNSIGNED_INT ? 4 :
dataType == GL_INT ? 4 :
dataType == GL_FLOAT ? 4 :
dataType == GL_UNSIGNED_BYTE_3_3_2 ? 1 :
dataType == GL_UNSIGNED_BYTE_2_3_3_REV ? 1 :
dataType == GL_UNSIGNED_SHORT_5_6_5 ? 2 :
dataType == GL_UNSIGNED_SHORT_5_6_5_REV ? 2 :
dataType == GL_UNSIGNED_SHORT_4_4_4_4 ? 2 :
dataType == GL_UNSIGNED_SHORT_4_4_4_4_REV ? 2 :
dataType == GL_UNSIGNED_SHORT_5_5_5_1 ? 2 :
dataType == GL_UNSIGNED_SHORT_1_5_5_5_REV ? 2 :
dataType == GL_UNSIGNED_INT_8_8_8_8 ? 4 :
dataType == GL_UNSIGNED_INT_8_8_8_8_REV ? 4 :
dataType == GL_UNSIGNED_INT_10_10_10_2 ? 4 :
dataType == GL_UNSIGNED_INT_2_10_10_10_REV ? 4 : 4;
GLenum pixelFormat = img.getPixelFormat();
raw.dim = 3;
raw.sizeX = img.s();
raw.sizeY = img.t();
raw.sizeZ =
pixelFormat == GL_COLOR_INDEX? 1 :
pixelFormat == GL_RED? 1 :
pixelFormat == GL_GREEN? 1 :
pixelFormat == GL_BLUE? 1 :
pixelFormat == GL_ALPHA? 1 :
pixelFormat == GL_RGB? 3 :
pixelFormat == GL_BGR ? 3 :
pixelFormat == GL_RGBA? 4 :
pixelFormat == GL_BGRA? 4 :
pixelFormat == GL_LUMINANCE? 1 :
pixelFormat == GL_LUMINANCE_ALPHA ? 2 : 1;
raw.min = 0;
raw.max = 0xFF;
raw.wasteBytes = 0;
strncpy( raw.name, name.c_str(), 80);
raw.colorMap = 0;
raw.bpc = (img.getPixelSizeInBits()/raw.sizeZ)/8;
int isize = img.getImageSizeInBytes();
unsigned char *buffer = new unsigned char[isize];
if(raw.bpc == 1)
{
unsigned char *dptr = buffer;
int i, j;
for( i = 0; i < raw.sizeZ; ++i )
{
const unsigned char *ptr = img.data();
ptr += i;
for( j = 0; j < isize/raw.sizeZ; ++j )
{
*(dptr++) = *ptr;
ptr += raw.sizeZ;
}
}
}
else
{ // bpc == 2
unsigned short *dptr = reinterpret_cast<unsigned short*>(buffer);
int i, j;
for( i = 0; i < raw.sizeZ; ++i )
{
const unsigned short *ptr = reinterpret_cast<const unsigned short*>(img.data());
ptr += i;
for( j = 0; j < isize/(raw.sizeZ*2); ++j )
{
*dptr = *ptr;
ConvertShort(dptr++, 1);
ptr += raw.sizeZ;
}
}
}
if( raw.needsBytesSwapped() )
raw.swapBytes();
/*
swapBytes( raw.imagic );
swapBytes( raw.type );
swapBytes( raw.dim );
swapBytes( raw.sizeX );
swapBytes( raw.sizeY );
swapBytes( raw.sizeZ );
swapBytes( raw.min );
swapBytes( raw.max );
swapBytes( raw.colorMap );
//.........这里部分代码省略.........
示例6: local_writeImage
WriteResult local_writeImage(std::ostream& fout,const osg::Image& img,const osgDB::ReaderWriter::Options* options) const
{
std::string my_errmsg;
try
{
gta::header hdr;
gta::compression compression = gta::zlib;
if (options)
{
std::istringstream iss(options->getOptionString());
std::string opt;
std::string compressionMethod;
while (iss >> opt)
{
if (opt == "COMPRESSION")
{
iss >> compressionMethod;
}
};
if (compressionMethod == "NONE")
compression = gta::none;
else if (compressionMethod == "ZLIB")
compression = gta::zlib;
else if (compressionMethod == "ZLIB1")
compression = gta::zlib1;
else if (compressionMethod == "ZLIB2")
compression = gta::zlib2;
else if (compressionMethod == "ZLIB3")
compression = gta::zlib3;
else if (compressionMethod == "ZLIB4")
compression = gta::zlib4;
else if (compressionMethod == "ZLIB5")
compression = gta::zlib5;
else if (compressionMethod == "ZLIB6")
compression = gta::zlib6;
else if (compressionMethod == "ZLIB7")
compression = gta::zlib7;
else if (compressionMethod == "ZLIB8")
compression = gta::zlib8;
else if (compressionMethod == "ZLIB9")
compression = gta::zlib9;
else if (compressionMethod == "BZIP2")
compression = gta::bzip2;
else if (compressionMethod == "XZ")
compression = gta::xz;
}
hdr.set_compression(compression);
if (img.s() > 0 && img.t() <= 1 && img.r() <= 1)
{
hdr.set_dimensions(img.s());
}
else if (img.s() > 0 && img.t() > 1 && img.r() <= 1)
{
hdr.set_dimensions(img.s(), img.t());
}
else if (img.s() > 0 && img.t() > 1 && img.r() > 1)
{
hdr.set_dimensions(img.s(), img.t(), img.r());
}
else
{
my_errmsg = "Image has unsupported dimensions";
throw std::exception();
}
gta::type type;
switch (img.getDataType())
{
case GL_BYTE:
type = gta::int8;
break;
case GL_UNSIGNED_BYTE:
type = gta::uint8;
break;
case GL_SHORT:
type = gta::int16;
break;
case GL_UNSIGNED_SHORT:
type = gta::uint16;
break;
case GL_INT:
type = gta::int32;
break;
case GL_UNSIGNED_INT:
type = gta::uint32;
break;
case GL_FLOAT:
type = gta::float32;
break;
default:
my_errmsg = "Image has unsupported data type";
throw std::exception();
}
switch (img.getPixelFormat())
{
case 1:
case GL_DEPTH_COMPONENT:
case GL_LUMINANCE:
case GL_ALPHA:
hdr.set_components(type);
break;
//.........这里部分代码省略.........
示例7: writeEXRStream
bool writeEXRStream(const osg::Image &img, std::ostream& fout, const std::string &fileName) const
{
bool writeOK = true;
//Obtain data from texture
int width = img.s();
int height = img.t();
unsigned int pixelFormat = img.getPixelFormat();
int numComponents = img.computeNumComponents(pixelFormat);
unsigned int dataType = img.getDataType();
//Validates image data
//if numbers of components matches
if (!( numComponents == 3 ||
numComponents == 4))
{
writeOK = false;
return false;
}
if (!( dataType == GL_HALF_FLOAT_ARB ||
dataType == GL_FLOAT))
{
writeOK = false;
return false;
}
//Create a stream to save to
C_OStream outStream(&fout);
//Copy data from texture to rgba pixel format
Array2D<Rgba> outPixels(height,width);
//If texture is half format
if (dataType == GL_HALF_FLOAT_ARB)
{
half* pOut = (half*) img.data();
for (long i = height-1; i >= 0; i--)
{
for (long j = 0 ; j < width; j++)
{
outPixels[i][j].r = (*pOut);
pOut++;
outPixels[i][j].g = (*pOut);
pOut++;
outPixels[i][j].b = (*pOut);
pOut++;
if (numComponents >= 4)
{
outPixels[i][j].a = (*pOut);
pOut++;
}
else {
outPixels[i][j].a = 1.0f;
}
}
}
}
else if (dataType == GL_FLOAT)
{
float* pOut = (float*) img.data();
for (long i = height-1; i >= 0; i--)
{
for (long j = 0 ; j < width; j++)
{
outPixels[i][j].r = half(*pOut);
pOut++;
outPixels[i][j].g = half(*pOut);
pOut++;
outPixels[i][j].b = half(*pOut);
pOut++;
if (numComponents >= 4)
{
outPixels[i][j].a = half(*pOut);
pOut++;
}
else
{
outPixels[i][j].a = 1.0f;
}
}
}
}
else
{
//If texture format not supported
return false;
}
try
{
//Write to stream
Header outHeader(width, height);
RgbaOutputFile rgbaFile (outStream, outHeader, WRITE_RGBA);
rgbaFile.setFrameBuffer ((&outPixels)[0][0], 1, width);
rgbaFile.writePixels (height);
}
catch( char * str )
{
writeOK = false;
}
//.........这里部分代码省略.........