3

I'm new to image processing. I was able to use the Boost Generic Image Library (Boost::GIL) to convert between common formats such as Bitmaps, JPEG, PNG, and TIFF. Now, I want to use the openjpeg library to convert any common format to jpeg2000.

Below is my image wrapper class. The boost::gil::rgb8_image_t variable contains image information such as width, height, number of channels, pixels, etc.

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);
};

I want to use the unencoded image data (pixel map) from the boost::gil::rgb8_image_t variable as the intermediate format to convert any common format to jpeg2000. The pixel map is stored in a 1D uint8_t vector. I want to store that vector into an openjpeg (opj_image_t) object.

By looking at the openjpeg source code, there's a function to convert an array of bitmap data to an opj_image_t object. How could I do the same thing to convert boost::gil::rgb8_image_t to opj_image_t?

Here is the code from the openjpeg library:

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;
}

Link to the openjpeg file that contains the code: https://github.com/uclouvain/openjpeg/blob/master/src/bin/jp2/convertbmp.c

sehe
  • 374,641
  • 47
  • 450
  • 633
BunRieuCua
  • 53
  • 4
  • 1
    Is this question still relevant? I never saw this. Here's some answers that might help: https://stackoverflow.com/questions/61656110/how-to-read-image-info-from-python-bytes-string-using-boostgil/61670231#61670231, https://stackoverflow.com/questions/61656110/how-to-read-image-info-from-python-bytes-string-using-boostgil/61670231#61670231, https://stackoverflow.com/questions/43953630/how-to-load-a-tiff-image-like-a-graph-in-c-boost/43958550#43958550 (too lazy to check which one matches your direction of conversion :)) – sehe Nov 22 '21 at 23:30
  • Thanks for your suggestions. I still don't know how to get boost::gil to work with openjpeg. I'm stuck on converting any common format such png, jpeg, tiff, bmp to jpeg2000. Your previous answer helped me handle a different format called WSQ. The issue is from the openjpeg library, not the boost::gil library. I'm not sure how to get the pixmap of an image that I can get from boost::gil to work with the functions in the openjpeg library – BunRieuCua Nov 24 '21 at 00:36

0 Answers0