Util: Start mPainter bringup with rectangle drawing

This commit is contained in:
Vicki Pfau 2023-07-23 21:43:15 -07:00
parent 369eab8da3
commit 5f35899ba3
3 changed files with 600 additions and 0 deletions

View File

@ -101,6 +101,15 @@ struct mImage {
enum mColorFormat format;
};
struct mPainter {
struct mImage* backing;
bool blend;
bool fill;
unsigned strokeWidth;
uint32_t strokeColor;
uint32_t fillColor;
};
struct VFile;
struct mImage* mImageCreate(unsigned width, unsigned height, enum mColorFormat format);
struct mImage* mImageCreateWithStride(unsigned width, unsigned height, unsigned stride, enum mColorFormat format);
@ -125,6 +134,9 @@ void mImageBlit(struct mImage* image, const struct mImage* source, int x, int y)
void mImageComposite(struct mImage* image, const struct mImage* source, int x, int y);
void mImageCompositeWithAlpha(struct mImage* image, const struct mImage* source, int x, int y, float alpha);
void mPainterInit(struct mPainter*, struct mImage* backing);
void mPainterDrawRectangle(struct mPainter*, int x, int y, int width, int height);
uint32_t mColorConvert(uint32_t color, enum mColorFormat from, enum mColorFormat to);
uint32_t mImageColorConvert(uint32_t color, const struct mImage* from, enum mColorFormat to);

View File

