Merge pull request #115 from yamt/inspect-opencv-tweak

inspect-opencv: Make the display similar to the SDL version
This commit is contained in:
Daniel Beer 2021-08-27 13:37:05 +12:00 committed by GitHub
commit 00d5e968b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,21 +27,43 @@ using namespace cv;
#include "dbgutil.h" #include "dbgutil.h"
/* /*
* Macros to conver a color from the SDL_gfxprimitive style format. * Macros to convert a color from the SDL/SDL_gfxprimitive style format.
* bpp=4, little-endian. *
* Note: we don't use alpha values and thus ignore them.
*/
/*
* The format used for a frame with bpp=4, little-endian.
*/
#define RAW_R(c) ((c) & 0xff)
#define RAW_G(c) ((c >> 8) & 0xff)
#define RAW_B(c) ((c >> 16) & 0xff)
/*
* SDL_gfx color is 0xRRGGBBAA
* https://www.ferzkopp.net/Software/SDL_gfx-2.0/Docs/html/index.html
*/
#define R(c) ((c >> 24) & 0xff)
#define G(c) ((c >> 16) & 0xff)
#define B(c) ((c >> 8) & 0xff)
#define A(c) (c & 0xff)
/*
* OpenCV color is BGR.
*/ */
#define R(c) ((c) & 0xff)
#define G(c) ((c >> 8) & 0xff)
#define B(c) ((c >> 16) & 0xff)
#define COLOR(c) Scalar(B(c), G(c), R(c)) #define COLOR(c) Scalar(B(c), G(c), R(c))
static double scale = 1.0;
static void stringColor(Mat &screen, int x, int y, const char *text, static void stringColor(Mat &screen, int x, int y, const char *text,
uint32_t color) uint32_t color)
{ {
static const int font = FONT_HERSHEY_PLAIN; static const int font = FONT_HERSHEY_PLAIN;
static const int thickness = 4; static const int thickness = scale;
static const double font_scale = 4.0; static const double font_scale = scale;
putText(screen, text, Point(x, y), font, font_scale, COLOR(color), putText(screen, text, Point(x, y), font, font_scale, COLOR(color),
thickness); thickness);
@ -59,10 +81,22 @@ static void pixelColor(Mat &screen, int x, int y, uint32_t color)
screen_pixel[2] = R(color); screen_pixel[2] = R(color);
} }
static void pixelColorRaw(Mat &screen, int x, int y, uint32_t rawColor)
{
if (x < 0 || y < 0 || x >= screen.cols || y >= screen.rows) {
return;
}
Vec3b &screen_pixel = screen.at<Vec3b>(y, x);
screen_pixel[0] = RAW_B(rawColor);
screen_pixel[1] = RAW_G(rawColor);
screen_pixel[2] = RAW_R(rawColor);
}
static void lineColor(Mat &screen, int x1, int y1, int x2, int y2, static void lineColor(Mat &screen, int x1, int y1, int x2, int y2,
uint32_t color) uint32_t color)
{ {
line(screen, Point(x1, y1), Point(x2, y2), COLOR(color), 8); line(screen, Point(x1, y1), Point(x2, y2), COLOR(color), scale);
} }
static void dump_info(struct quirc *q) static void dump_info(struct quirc *q)
@ -125,7 +159,7 @@ static void draw_frame(Mat &screen, struct quirc *q)
break; break;
} }
pixelColor(screen, x, y, color); pixelColorRaw(screen, x, y, color);
} }
} }
} }