本文整理汇总了C++中refimport_t::Malloc方法的典型用法代码示例。如果您正苦于以下问题:C++ refimport_t::Malloc方法的具体用法?C++ refimport_t::Malloc怎么用?C++ refimport_t::Malloc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类refimport_t
的用法示例。
在下文中一共展示了refimport_t::Malloc方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: R_LoadJPG
//.........这里部分代码省略.........
* Make sure it always converts images to RGB color space. This will
* automatically convert 8-bit greyscale images to RGB as well.
*/
cinfo.out_color_space = JCS_RGB;
/* Step 5: Start decompressor */
(void) jpeg_start_decompress(&cinfo);
/* We can ignore the return value since suspension is not possible
* with the stdio data source.
*/
/* We may need to do some setup of our own at this point before reading
* the data. After jpeg_start_decompress() we have the correct scaled
* output image dimensions available, as well as the output colormap
* if we asked for color quantization.
* In this example, we need to make an output work buffer of the right size.
*/
/* JSAMPLEs per row in output buffer */
pixelcount = cinfo.output_width * cinfo.output_height;
if(!cinfo.output_width || !cinfo.output_height
|| ((pixelcount * 4) / cinfo.output_width) / 4 != cinfo.output_height
|| pixelcount > 0x1FFFFFFF || cinfo.output_components != 3
)
{
// Free the memory to make sure we don't leak memory
ri.FS_FreeFile (fbuffer.v);
jpeg_destroy_decompress(&cinfo);
ri.Error(ERR_DROP, "LoadJPG: %s has an invalid image format: %dx%d*4=%d, components: %d", filename,
cinfo.output_width, cinfo.output_height, pixelcount * 4, cinfo.output_components);
}
memcount = pixelcount * 4;
row_stride = cinfo.output_width * cinfo.output_components;
out = ri.Malloc(memcount);
*width = cinfo.output_width;
*height = cinfo.output_height;
/* Step 6: while (scan lines remain to be read) */
/* jpeg_read_scanlines(...); */
/* Here we use the library's state variable cinfo.output_scanline as the
* loop counter, so that we don't have to keep track ourselves.
*/
while (cinfo.output_scanline < cinfo.output_height) {
/* jpeg_read_scanlines expects an array of pointers to scanlines.
* Here the array is only one element long, but you could ask for
* more than one scanline at a time if that's more convenient.
*/
buf = ((out+(row_stride*cinfo.output_scanline)));
buffer = &buf;
(void) jpeg_read_scanlines(&cinfo, buffer, 1);
}
buf = out;
// Expand from RGB to RGBA
sindex = pixelcount * cinfo.output_components;
dindex = memcount;
do
{
buf[--dindex] = 255;
buf[--dindex] = buf[--sindex];
buf[--dindex] = buf[--sindex];
buf[--dindex] = buf[--sindex];
} while(sindex);
*pic = out;
/* Step 7: Finish decompression */
jpeg_finish_decompress(&cinfo);
/* We can ignore the return value since suspension is not possible
* with the stdio data source.
*/
/* Step 8: Release JPEG decompression object */
/* This is an important step since it will release a good deal of memory. */
jpeg_destroy_decompress(&cinfo);
/* After finish_decompress, we can close the input file.
* Here we postpone it until after no more JPEG errors are possible,
* so as to simplify the setjmp error logic above. (Actually, I don't
* think that jpeg_destroy can do an error exit, but why assume anything...)
*/
ri.FS_FreeFile (fbuffer.v);
/* At this point you may want to check to see whether any corrupt-data
* warnings occurred (test whether jerr.pub.num_warnings is nonzero).
*/
/* And we're done! */
}
示例2: R_LoadPCX
void R_LoadPCX ( const char *filename, byte **pic, int *width, int *height)
{
union {
byte *b;
void *v;
} raw;
byte *end;
pcx_t *pcx;
int len;
unsigned char dataByte = 0, runLength = 0;
byte *out, *pix;
unsigned short w, h;
byte *pic8;
byte *palette;
int i;
unsigned size = 0;
if (width)
*width = 0;
if (height)
*height = 0;
*pic = NULL;
//
// load the file
//
len = ri.FS_ReadFile( ( char * ) filename, &raw.v);
if (!raw.b || len < 0) {
return;
}
if((unsigned)len < sizeof(pcx_t))
{
ri.Printf (PRINT_ALL, "PCX truncated: %s\n", filename);
ri.FS_FreeFile (raw.v);
return;
}
//
// parse the PCX file
//
pcx = (pcx_t *)raw.b;
end = raw.b+len;
w = LittleShort(pcx->xmax)+1;
h = LittleShort(pcx->ymax)+1;
size = w*h;
if (pcx->manufacturer != 0x0a
|| pcx->version != 5
|| pcx->encoding != 1
|| pcx->color_planes != 1
|| pcx->bits_per_pixel != 8
|| w >= 1024
|| h >= 1024)
{
ri.Printf (PRINT_ALL, "Bad or unsupported pcx file %s (%dx%[email protected]%d)\n", filename, w, h, pcx->bits_per_pixel);
return;
}
pix = pic8 = ri.Malloc ( size );
raw.b = pcx->data;
// FIXME: should use bytes_per_line but original q3 didn't do that either
while(pix < pic8+size)
{
if(runLength > 0) {
*pix++ = dataByte;
--runLength;
continue;
}
if(raw.b+1 > end)
break;
dataByte = *raw.b++;
if((dataByte & 0xC0) == 0xC0)
{
if(raw.b+1 > end)
break;
runLength = dataByte & 0x3F;
dataByte = *raw.b++;
}
else
runLength = 1;
}
if(pix < pic8+size)
{
ri.Printf (PRINT_ALL, "PCX file truncated: %s\n", filename);
ri.FS_FreeFile (pcx);
ri.Free (pic8);
}
if (raw.b-(byte*)pcx >= end - (byte*)769 || end[-769] != 0x0c)
{
ri.Printf (PRINT_ALL, "PCX missing palette: %s\n", filename);
ri.FS_FreeFile (pcx);
ri.Free (pic8);
return;
//.........这里部分代码省略.........
示例3: R_LoadTGA
void R_LoadTGA ( const char *name, byte **pic, int *width, int *height)
{
unsigned columns, rows, numPixels;
byte *pixbuf;
int row, column;
byte *buf_p;
byte *end;
union {
byte *b;
void *v;
} buffer;
TargaHeader targa_header;
byte *targa_rgba;
int length;
*pic = NULL;
if(width)
*width = 0;
if(height)
*height = 0;
//
// load the file
//
length = ri.FS_ReadFile ( ( char * ) name, &buffer.v);
if (!buffer.b || length < 0) {
return;
}
if(length < 18)
{
ri.Error( ERR_DROP, "LoadTGA: header too short (%s)", name );
}
buf_p = buffer.b;
end = buffer.b + length;
targa_header.id_length = buf_p[0];
targa_header.colormap_type = buf_p[1];
targa_header.image_type = buf_p[2];
memcpy(&targa_header.colormap_index, &buf_p[3], 2);
memcpy(&targa_header.colormap_length, &buf_p[5], 2);
targa_header.colormap_size = buf_p[7];
memcpy(&targa_header.x_origin, &buf_p[8], 2);
memcpy(&targa_header.y_origin, &buf_p[10], 2);
memcpy(&targa_header.width, &buf_p[12], 2);
memcpy(&targa_header.height, &buf_p[14], 2);
targa_header.pixel_size = buf_p[16];
targa_header.attributes = buf_p[17];
targa_header.colormap_index = LittleShort(targa_header.colormap_index);
targa_header.colormap_length = LittleShort(targa_header.colormap_length);
targa_header.x_origin = LittleShort(targa_header.x_origin);
targa_header.y_origin = LittleShort(targa_header.y_origin);
targa_header.width = LittleShort(targa_header.width);
targa_header.height = LittleShort(targa_header.height);
buf_p += 18;
if (targa_header.image_type!=2
&& targa_header.image_type!=10
&& targa_header.image_type != 3 )
{
ri.Error (ERR_DROP, "LoadTGA: Only type 2 (RGB), 3 (gray), and 10 (RGB) TGA images supported");
}
if ( targa_header.colormap_type != 0 )
{
ri.Error( ERR_DROP, "LoadTGA: colormaps not supported" );
}
if ( ( targa_header.pixel_size != 32 && targa_header.pixel_size != 24 ) && targa_header.image_type != 3 )
{
ri.Error (ERR_DROP, "LoadTGA: Only 32 or 24 bit images supported (no colormaps)");
}
columns = targa_header.width;
rows = targa_header.height;
numPixels = columns * rows * 4;
if(!columns || !rows || numPixels > 0x7FFFFFFF || numPixels / columns / 4 != rows)
{
ri.Error (ERR_DROP, "LoadTGA: %s has an invalid image size", name);
}
targa_rgba = ri.Malloc (numPixels);
if (targa_header.id_length != 0)
{
if (buf_p + targa_header.id_length > end)
ri.Error( ERR_DROP, "LoadTGA: header too short (%s)", name );
buf_p += targa_header.id_length; // skip TARGA image comment
}
if ( targa_header.image_type==2 || targa_header.image_type == 3 )
{
//.........这里部分代码省略.........