本文整理汇总了C++中span::size_bytes方法的典型用法代码示例。如果您正苦于以下问题:C++ span::size_bytes方法的具体用法?C++ span::size_bytes怎么用?C++ span::size_bytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类span
的用法示例。
在下文中一共展示了span::size_bytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DetectImageFormat
ImageFileInfo DetectImageFormat(span<uint8_t> data) {
ImageFileInfo info;
stbi__context ctx;
stbi__start_mem(&ctx, &data[0], data.size_bytes());
int comp;
if (stbi__bmp_info(&ctx, &info.width, &info.height, &comp)) {
info.hasAlpha = (comp == 4);
info.format = ImageFileFormat::BMP;
return info;
}
TjDecompressHandle handle;
if (tjDecompressHeader(handle, &data[0], data.size_bytes(), &info.width, &info.height) == 0) {
info.hasAlpha = false;
info.format = ImageFileFormat::JPEG;
return info;
}
if (DetectTga(data, info)) {
return info;
}
// Not a very good heuristic
if (data.size() == 256 * 256) {
info.width = 256;
info.height = 256;
info.hasAlpha = true;
info.format = ImageFileFormat::FNTART;
return info;
}
return info;
}
示例2: TempleException
std::unique_ptr<uint8_t[]> DecodeJpeg(const span<uint8_t> data) {
TjDecompressHandle handle;
int w, h;
tjDecompressHeader(handle, &data[0], data.size_bytes(), &w, &h);
std::unique_ptr<uint8_t[]> result(new uint8_t[w * h * 4]);
auto status = tjDecompress2(handle, &data[0], data.size_bytes(), &result[0], w, w * 4, h, TJPF_BGRX, 0);
if (status != 0) {
throw TempleException("Unable to decompress jpeg image: {}",
tjGetErrorStr());
}
return result;
}
示例3: DecodeImage
DecodedImage DecodeImage(const span<uint8_t> data) {
DecodedImage result;
result.info = DetectImageFormat(data);
stbi__context ctx;
stbi__start_mem(&ctx, &data[0], data.size_bytes());
int w, h, comp;
switch (result.info.format) {
case ImageFileFormat::BMP:
result.data.reset(stbi__bmp_load(&ctx, &w, &h, &comp, 4));
break;
case ImageFileFormat::JPEG:
result.data = DecodeJpeg(data);
break;
case ImageFileFormat::TGA:
result.data = DecodeTga(data);
break;
case ImageFileFormat::FNTART:
return DecodeFontArt(data);
default:
case ImageFileFormat::Unknown:
throw TempleException("Unrecognized image format.");
}
return result;
}