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 1-bit-per-pixel ImageData #311

Open
mboedigh opened this issue Jun 26, 2019 · 0 comments
Open

support 1-bit-per-pixel ImageData #311

mboedigh opened this issue Jun 26, 2019 · 0 comments

Comments

@mboedigh
Copy link

SC2 now has 1-bit-per pixel imagedata for pathable_grid and placement_grid. SampleImageData needs to detect this and parse the image correctly. I don't know how to do a pull-request, but I think something like this works: Just replace two of the SampleImageData functions with the ones below.

    inline int8_t getBit(std::string const& str, int j)
    {
        div_t d = div(j, 8);
        unsigned char data = str[d.quot] >> (7 - d.rem);
        return  data & 1;
    }
    static bool SampleImageBit(const std::string& data, int width, int height, const Point2D& point, unsigned char& result) {
        Point2DI pointI(int(point.x), int(point.y));
        if (pointI.x < 0 || pointI.x >= width || pointI.y < 0 || pointI.y >= height) {
            return false;
        }

        //const int idx = pointI.x + (height - 1 - pointI.y) * width;
        const int idx = pointI.x + pointI.y * width;
        result = getBit(data, idx);
        return true;
    }

    static bool SampleImageData(const SC2APIProtocol::ImageData& data, const Point2D& point, unsigned char& result) {
        if (data.bits_per_pixel() == 1)
            return SampleImageBit(data.data(), data.size().x(), data.size().y(), point, result);
        else if (data.bits_per_pixel() == 8)
            return SampleImageData(data.data(), data.size().x(), data.size().y(), point, result);
        else
            return false;
    }

    static bool SampleImageData(const ImageData& data, const Point2D& point, unsigned char& result) {
        if (data.bits_per_pixel == 1)
            return SampleImageBit(data.data, data.width, data.height, point, result);
        else if (data.bits_per_pixel == 8)
            return SampleImageData(data.data, data.width, data.height, point, result);
        else
            return false;
    }
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

1 participant