本文整理汇总了C++中Reference::data方法的典型用法代码示例。如果您正苦于以下问题:C++ Reference::data方法的具体用法?C++ Reference::data怎么用?C++ Reference::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reference
的用法示例。
在下文中一共展示了Reference::data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doHideCursor
//! ---|> Window
void WindowSDL::doHideCursor() {
static std::unique_ptr<Cursor> hiddenCursor;
if(hiddenCursor.get() == nullptr) {
Reference<Bitmap> bitmap = new Bitmap(1, 1);
bitmap->data()[0] = 0;
bitmap->data()[1] = 0;
bitmap->data()[2] = 0;
bitmap->data()[3] = 0;
hiddenCursor = createCursor(bitmap, 0, 0);
}
doSetCursor(hiddenCursor.get());
}
示例2: readData
Reference<Bitmap> StreamerPNG::loadBitmap(std::istream & input) {
char header[8];
input.read(header, 8);
const int is_png = !png_sig_cmp(reinterpret_cast<png_byte *>(header), 0, 8);
if(!is_png) {
WARN("File is not a valid PNG image.");
return nullptr;
}
// Set up the necessary structures for libpng.
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if(!png_ptr) {
return nullptr;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if(!info_ptr) {
png_destroy_read_struct(&png_ptr, static_cast<png_infopp>(nullptr), static_cast<png_infopp>(nullptr));
return nullptr;
}
if(setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr, static_cast<png_infopp>(nullptr));
return nullptr;
}
struct PNGFunctions {
static void readData(png_structp read_ptr, png_bytep data, png_size_t length) {
std::istream * in = reinterpret_cast<std::istream *>(png_get_io_ptr(read_ptr));
if(in == nullptr || !in->good()) {
png_error(read_ptr, "Error in input stream.");
}
in->read(reinterpret_cast<char *>(data), static_cast<std::streamsize>(length));
if(in->gcount() != static_cast<std::streamsize>(length)) {
png_error(read_ptr, "Requested amount of data could not be extracted from input stream");
}
}
};
png_set_read_fn(png_ptr, reinterpret_cast<png_voidp>(&input), PNGFunctions::readData);
png_set_sig_bytes(png_ptr, 8);
png_read_info(png_ptr, info_ptr);
png_uint_32 width;
png_uint_32 height;
int bit_depth;
int color_type;
png_get_IHDR( png_ptr, info_ptr,
&width, &height,
&bit_depth, &color_type, nullptr, nullptr, nullptr);
PixelFormat pixelFormat = PixelFormat::RGB;
switch(color_type) {
case PNG_COLOR_TYPE_GRAY:
// Convert bpp less than 8 to 8 bits.
if(bit_depth < 8) {
png_set_expand_gray_1_2_4_to_8(png_ptr);
}
pixelFormat = PixelFormat::MONO;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
// Convert grayscale with alpha to RGBA.
png_set_expand(png_ptr);
png_set_gray_to_rgb(png_ptr);
pixelFormat = PixelFormat::RGBA;
break;
case PNG_COLOR_TYPE_PALETTE:
// Convert color palette to RGB(A).
png_set_expand(png_ptr);
// Check if the color palette contains transparent colors.
#if PNG_LIBPNG_VER >= 10300
if(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)){
pixelFormat = PixelFormat::RGBA;
}
#else
if(info_ptr->valid & PNG_INFO_tRNS) {
pixelFormat = PixelFormat::RGBA;
}
#endif
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
pixelFormat = PixelFormat::RGBA;
break;
default:
// Already set to RGB above.
break;
}
// Convert 16 bpp to 8 bits.
if (bit_depth == 16) {
png_set_strip_16(png_ptr);
}
// Create the bitmap to store the data.
Reference<Bitmap> bitmap = new Bitmap(width, height, pixelFormat);
auto row_pointers = new png_bytep[height];
const uint8_t bytes = pixelFormat.getBytesPerPixel();
//.........这里部分代码省略.........