本文整理汇总了C++中imageStruct::reallocate方法的典型用法代码示例。如果您正苦于以下问题:C++ imageStruct::reallocate方法的具体用法?C++ imageStruct::reallocate怎么用?C++ imageStruct::reallocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imageStruct
的用法示例。
在下文中一共展示了imageStruct::reallocate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
/////////////////////////////////////////////////////////
// really open the file ! (OS dependent)
//
/////////////////////////////////////////////////////////
bool imageMAGICK :: load(std::string filename, imageStruct&result, gem::Properties&props)
{
Magick::Image image;
try {
::verbose(2, "reading '%s' with ImageMagick", filename.c_str());
// Read a file into image object
try {
image.read( filename );
} catch (Magick::Warning e) {
verbose(1, "magick loading problem: %s", e.what());
}
result.xsize=static_cast<GLint>(image.columns());
result.ysize=static_cast<GLint>(image.rows());
result.setCsizeByFormat(GL_RGBA);
result.reallocate();
result.upsidedown=true;
try {
image.write(0,0,result.xsize,result.ysize,
"RGBA",
Magick::CharPixel,
reinterpret_cast<void*>(result.data));
} catch (Magick::Warning e) {
verbose(1, "magick decoding problem: %s", e.what());
}
}catch( Magick::Exception e ) {
verbose(1, "magick loading image failed with: %s", e.what());
return false;
}
return true;
}
示例2: refresh_buffer
/////////////////////////////////////////////////////////
// CreateBuffer
//
/////////////////////////////////////////////////////////
bool refresh_buffer(const imageStruct&reference, imageStruct&buffer)
{
// only 1 channel !!, to keep data-size handy
unsigned char*data = buffer.data;
size_t dataSize = reference.xsize * reference.xsize * reference.ysize * reference.csize * sizeof(unsigned char);
bool refresh=
(reference.xsize != buffer.xsize) ||
(reference.ysize != buffer.ysize) ||
(reference.csize != buffer.csize);
buffer.xsize = reference.xsize;
buffer.ysize = reference.ysize;
buffer.setCsizeByFormat(reference.format);
if(data!=buffer.reallocate( dataSize ) || refresh) {
buffer.setBlack();
}
return (0!=buffer.data);
}
示例3: verbose
static bool QuickTimeImage2mem(GraphicsImportComponent inImporter,
imageStruct&result)
{
Rect r;
if (::GraphicsImportGetNaturalBounds(inImporter, &r)) {
return NULL; //get an image size
}
::OffsetRect(&r, -r.left, -r.top);
if (::GraphicsImportSetBoundsRect(inImporter, &r)) {
return NULL;
}
ImageDescriptionHandle imageDescH = NULL;
if (::GraphicsImportGetImageDescription(inImporter, &imageDescH)) {
return NULL;
}
result.xsize = (*imageDescH)->width;
result.ysize = (*imageDescH)->height;
result.upsidedown = true;
OSType pixelformat = 0;
/* afaik, there is no 8bit grayscale format....
* and even if it was, k8GrayPixelFormat would not be a define...
*/
#ifdef k8GrayPixelFormat
/* from the docs on "depth": what depth is this data (1-32) or ( 33-40 grayscale ) */
if ((*imageDescH)->depth <= 32) {
result.setCsizeByFormat(GL_RGBA_GEM);
pixelformat = IMAGEQT_RGBA_PIXELFORMAT;
} else {
result.setCsizeByFormat(GL_LUMINANCE);
pixelformat = k8GrayPixelFormat;
}
#else
result.setCsizeByFormat(GL_RGBA_GEM);
pixelformat = IMAGEQT_RGBA_PIXELFORMAT;
#endif
::DisposeHandle(reinterpret_cast<Handle>(imageDescH));
imageDescH = NULL;
result.reallocate();
verbose(1, "[GEM:imageQT] QuickTimeImage2mem() allocate %d bytes",
result.xsize*result.ysize*result.csize);
if (result.data == NULL) {
verbose(0, "[GEM:imageQT] Can't allocate memory for an image.");
return false;
}
GWorldPtr gw = NULL;
OSErr err = QTNewGWorldFromPtr(&gw,
/* taken from pix_filmDarwin */
pixelformat, // gives noErr
&r, NULL, NULL, 0,
// keepLocal,
//useDistantHdwrMem,
result.data,
static_cast<long>(result.xsize * result.csize));
if (err) {
verbose(0, "[GEM:imageQT] Can't create QTNewWorld");
}
::GraphicsImportSetGWorld(inImporter, gw, NULL);
::GraphicsImportDraw(inImporter);
::DisposeGWorld(gw); //dispose the offscreen
gw = NULL;
return true;
}
示例4: load
/////////////////////////////////////////////////////////
// really open the file ! (OS dependent)
//
/////////////////////////////////////////////////////////
bool imageJPEG :: load(std::string filename, imageStruct&result, gem::Properties&props)
{
// open up the file
FILE * infile;
::verbose(2, "reading '%s' with libJPEG", filename.c_str());
if ((infile = fopen(filename.c_str(), "rb")) == NULL) {
//verbose(2, "GemImageLoad(JPEG): Unable to open image file: %s", filename.c_str());
return(false);
}
// create the jpeg structures
jpeg_decompress_struct cinfo;
my_error_mgr jerr;
// We set up the normal JPEG error routines, then override error_exit
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
// Establish the setjmp return context for my_error_exit to use.
if ( setjmp(jerr.setjmp_buffer) ) {
// If we get here, the JPEG code has signaled an error.
// We need to clean up the JPEG object, close the input file, and return.
jpeg_destroy_decompress(&cinfo);
fclose(infile);
return(false);
}
// create the decompression structure
jpeg_create_decompress(&cinfo);
// associate the decompress struct with the file
jpeg_stdio_src(&cinfo, infile);
// read in the file info
jpeg_read_header(&cinfo, TRUE);
// do we have an RGB image?
if (cinfo.jpeg_color_space == JCS_RGB) {
result.setCsizeByFormat(GL_RGBA);
} else if (cinfo.jpeg_color_space == JCS_GRAYSCALE) {
// do we have a gray8 image?
result.setCsizeByFormat(GL_LUMINANCE);
} else {
// something else, so decompress as RGB
result.setCsizeByFormat(GL_RGBA);
cinfo.out_color_space = JCS_RGB;
}
// start the decompression
jpeg_start_decompress(&cinfo);
int xSize = cinfo.output_width;
int ySize = cinfo.output_height;
int cSize = result.csize;
result.upsidedown=true;
result.xsize = xSize;
result.ysize = ySize;
result.reallocate();
// cycle through the scan lines
unsigned char *srcLine = new unsigned char[xSize * cSize];
unsigned char *dstLine = result.data;
int yStride = xSize * cSize;
int lines = ySize;
int pixes = xSize;
// do RGBA/RGB data
if (cSize == 4) {
while (lines--) {
unsigned char *src = srcLine;
unsigned char *dst = dstLine;
jpeg_read_scanlines(&cinfo, &src, 1);
pixes = xSize;
while (pixes--) {
dst[chRed] = src[0];
dst[chGreen] = src[1];
dst[chBlue] = src[2];
dst[chAlpha] = 255;
dst += 4;
src += 3;
}
dstLine += yStride;
}
} else {
// do grayscale data
while (lines--) {
unsigned char *src = srcLine;
unsigned char *dst = dstLine;
jpeg_read_scanlines(&cinfo, &src, 1);
pixes = xSize;
while (pixes--) {
*dst++ = *src++;
}
dstLine += yStride;
}
}
//.........这里部分代码省略.........
示例5: if
/////////////////////////////////////////////////////////
// really open the file ! (OS dependent)
//
/////////////////////////////////////////////////////////
bool imageTIFF :: load(std::string filename, imageStruct&result, gem::Properties&props)
{
::logpost(NULL, 6, "reading '%s' with libTIFF", filename.c_str());
TIFF *tif = TIFFOpen(filename.c_str(), "r");
if (tif == NULL) {
return(NULL);
}
uint32 width, height;
short bits, samps;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bits);
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samps);
int npixels = width * height;
result.xsize=width;
result.ysize=height;
result.upsidedown=true;
result.type=GL_UNSIGNED_BYTE; //?
bool knownFormat = false;
// Is it a gray8 image?
if (bits == 8 && samps == 1)
{
result.setCsizeByFormat(GL_LUMINANCE);
knownFormat = true;
}
// Is it an RGB image?
else if (bits == 8 && samps == 3)
{
result.setCsizeByFormat(GL_RGBA);
knownFormat = true;
}
// Is it an RGBA image?
else if (bits == 8 && samps == 4)
{
result.setCsizeByFormat(GL_RGBA);
knownFormat = true;
}
// can we handle the raw data?
if (knownFormat) {
unsigned char *buf = new unsigned char [TIFFScanlineSize(tif)];
if (buf == NULL) {
error("GemImageLoad(TIFF): can't allocate memory for scanline buffer: %s", filename.c_str());
TIFFClose(tif);
return(false);
}
result.reallocate();
unsigned char *dstLine = result.data;
int yStride = result.xsize * result.csize;
for (uint32 row = 0; row < height; row++)
{
unsigned char *pixels = dstLine;
if (TIFFReadScanline(tif, buf, row, 0) < 0) {
error("GemImageLoad(TIFF): bad image data read on line: %d: %s", row, filename.c_str());
TIFFClose(tif);
return false;
}
unsigned char *inp = buf;
if (samps == 1) {
for (uint32 i = 0; i < width; i++) {
*pixels++ = *inp++; // Gray8
}
}
else if (samps == 3) {
for (uint32 i = 0; i < width; i++) {
pixels[chRed] = inp[0]; // Red
pixels[chGreen] = inp[1]; // Green
pixels[chBlue] = inp[2]; // Blue
pixels[chAlpha] = 255; // Alpha
pixels += 4;
inp += 3;
}
} else {
for (uint32 i = 0; i < width; i++) {
pixels[chRed] = inp[0]; // Red
pixels[chGreen] = inp[1]; // Green
pixels[chBlue] = inp[2]; // Blue
pixels[chAlpha] = inp[3]; // Alpha
pixels += 4;
inp += 4;
}
}
dstLine += yStride;
}
delete [] buf;
}
// nope, so use the automatic conversion
else {
char emsg[1024];
TIFFRGBAImage img;
if (TIFFRGBAImageBegin(&img, tif, 0, emsg) == 0) {
//.........这里部分代码省略.........