@ -523,6 +523,97 @@ void mImageCompositeWithAlpha(struct mImage* image, const struct mImage* source,
}
}
#define FILL_BOUNDS_INIT(X, Y, W, H) \
struct mRectangle dstRect = { \
.x = 0, \
.y = 0, \
.width = painter->backing->width, \
.height = painter->backing->height \
}; \
struct mRectangle srcRect = { \
.x = (X), \
.y = (Y), \
.width = (W), \
.height = (H) \
}; \
if (!mRectangleIntersection(&srcRect, &dstRect)) { \
return; \
} \
int dstStartX; \
int dstStartY; \
if ((X) < 0) { \
dstStartX = 0; \
} else { \
dstStartX = srcRect.x; \
} \
if ((Y) < 0) { \
dstStartY = 0; \
} else { \
dstStartY = srcRect.y; \
}
void mPainterInit(struct mPainter* painter, struct mImage* backing) {
memset(painter, 0, sizeof(*painter));
painter->backing = backing;
}
static void mPainterFillRectangle(struct mPainter* painter, int x, int y, int width, int height) {
FILL_BOUNDS_INIT(x, y, width, height);
if (!painter->blend || painter->fillColor >= 0xFF000000) {
uint32_t color = mColorConvert(painter->fillColor, mCOLOR_ARGB8, painter->backing->format);
for (y = 0; y < srcRect.height; ++y) {
uintptr_t dstPixel = (uintptr_t) PIXEL(painter->backing, dstStartX, dstStartY + y);
for (x = 0; x < srcRect.width; ++x, dstPixel += painter->backing->depth) {
PUT_PIXEL(color, dstPixel, painter->backing->depth);
}
}
} else {
for (y = 0; y < srcRect.height; ++y) {
uintptr_t dstPixel = (uintptr_t) PIXEL(painter->backing, dstStartX, dstStartY + y);
for (x = 0; x < srcRect.width; ++x, dstPixel += painter->backing->depth) {
uint32_t color;
GET_PIXEL(color, dstPixel, painter->backing->depth);
color = mColorConvert(color, painter->backing->format, mCOLOR_ARGB8);
color = mColorMixARGB8(painter->fillColor, color);
color = mColorConvert(color, mCOLOR_ARGB8, painter->backing->format);
PUT_PIXEL(color, dstPixel, painter->backing->depth);
}
}
}
}
static void mPainterStrokeRectangle(struct mPainter* painter, int x, int y, int width, int height) {
uint32_t fillColor = painter->fillColor;
painter->fillColor = painter->strokeColor;
if (width <= painter->strokeWidth * 2 || height <= painter->strokeWidth * 2) {
mPainterFillRectangle(painter, x, y, width, height);
} else {
int lr = height - painter->strokeWidth;
int tb = width - painter->strokeWidth;
// Top, top-left corner
mPainterFillRectangle(painter, x, y, tb, painter->strokeWidth);
// Left, bottom-left corner
mPainterFillRectangle(painter, x, y + painter->strokeWidth, painter->strokeWidth, lr);
// Bottom, bottom-right corner
mPainterFillRectangle(painter, x + painter->strokeWidth, y + height - painter->strokeWidth, tb, painter->strokeWidth);
// Right, top-right corner
mPainterFillRectangle(painter, x + width - painter->strokeWidth, y, painter->strokeWidth, lr);
}
painter->fillColor = fillColor;
}
void mPainterDrawRectangle(struct mPainter* painter, int x, int y, int width, int height) {
int interiorW = width - painter->strokeWidth * 2;
int interiorH = height - painter->strokeWidth * 2;
if (painter->fill && interiorW > 0 && interiorH > 0) {
mPainterFillRectangle(painter, x + painter->strokeWidth, y + painter->strokeWidth, interiorW, interiorH);
}
if (painter->strokeWidth) {
mPainterStrokeRectangle(painter, x, y, width, height);
}
}
uint32_t mColorConvert(uint32_t color, enum mColorFormat from, enum mColorFormat to) {
if (from == to) {
return color;

View File

@ -1142,6 +1142,497 @@ M_TEST_DEFINE(blitBoundaries) {
mImageDestroy(sprite);
}
#define COMPARE4(AA, BA, CA, DA, AB, BB, CB, DB, AC, BC, CC, DC, AD, BD, CD, DD) \
assert_int_equal(mImageGetPixel(image, 0, 0), (AA)); \
assert_int_equal(mImageGetPixel(image, 1, 0), (BA)); \
assert_int_equal(mImageGetPixel(image, 2, 0), (CA)); \
assert_int_equal(mImageGetPixel(image, 3, 0), (DA)); \
assert_int_equal(mImageGetPixel(image, 0, 1), (AB)); \
assert_int_equal(mImageGetPixel(image, 1, 1), (BB)); \
assert_int_equal(mImageGetPixel(image, 2, 1), (CB)); \
assert_int_equal(mImageGetPixel(image, 3, 1), (DB)); \
assert_int_equal(mImageGetPixel(image, 0, 2), (AC)); \
assert_int_equal(mImageGetPixel(image, 1, 2), (BC)); \
assert_int_equal(mImageGetPixel(image, 2, 2), (CC)); \
assert_int_equal(mImageGetPixel(image, 3, 2), (DC)); \
assert_int_equal(mImageGetPixel(image, 0, 3), (AD)); \
assert_int_equal(mImageGetPixel(image, 1, 3), (BD)); \
assert_int_equal(mImageGetPixel(image, 2, 3), (CD)); \
assert_int_equal(mImageGetPixel(image, 3, 3), (DD))
#define COMPARE4X(AA, BA, CA, DA, AB, BB, CB, DB, AC, BC, CC, DC, AD, BD, CD, DD) \
COMPARE4(0xFF000000 | (AA), 0xFF000000 | (BA), 0xFF000000 | (CA), 0xFF000000 | (DA), \
0xFF000000 | (AB), 0xFF000000 | (BB), 0xFF000000 | (CB), 0xFF000000 | (DB), \
0xFF000000 | (AC), 0xFF000000 | (BC), 0xFF000000 | (CC), 0xFF000000 | (DC), \
0xFF000000 | (AD), 0xFF000000 | (BD), 0xFF000000 | (CD), 0xFF000000 | (DD))
#define COMPARE3(AA, BA, CA, AB, BB, CB, AC, BC, CC) \
assert_int_equal(mImageGetPixel(image, 0, 0), (AA)); \
assert_int_equal(mImageGetPixel(image, 1, 0), (BA)); \
assert_int_equal(mImageGetPixel(image, 2, 0), (CA)); \
assert_int_equal(mImageGetPixel(image, 0, 1), (AB)); \
assert_int_equal(mImageGetPixel(image, 1, 1), (BB)); \
assert_int_equal(mImageGetPixel(image, 2, 1), (CB)); \
assert_int_equal(mImageGetPixel(image, 0, 2), (AC)); \
assert_int_equal(mImageGetPixel(image, 1, 2), (BC)); \
assert_int_equal(mImageGetPixel(image, 2, 2), (CC))
#define COMPARE3X(AA, BA, CA, AB, BB, CB, AC, BC, CC) \
COMPARE3(0xFF000000 | (AA), 0xFF000000 | (BA), 0xFF000000 | (CA), \
0xFF000000 | (AB), 0xFF000000 | (BB), 0xFF000000 | (CB), \
0xFF000000 | (AC), 0xFF000000 | (BC), 0xFF000000 | (CC))
M_TEST_DEFINE(painterFillRectangle) {
struct mImage* image;
struct mPainter painter;
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = true;
painter.strokeWidth = 0;
painter.fillColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 1, 1, 2, 2);
COMPARE4X(0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x0000FF, 0x0000FF, 0x000000,
0x000000, 0x0000FF, 0x0000FF, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = true;
painter.strokeWidth = 0;
painter.fillColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, -1, -1, 2, 2);
COMPARE4X(0x0000FF, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = true;
painter.strokeWidth = 0;
painter.fillColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 3, -1, 2, 2);
COMPARE4X(0x000000, 0x000000, 0x000000, 0x0000FF,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = true;
painter.strokeWidth = 0;
painter.fillColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, -1, 3, 2, 2);
COMPARE4X(0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000,
0x0000FF, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = true;
painter.strokeWidth = 0;
painter.fillColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 3, 3, 2, 2);
COMPARE4X(0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x0000FF);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = true;
painter.strokeWidth = 0;
painter.fillColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 0, 0, 3, 3);
painter.fillColor = 0xFF00FF00;
mPainterDrawRectangle(&painter, 1, 1, 3, 3);
COMPARE4X(0x0000FF, 0x0000FF, 0x0000FF, 0x000000,
0x0000FF, 0x00FF00, 0x00FF00, 0x00FF00,
0x0000FF, 0x00FF00, 0x00FF00, 0x00FF00,
0x000000, 0x00FF00, 0x00FF00, 0x00FF00);
mImageDestroy(image);
}
M_TEST_DEFINE(painterFillRectangleBlend) {
struct mImage* image;
struct mPainter painter;
image = mImageCreate(3, 3, mCOLOR_ARGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = true;
painter.strokeWidth = 0;
painter.fillColor = 0x400000FF;
mPainterDrawRectangle(&painter, 0, 0, 2, 2);
painter.fillColor = 0x40FF0000;
mPainterDrawRectangle(&painter, 1, 1, 2, 2);
COMPARE3(0x400000FF, 0x400000FF, 0x00000000,
0x400000FF, 0x40FF0000, 0x40FF0000,
0x00000000, 0x40FF0000, 0x40FF0000);
mImageDestroy(image);
image = mImageCreate(3, 3, mCOLOR_ARGB8);
mPainterInit(&painter, image);
painter.blend = true;
painter.fill = true;
painter.strokeWidth = 0;
painter.fillColor = 0x400000FF;
mPainterDrawRectangle(&painter, 0, 0, 2, 2);
painter.fillColor = 0x40FF0000;
mPainterDrawRectangle(&painter, 1, 1, 2, 2);
COMPARE3(0x400000FF, 0x400000FF, 0x00000000,
0x400000FF, 0x6F91006D, 0x40FF0000,
0x00000000, 0x40FF0000, 0x40FF0000);
mImageDestroy(image);
}
M_TEST_DEFINE(painterStrokeRectangle) {
struct mImage* image;
struct mPainter painter;
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 1, 1, 2, 2);
COMPARE4X(0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x0000FF, 0x0000FF, 0x000000,
0x000000, 0x0000FF, 0x0000FF, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, -1, -1, 3, 3);
COMPARE4X(0x000000, 0x0000FF, 0x000000, 0x000000,
0x0000FF, 0x0000FF, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 2, -1, 3, 3);
COMPARE4X(0x000000, 0x000000, 0x0000FF, 0x000000,
0x000000, 0x000000, 0x0000FF, 0x0000FF,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, -1, 2, 3, 3);
COMPARE4X(0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000,
0x0000FF, 0x0000FF, 0x000000, 0x000000,
0x000000, 0x0000FF, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 2, 2, 3, 3);
COMPARE4X(0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x0000FF, 0x0000FF,
0x000000, 0x000000, 0x0000FF, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 0, 0, 3, 3);
painter.strokeColor = 0xFF00FF00;
mPainterDrawRectangle(&painter, 1, 1, 3, 3);
COMPARE4X(0x0000FF, 0x0000FF, 0x0000FF, 0x000000,
0x0000FF, 0x00FF00, 0x00FF00, 0x00FF00,
0x0000FF, 0x00FF00, 0x0000FF, 0x00FF00,
0x000000, 0x00FF00, 0x00FF00, 0x00FF00);
mImageDestroy(image);
}
M_TEST_DEFINE(painterStrokeRectangleWidth) {
struct mImage* image;
struct mPainter painter;
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 0, 0, 4, 4);
COMPARE4X(0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x0000FF, 0x000000, 0x000000, 0x0000FF,
0x0000FF, 0x000000, 0x000000, 0x0000FF,
0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 0, 0, 4, 1);
COMPARE4X(0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 0, 0, 1, 4);
COMPARE4X(0x0000FF, 0x000000, 0x000000, 0x000000,
0x0000FF, 0x000000, 0x000000, 0x000000,
0x0000FF, 0x000000, 0x000000, 0x000000,
0x0000FF, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 0, 0, 4, 2);
COMPARE4X(0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 0, 0, 2, 4);
COMPARE4X(0x0000FF, 0x0000FF, 0x000000, 0x000000,
0x0000FF, 0x0000FF, 0x000000, 0x000000,
0x0000FF, 0x0000FF, 0x000000, 0x000000,
0x0000FF, 0x0000FF, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 2;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 0, 0, 4, 4);
COMPARE4X(0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 2;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 0, 0, 4, 2);
COMPARE4X(0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 2;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 0, 0, 2, 4);
COMPARE4X(0x0000FF, 0x0000FF, 0x000000, 0x000000,
0x0000FF, 0x0000FF, 0x000000, 0x000000,
0x0000FF, 0x0000FF, 0x000000, 0x000000,
0x0000FF, 0x0000FF, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 3;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 0, 0, 4, 2);
COMPARE4X(0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 3;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 0, 0, 2, 4);
COMPARE4X(0x0000FF, 0x0000FF, 0x000000, 0x000000,
0x0000FF, 0x0000FF, 0x000000, 0x000000,
0x0000FF, 0x0000FF, 0x000000, 0x000000,
0x0000FF, 0x0000FF, 0x000000, 0x000000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_XRGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 4;
painter.strokeColor = 0xFF0000FF;
mPainterDrawRectangle(&painter, 1, 1, 2, 2);
COMPARE4X(0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x0000FF, 0x0000FF, 0x000000,
0x000000, 0x0000FF, 0x0000FF, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000);
mImageDestroy(image);
}
M_TEST_DEFINE(painterStrokeRectangleBlend) {
struct mImage* image;
struct mPainter painter;
image = mImageCreate(4, 4, mCOLOR_ARGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0x400000FF;
mPainterDrawRectangle(&painter, 0, 0, 3, 3);
painter.strokeColor = 0x40FF0000;
mPainterDrawRectangle(&painter, 1, 1, 3, 3);
COMPARE4(0x400000FF, 0x400000FF, 0x400000FF, 0x00000000,
0x400000FF, 0x40FF0000, 0x40FF0000, 0x40FF0000,
0x400000FF, 0x40FF0000, 0x400000FF, 0x40FF0000,
0x00000000, 0x40FF0000, 0x40FF0000, 0x40FF0000);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_ARGB8);
mPainterInit(&painter, image);
painter.blend = true;
painter.fill = false;
painter.strokeWidth = 1;
painter.strokeColor = 0x400000FF;
mPainterDrawRectangle(&painter, 0, 0, 3, 3);
painter.strokeColor = 0x40FF0000;
mPainterDrawRectangle(&painter, 1, 1, 3, 3);
COMPARE4(0x400000FF, 0x400000FF, 0x400000FF, 0x00000000,
0x400000FF, 0x40FF0000, 0x6F91006D, 0x40FF0000,
0x400000FF, 0x6F91006D, 0x400000FF, 0x40FF0000,
0x00000000, 0x40FF0000, 0x40FF0000, 0x40FF0000);
}
M_TEST_DEFINE(painterDrawRectangle) {
struct mImage* image;
struct mPainter painter;
image = mImageCreate(3, 3, mCOLOR_ARGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = true;
painter.fillColor = 0x800000FF;
painter.strokeWidth = 1;
painter.strokeColor = 0x4000FF00;
mPainterDrawRectangle(&painter, 0, 0, 3, 3);
COMPARE3(0x4000FF00, 0x4000FF00, 0x4000FF00,
0x4000FF00, 0x800000FF, 0x4000FF00,
0x4000FF00, 0x4000FF00, 0x4000FF00);
mImageDestroy(image);
image = mImageCreate(3, 3, mCOLOR_ARGB8);
mPainterInit(&painter, image);
painter.blend = true;
painter.fill = true;
painter.fillColor = 0x800000FF;
painter.strokeWidth = 1;
painter.strokeColor = 0x4000FF00;
mPainterDrawRectangle(&painter, 0, 0, 3, 3);
COMPARE3(0x4000FF00, 0x4000FF00, 0x4000FF00,
0x4000FF00, 0x800000FF, 0x4000FF00,
0x4000FF00, 0x4000FF00, 0x4000FF00);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_ARGB8);
mPainterInit(&painter, image);
painter.blend = false;
painter.fill = true;
painter.fillColor = 0x800000FF;
painter.strokeWidth = 1;
painter.strokeColor = 0x4000FF00;
mPainterDrawRectangle(&painter, 0, 0, 3, 3);
mPainterDrawRectangle(&painter, 1, 1, 3, 3);
COMPARE4(0x4000FF00, 0x4000FF00, 0x4000FF00, 0x00000000,
0x4000FF00, 0x4000FF00, 0x4000FF00, 0x4000FF00,
0x4000FF00, 0x4000FF00, 0x800000FF, 0x4000FF00,
0x00000000, 0x4000FF00, 0x4000FF00, 0x4000FF00);
mImageDestroy(image);
image = mImageCreate(4, 4, mCOLOR_ARGB8);
mPainterInit(&painter, image);
painter.blend = true;
painter.fill = true;
painter.fillColor = 0x800000FF;
painter.strokeWidth = 1;
painter.strokeColor = 0x4000FF00;
mPainterDrawRectangle(&painter, 0, 0, 3, 3);
mPainterDrawRectangle(&painter, 1, 1, 3, 3);
COMPARE4(0x4000FF00, 0x4000FF00, 0x4000FF00, 0x00000000,
0x4000FF00, 0x9F006698, 0x6F00FF00, 0x4000FF00,
0x4000FF00, 0x6F00FF00, 0x9F0032CC, 0x4000FF00,
0x00000000, 0x4000FF00, 0x4000FF00, 0x4000FF00);
mImageDestroy(image);
}
#undef COMPARE3X
#undef COMPARE3
#undef COMPARE4X
#undef COMPARE4
M_TEST_SUITE_DEFINE(Image,
cmocka_unit_test(zeroDim),
cmocka_unit_test(pitchRead),
@ -1166,4 +1657,10 @@ M_TEST_SUITE_DEFINE(Image,
cmocka_unit_test(convert1x2),
cmocka_unit_test(convert2x2),
cmocka_unit_test(blitBoundaries),
cmocka_unit_test(painterFillRectangle),
cmocka_unit_test(painterFillRectangleBlend),
cmocka_unit_test(painterStrokeRectangle),
cmocka_unit_test(painterStrokeRectangleWidth),
cmocka_unit_test(painterStrokeRectangleBlend),
cmocka_unit_test(painterDrawRectangle),
)