本文整理汇总了C++中ImageType::move_in方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageType::move_in方法的具体用法?C++ ImageType::move_in怎么用?C++ ImageType::move_in使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageType
的用法示例。
在下文中一共展示了ImageType::move_in方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Load
//.........这里部分代码省略.........
BOOST_STATIC_ASSERT((sizeof(gil::rgba8_pixel_t) == 4));
typedef boost::mpl::vector4<
gil::gray8_image_t,
gil::gray_alpha8_image_t,
gil::rgb8_image_t,
gil::rgba8_image_t
> ImageTypes;
typedef gil::any_image<ImageTypes> ImageType;
fs::path path(filename);
if (!fs::exists(path))
throw BadFile("Texture file \"" + filename + "\" does not exist");
if (!fs::is_regular_file(path))
throw BadFile("Texture \"file\" \"" + filename + "\" is not a file");
std::string extension = boost::algorithm::to_lower_copy(path.extension().string());
ImageType image;
try {
// First attempt -- try just to read the file in one of the default
// formats above.
#if GG_HAVE_LIBJPEG
if (extension == ".jpg" || extension == ".jpe" || extension == ".jpeg")
gil::jpeg_read_image(filename, image);
else
#endif
#if GG_HAVE_LIBPNG
if (extension == ".png")
gil::png_read_image(filename, image);
else
#endif
#if GG_HAVE_LIBTIFF
if (extension == ".tif" || extension == ".tiff")
gil::tiff_read_image(filename, image);
else
#endif
throw BadFile("Texture file \"" + filename + "\" does not have a supported file extension");
} catch (const std::ios_base::failure &) {
// Second attempt -- If *_read_image() throws, see if we can convert
// the image to RGBA. This is needed for color-indexed images.
#if GG_HAVE_LIBJPEG
if (extension == ".jpg" || extension == ".jpe" || extension == ".jpeg") {
gil::rgba8_image_t rgba_image;
gil::jpeg_read_and_convert_image(filename, rgba_image);
image.move_in(rgba_image);
}
#endif
#if GG_HAVE_LIBPNG
if (extension == ".png") {
gil::rgba8_image_t rgba_image;
gil::png_read_and_convert_image(filename, rgba_image);
image.move_in(rgba_image);
}
#endif
#if GG_HAVE_LIBTIFF
if (extension == ".tif" || extension == ".tiff") {
gil::rgba8_image_t rgba_image;
gil::tiff_read_and_convert_image(filename, rgba_image);
image.move_in(rgba_image);
}
#endif
}
m_filename = filename;
m_default_width = X(image.width());
m_default_height = Y(image.height());
m_type = GL_UNSIGNED_BYTE;
#define IF_IMAGE_TYPE_IS(image_prefix) \
if (image.current_type_is<image_prefix ## _image_t>()) { \
m_bytes_pp = sizeof(image_prefix ## _pixel_t); \
image_data = interleaved_view_get_raw_data( \
const_view(image._dynamic_cast<image_prefix ## _image_t>())); \
}
const unsigned char* image_data = 0;
IF_IMAGE_TYPE_IS(gil::gray8)
else IF_IMAGE_TYPE_IS(gil::gray_alpha8)
else IF_IMAGE_TYPE_IS(gil::rgb8)
else IF_IMAGE_TYPE_IS(gil::rgba8)
#undef IF_IMAGE_TYPE_IS
switch (m_bytes_pp) {
case 1: m_format = GL_LUMINANCE; break;
case 2: m_format = GL_LUMINANCE_ALPHA; break;
case 3: m_format = GL_RGB; break;
case 4: m_format = GL_RGBA; break;
default: throw BadFile("Texture file \"" + filename + "\" does not have a supported number of color channels (1-4)");
}
assert(image_data);
Init(m_default_width, m_default_height, image_data, m_format, m_type, m_bytes_pp, mipmap);
#endif
}