目标
我正在尝试使用 Boost GIL 来替换我已经实现的一些类似功能,这些功能即将达到其可维护生命周期的尽头。
我现有的代码适用于 24 BPP、8 位 RGB 图像,使用uint8_t*
. 我无法改变这一点,因为相同的接口用于从不同的地方(例如 OpenGL 缓冲区)公开图像,并且已经有相当多的代码。
因此,我尝试以小步骤使用 GIL,首先读取文件并将像素逐字节复制到std::vector<uint8_t>
可用于管理存储的 a 中,但仍然uint8_t*
通过使用&vector[0]
.
这可以透明地放在现有接口后面,直到重构有意义为止。
我试过的
我认为这应该是使用copy_pixels()
两个适当构造的视图的简单案例。
我整理了一个最小的、完整的示例,说明了我通过查看文档和尝试实现的目标的总和:
#include <boost/gil/rgb.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>
#include <stdint.h>
#include <vector>
int main() {
std::vector<uint8_t> storage;
{
using namespace boost::gil;
rgb8_image_t img;
png_read_image("test.png", img);
// what should replace 3 here to be more "generic"?
storage.resize(img.width()*img.height()*3);
// doesn't work, the type of the images aren't compatible.
copy_pixels(const_view(img),
interleaved_view(img.width(), img.height(), &storage[0], 3*img.width()));
}
}
我被困在哪里
这不编译:
error: cannot convert ‘const boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >’ to ‘unsigned char’ in assignment
这是相当不言自明的 - RGB 像素不能unsigned char
自动转换为单个像素。我想我会尝试使用copy_and_convert_pixels()
来解决这个问题,但我看不到unsigned char
解决这些转换问题的 3:1(即我在输出中为源图像中的每个像素都有 3 秒)问题的方法。转换似乎更针对色彩空间转换(例如 RGB->HSV)或包装更改。