本文整理汇总了C++中BitmapData::GetBufferPitch方法的典型用法代码示例。如果您正苦于以下问题:C++ BitmapData::GetBufferPitch方法的具体用法?C++ BitmapData::GetBufferPitch怎么用?C++ BitmapData::GetBufferPitch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitmapData
的用法示例。
在下文中一共展示了BitmapData::GetBufferPitch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadJPEG
//--------------------------------------------------------------------------------
BitmapData* LoadJPEG(const Path& in_file)
{
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
FILE *infile;
JSAMPARRAY buffer;
FOPEN(&infile, in_file.GetData(), L("rb"));
if (infile == nullptr)
{
Assert(false);
return nullptr;
}
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
if (setjmp(jerr.setjmp_buffer))
{
jpeg_destroy_decompress(&cinfo);
fclose(infile);
return nullptr;
}
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, infile);
jpeg_read_header(&cinfo, true);
jpeg_start_decompress(&cinfo);
BufferFormat eFormat = BufferFormat::INVALID_FORMAT;
switch (cinfo.out_color_space)
{
case JCS_EXT_ABGR: eFormat = BufferFormat::RGBA_U32; break;
case JCS_EXT_BGRA: eFormat = BufferFormat::ARGB_U32; break;
case JCS_EXT_RGBA: eFormat = BufferFormat::ABGR_U32; break;
case JCS_RGB: eFormat = BufferFormat::BGR_U24; break;
case JCS_EXT_BGR: eFormat = BufferFormat::RGB_U24; break;
//case JCS_RGB565: eFormat = BufferFormat::R5G6B5_U16; break;
case JCS_GRAYSCALE: eFormat = BufferFormat::A_U8; break;
default:
Assert(false);
return nullptr;
}
BitmapData* pData = new BitmapData(cinfo.output_width, cinfo.output_height, eFormat);
buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr)&cinfo, JPOOL_IMAGE, pData->GetBufferPitch(), 1);
while (cinfo.output_scanline < cinfo.output_height)
{
jpeg_read_scanlines(&cinfo, buffer, 1);
memcpy((u8*)&(pData->GetBuffer()[(cinfo.output_scanline-1) * pData->GetBufferPitch()]), buffer[0], pData->GetBufferPitch());
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
fclose(infile);
Assert(jerr.pub.num_warnings == 0);
return pData;
}