smasherprog / screen_capture_lite

cross platform screen/window capturing library
MIT License
638 stars 156 forks source link

Add some Extract and Convert #27

Closed namkazt closed 7 years ago

namkazt commented 7 years ago

here is some more extract and convert would be useful to stream.

inline void ExtractAndConvertToRGB(const Image& img, char* dst, size_t dst_size)
        {
            auto totalsize = Width(img) * 3 * Height(img);
            assert(dst_size >= static_cast<size_t>(totalsize));
            auto imgsrc = StartSrc(img);
            auto imgdist = dst;
            for (auto h = 0; h < Height(img); h++) {
                for (auto w = 0; w < Width(img); w++) {
                    *imgdist++ = *(imgsrc + 2);
                    *imgdist++ = *(imgsrc + 1);
                    *imgdist++ = *(imgsrc);
                    imgsrc += img.Pixelstride;
                }
                imgsrc += RowPadding(img);
            }
        }

        inline void ExtractAndConvertToRGB565(const Image& img, char* dst, size_t dst_size)
        {
            auto totalsize = Width(img) * 2 * Height(img);
            assert(dst_size >= static_cast<size_t>(totalsize));
            auto imgsrc = StartSrc(img);
            auto imgdist = dst;
            for (auto h = 0; h < Height(img); h++) {
                for (auto w = 0; w < Width(img); w++) {
                    int short rgb = (*(imgsrc + 2) << 11) | (*(imgsrc + 1) << 5) | *(imgsrc);
                    *imgdist++ = rgb;
                    *imgdist++ = rgb << 8;
                    imgsrc += img.Pixelstride;
                }
                imgsrc += RowPadding(img);
            }
        }
smasherprog commented 7 years ago

Merged these into master.. thanks for the improvements!