Using Boost.GIL to convert an image into “raw” bytes

后端 未结 4 1578
星月不相逢
星月不相逢 2021-01-06 09:53

Goal

I\'m trying to move towards Boost GIL to replace some similar functionality I\'ve implemented that is reaching the end of its maintainable life.

I have

4条回答
  •  别那么骄傲
    2021-01-06 10:21

    I would just push_back each color of the rgb8_pixel_t individually:

    struct PixelInserter{
            std::vector* storage;
            PixelInserter(std::vector* s) : storage(s) {}
            void operator()(boost::gil::rgb8_pixel_t p) const {
                    storage->push_back(boost::gil::at_c<0>(p));
                    storage->push_back(boost::gil::at_c<1>(p));
                    storage->push_back(boost::gil::at_c<2>(p));
            }
    };
    
    int main() {
      std::vector storage;
      {
        using namespace boost::gil;
        rgb8_image_t img;
        png_read_image("test.png", img);
        storage.reserve(img.width() * img.height() * num_channels());
        for_each_pixel(const_view(img), PixelInserter(&storage));
      }
    ...
    }
    

    ...but I'm not an expert on GIL either.

提交回复
热议问题