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

Render to gray-scale #19

Closed
OriBibi opened this issue Dec 9, 2020 · 1 comment
Closed

Render to gray-scale #19

OriBibi opened this issue Dec 9, 2020 · 1 comment
Labels
question Further information is requested

Comments

@OriBibi
Copy link

OriBibi commented Dec 9, 2020

Your library set Bitmap to be RGBA only. The RenderToBitmap function is good but I need RenderToGrayScale function. Is it possible to add support or any conversion option to gray-scale as well?

@sammycage
Copy link
Owner

Bitmap to GrayScale

    for (uint32_t y = 0; y < bitmap.height(); y++) {
        uint8_t* row = bitmap.data() + bitmap.stride() * y;
        for (uint32_t x = 0; x < bitmap.width(); x++) {
            uint32_t r = row[0];
            uint32_t g = row[1];
            uint32_t b = row[2];

            uint32_t l = (r * 299 + g * 587 + b * 114);

            row[0] = row[1] = row[2] = uint8_t(l / 1000);

            row += 4;
        }
    }

@sammycage sammycage added the question Further information is requested label Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants