Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for BGR image interleaved. #397

Open
cgringmuth opened this issue Sep 11, 2023 · 3 comments
Open

Support for BGR image interleaved. #397

cgringmuth opened this issue Sep 11, 2023 · 3 comments

Comments

@cgringmuth
Copy link

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
Copy link
Collaborator

dtschump commented Sep 11, 2023

I'd say it should be:

CImg<unsigned char> img = CImg<unsigned char>(buffter,3,W,H).permute_axes("yzcx");

@cgringmuth
Copy link
Author

cgringmuth commented Sep 11, 2023

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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants