diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index 197c77208..859653694 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -195,23 +195,23 @@ void BitmapBuffer::drawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, ui } } -// -//void BitmapBuffer::invertRect(coord_t x, coord_t y, coord_t w, coord_t h, LcdFlags att) -//{ -// pixel_t color = lcdColorTable[COLOR_IDX(att)]; -// RGB_SPLIT(color, red, green, blue); -// -// for (int i=y; i 360) - angle %= 360; - float radians = float(angle) * (M_PI / 180.0f); - if (angle == 0) { - left = false; - value = 100000; - } - else if (angle == 360) { - left = true; - value = 100000; - } - else if (angle >= 180) { - left = true; - value = -(cosf(radians) * 100 / sinf(radians)); - } - else { - left = false; - value = (cosf(radians) * 100 / sinf(radians)); - } +public: + explicit Slope(int angle) { + if (angle < 0) + angle += 360; + if (angle > 360) + angle %= 360; + float radians = float(angle) * (M_PI / 180.0f); + if (angle == 0) { + left = false; + value = 100000; } + else if (angle == 360) { + left = true; + value = 100000; + } + else if (angle >= 180) { + left = true; + value = -(cosf(radians) * 100 / sinf(radians)); + } + else { + left = false; + value = (cosf(radians) * 100 / sinf(radians)); + } + } - Slope(bool left, int value): + Slope(bool left, int value): left(left), value(value) - { - } + { + } - bool isBetween(const Slope & start, const Slope & end) const - { - if (left) { - if (start.left) { - if (end.left) - return end.value > start.value ? (value <= end.value && value >= start.value) : (value <= end.value || value >= start.value); - else - return value >= start.value; - } - else { - if (end.left) - return value <= end.value; - else - return end.value > start.value; - } + bool isBetween(const Slope & start, const Slope & end) const + { + if (left) { + if (start.left) { + if (end.left) + return end.value > start.value ? (value <= end.value && value >= start.value) : (value <= end.value || value >= start.value); + else + return value >= start.value; } else { - if (start.left) { - if (end.left) - return start.value > end.value; - else - return value >= end.value; - } - else { - if (end.left) - return value <= start.value; - else - return end.value < start.value ? (value >= end.value && value <= start.value) : (value <= start.value || value >= end.value); - } + if (end.left) + return value <= end.value; + else + return end.value > start.value; } } - - Slope & invertVertical() - { - value = -value; - return *this; + else { + if (start.left) { + if (end.left) + return start.value > end.value; + else + return value >= end.value; + } + else { + if (end.left) + return value <= start.value; + else + return end.value < start.value ? (value >= end.value && value <= start.value) : (value <= start.value || value >= end.value); + } } + } - Slope & invertHorizontal() - { - left = !left; - return *this; - } + Slope & invertVertical() + { + value = -value; + return *this; + } - protected: - bool left; - int value; + Slope & invertHorizontal() + { + left = !left; + return *this; + } + +protected: + bool left; + int value; }; void BitmapBuffer::drawAnnulusSector(coord_t x, coord_t y, coord_t internalRadius, coord_t externalRadius, int startAngle, int endAngle, LcdFlags flags) @@ -667,39 +667,43 @@ void drawSolidRect(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h // } //} // -//void BitmapBuffer::drawBitmapPatternPie(coord_t x0, coord_t y0, const uint8_t * img, LcdFlags flags, int startAngle, int endAngle) -//{ -// coord_t width = *((uint16_t *)img); -// coord_t height = *(((uint16_t *)img)+1); -// const uint8_t * q = img+4; -// -// int slopes[4]; -// if (!evalSlopes(slopes, startAngle, endAngle)) -// return; -// -// pixel_t color = lcdColorTable[COLOR_IDX(flags)]; -// -// int w2 = width/2; -// int h2 = height/2; -// -// for (int y=h2-1; y>=0; y--) { -// for (int x=w2-1; x>=0; x--) { -// int slope = (x==0 ? (y<0 ? -99000 : 99000) : y*100/x); -// if (slope >= slopes[0] && slope < slopes[1]) { -// drawAlphaPixel(x0+w2+x, y0+h2-y, q[(h2-y)*width + w2+x], color); -// } -// if (-slope >= slopes[0] && -slope < slopes[1]) { -// drawAlphaPixel(x0+w2+x, y0+h2+y, q[(h2+y)*width + w2+x], color); -// } -// if (slope >= slopes[2] && slope < slopes[3]) { -// drawAlphaPixel(x0+w2-x, y0+h2-y, q[(h2-y)*width + w2-x], color); -// } -// if (-slope >= slopes[2] && -slope < slopes[3]) { -// drawAlphaPixel(x0+w2-x, y0+h2+y, q[(h2+y)*width + w2-x], color); -// } -// } -// } -//} +void BitmapBuffer::drawBitmapPatternPie(coord_t x, coord_t y, const uint8_t * img, LcdFlags flags, int startAngle, int endAngle) +{ + if (endAngle == startAngle) { + endAngle += 1; + } + + Slope startSlope(startAngle); + Slope endSlope(endAngle); + + pixel_t color = lcdColorTable[COLOR_IDX(flags)]; + APPLY_OFFSET(); + + coord_t width = *((uint16_t *)img); + coord_t height = *(((uint16_t *)img) + 1); + const uint8_t * q = img + 4; + + int w2 = width / 2; + int h2 = height / 2; + + for (int y1 = h2 - 1; y1 >= 0; y1--) { + for (int x1 = w2 - 1; x1 >= 0; x1--) { + Slope slope(false, x1 == 0 ? 99000 : y1 * 100 / x1); + if (slope.isBetween(startSlope, endSlope)) { + drawAlphaPixel(x + w2 + x1, y + h2 - y1, q[(h2 - y1) * width + w2 + x1], color); + } + if (slope.invertVertical().isBetween(startSlope, endSlope)) { + drawAlphaPixel(x + w2 + x1, y + h2 + y1, q[(h2 + y1) * width + w2 + x1], color); + } + if (slope.invertHorizontal().isBetween(startSlope, endSlope)) { + drawAlphaPixel(x + w2 - x1, y + h2 + y1, q[(h2 + y1) * width + w2 - x1], color); + } + if (slope.invertVertical().isBetween(startSlope, endSlope)) { + drawAlphaPixel(x + w2 - x1, y + h2 - y1, q[(h2 - y1) * width + w2 - x1], color); + } + } + } +} BitmapBuffer * BitmapBuffer::loadBitmap(const char * filename) { @@ -1042,9 +1046,9 @@ int stbc_eof(void *user) // callbacks for stb-image const stbi_io_callbacks stbCallbacks = { - stbc_read, - stbc_skip, - stbc_eof + stbc_read, + stbc_skip, + stbc_eof }; BitmapBuffer * BitmapBuffer::load_stb(const char * filename)