GreycLab / CImg

The CImg Library is a small and open-source C++ toolkit for image processing
http://cimg.eu
Other
1.49k stars 285 forks source link

Support for BGR image interleaved. #397

Open cgringmuth opened 1 year ago

cgringmuth commented 1 year ago

Hi, I have an image buffer with BGR interleaved. It is not clear to me, how to represent this correctly in CImg.

CImg<unsigned char> img = CImg<unsigned char>(buffter,3,W,H).permute_axes("zyxc"); Somewhat does the trick, but the color is still wrong. Can you tell me, what I'm doing wrong?

Best.

dtschump commented 1 year ago

I'd say it should be:

CImg<unsigned char> img = CImg<unsigned char>(buffter,3,W,H).permute_axes("yzcx");
cgringmuth commented 1 year ago

Wow... this was fast. Thx I was wondering something else. Is this code snippet correct?

      default : {
        cimg_forY(*this,y) {
          cimg_forX(*this,x) {
            std::fputc((unsigned char)(*(ptr_b++)),nfile);
            std::fputc((unsigned char)(*(ptr_g++)),nfile);
            std::fputc((unsigned char)(*(ptr_r++)),nfile);
          }
          cimg::fwrite(align_buf,align,nfile);
          ptr_r-=2*_width; ptr_g-=2*_width; ptr_b-=2*_width;
        }

In my limited understanding it first save blue, then green and then red. But I though BMP saves RGB instead? You can find this in _save_bmp.

dtschump commented 1 year ago

In my limited understanding if first save blue, then green and then red.

That is what it does indeed. If it's like this in save_bmp, then it's probably how the data are stored in a .bmp file.