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

screenshot on windows #2

Open
lynnux opened this issue Sep 18, 2017 · 1 comment
Open

screenshot on windows #2

lynnux opened this issue Sep 18, 2017 · 1 comment

Comments

@lynnux
Copy link

lynnux commented Sep 18, 2017

I have implement screenshot in C, and I found a way not need flip_rows on windows.

BITMAPINFOHEADER bih = {0};
    bih.biBitCount = bmp.bmBitsPixel;
    bih.biCompression = BI_RGB;
    bih.biHeight = - bmp.bmHeight;   // set this to negative

and there need to convert bgra to rgba

unsigned char* bgra2rgba(unsigned char* buf, DWORD size)
{
    if(0 == size % 4)
    {
        unsigned char* ret = new unsigned char[size]; // new alloc is only need for my own project
        memcpy(ret, buf, size);
        DWORD all_chunks = size / 4;
        for(DWORD i = 0; i< all_chunks; ++i)
        {
            ret[i*4+2] = buf[i*4]; // swap b, r
            ret[i*4] = buf[i*4+2];
            ret[i*4+3] = 255; // alpha channel: XP need this
        }
        return ret;
    }
    return 0;
}
@EddieIvan01
Copy link

Just set BITMAPINFOHEADER.biHeight to negative and do

fn bgra2rgba(input: &mut [u8], width: i32, height: i32) {
    let mut offset = 0;

    for _ in 0..height * width {
        let tmp = input[offset];
        input[offset] = input[offset + 2];
        input[offset + 2] = tmp;
        offset += 4;
    }
}

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