2

我是图像处理的新手。我能够使用 Boost 通用图像库 ( Boost::GIL) 在常见格式之间进行转换,例如BitmapsJPEGPNGTIFF. 现在,我想使用 openjpeg 库将任何常见格式转换为jpeg2000.

下面是我的图像包装类。该boost::gil::rgb8_image_t变量包含图像信息,例如宽度、高度、通道数、像素等。

class image_wrapper {

private:
    boost::gil::rgb8_image_t _img;

public:
    image_wrapper() = default;
    enum class image_type : uint8_t { JPEG = 1, BMP = 2, TIFF = 3, PNG = 4, JPEG2000 = 5 };

    void read_in_image(const std::string& filename);
    void read_in_image(std::vector<uint8_t>& bytes);
    void write_out_image(const std::string& file_name, image_type img_type);
};

我想使用pixel map来自变量的未编码图像数据 ()boost::gil::rgb8_image_t作为中间格式,将任何常见格式转换为jpeg2000. pixel map存储在一维向量uint8_t中。我想将该向量存储到一个 openjpeg ( opj_image_t) 对象中。

bitmap通过查看 openjpeg 源代码,有一个函数可以将数据数组转换为opj_image_t对象。我怎么能做同样的事情来boost::gil::rgb8_image_t转换opj_image_t

这是来自 openjpeg 库的代码:

static void bmp24toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_image_t* image){
int index;
OPJ_UINT32 width, height;
OPJ_UINT32 x, y;
const OPJ_UINT8* pSrc = NULL;

width = image->comps[0].w;
height = image->comps[0].h;
index = 0;
pSrc = pData + (height - 1U) * stride;
for (y = 0; y < height; y++) {
    for (x = 0; x < width; x++) {
        image->comps[0].data[index] = (OPJ_INT32)pSrc[3 * x + 2]; /* R */
        image->comps[1].data[index] = (OPJ_INT32)pSrc[3 * x + 1]; /* G */
        image->comps[2].data[index] = (OPJ_INT32)pSrc[3 * x + 0]; /* B */
        index++;
    }
    pSrc -= stride;
}

链接到包含代码的 openjpeg 文件:https ://github.com/uclouvain/openjpeg/blob/master/src/bin/jp2/convertbmp.c

4

0 回答 0