improve bleed edge

This commit is contained in:
GenevensiS
2025-12-17 08:16:11 +01:00
parent 2d5ec064df
commit 80a7dccdf1
2 changed files with 99 additions and 187 deletions
+49 -93
View File
@@ -58,116 +58,72 @@ Image export_image(const SetP& set, const CardP& card, const bool write_metadata
int width = img.GetWidth(), height = img.GetHeight(); int width = img.GetWidth(), height = img.GetHeight();
/// add print bleed edge /// add print bleed edge
if (size.width < 1.0 || size.height < 1.0) { if (size.width < bleed + 2 || size.height < bleed + 2) {
queue_message(MESSAGE_ERROR, _("Cannot add bleed edge to empty image")); queue_message(MESSAGE_ERROR, _("Image too small to add bleed edge"));
} }
else { else {
if (!img.HasAlpha()) img.InitAlpha(); if (!img.HasAlpha()) img.InitAlpha();
Byte* pixels = img.GetData(); Byte* pixels = img.GetData();
Byte* alpha = img.GetAlpha(); Byte* alpha = img.GetAlpha();
// fill top left corner int pixel, mirror, x_start, y_start, x_size, y_size;
int pixel;
int x_start = 0;
int y_start = 0;
int ref = bleed + bleed * width;
for (int y = 0; y < bleed; ++y) {
for (int x = 0; x < bleed; ++x) {
pixel = x_start + x + (y_start + y) * width;
pixels[3 * pixel + 0] = pixels[3 * ref + 0];
pixels[3 * pixel + 1] = pixels[3 * ref + 1];
pixels[3 * pixel + 2] = pixels[3 * ref + 2];
alpha[pixel] = alpha[ref];
}
}
// fill top right corner
x_start = width - bleed;
y_start = 0;
ref = x_start - 1 + bleed * width;
for (int y = 0; y < bleed; ++y) {
for (int x = 0; x < bleed; ++x) {
pixel = x_start + x + (y_start + y) * width;
pixels[3 * pixel + 0] = pixels[3 * ref + 0];
pixels[3 * pixel + 1] = pixels[3 * ref + 1];
pixels[3 * pixel + 2] = pixels[3 * ref + 2];
alpha[pixel] = alpha[ref];
}
}
// fill bottom left corner
x_start = 0;
y_start = height - bleed;
ref = bleed + (y_start - 1) * width;
for (int y = 0; y < bleed; ++y) {
for (int x = 0; x < bleed; ++x) {
pixel = x_start + x + (y_start + y) * width;
pixels[3 * pixel + 0] = pixels[3 * ref + 0];
pixels[3 * pixel + 1] = pixels[3 * ref + 1];
pixels[3 * pixel + 2] = pixels[3 * ref + 2];
alpha[pixel] = alpha[ref];
}
}
// fill bottom right corner
x_start = width - bleed;
y_start = height - bleed;
ref = (x_start - 1) + (y_start - 1) * width;
for (int y = 0; y < bleed; ++y) {
for (int x = 0; x < bleed; ++x) {
pixel = x_start + x + (y_start + y) * width;
pixels[3 * pixel + 0] = pixels[3 * ref + 0];
pixels[3 * pixel + 1] = pixels[3 * ref + 1];
pixels[3 * pixel + 2] = pixels[3 * ref + 2];
alpha[pixel] = alpha[ref];
}
}
// fill left border // fill left border
x_start = 0; x_start = 0;
y_start = bleed; y_start = bleed;
for (int y = 0; y < height - bleed - bleed; ++y) { x_size = bleed;
ref = bleed + (y_start + y) * width; y_size = height - bleed - bleed;
for (int x = 0; x < bleed; ++x) { for (int y = 0; y < y_size; ++y) {
pixel = x_start + x + (y_start + y) * width; for (int x = 0; x < x_size; ++x) {
pixels[3 * pixel + 0] = pixels[3 * ref + 0]; pixel = x_start + x + (y_start + y) * width;
pixels[3 * pixel + 1] = pixels[3 * ref + 1]; mirror = 2 * bleed - x + (y_start + y) * width;
pixels[3 * pixel + 2] = pixels[3 * ref + 2]; pixels[3 * pixel + 0] = pixels[3 * mirror + 0];
alpha[pixel] = alpha[ref]; pixels[3 * pixel + 1] = pixels[3 * mirror + 1];
} pixels[3 * pixel + 2] = pixels[3 * mirror + 2];
} alpha[pixel] = alpha[mirror];
// fill top border
x_start = bleed;
y_start = 0;
for (int y = 0; y < bleed; ++y) {
for (int x = 0; x < width - bleed - bleed; ++x) {
pixel = x_start + x + (y_start + y) * width;
ref = x_start + x + bleed * width;
pixels[3 * pixel + 0] = pixels[3 * ref + 0];
pixels[3 * pixel + 1] = pixels[3 * ref + 1];
pixels[3 * pixel + 2] = pixels[3 * ref + 2];
alpha[pixel] = alpha[ref];
} }
} }
// fill right border // fill right border
x_start = width - bleed; x_start = width - bleed;
y_start = bleed; y_start = bleed;
for (int y = 0; y < height - bleed - bleed; ++y) { x_size = bleed;
ref = width - bleed - 1 + (y_start + y) * width; y_size = height - bleed - bleed;
for (int x = 0; x < bleed; ++x) { for (int y = 0; y < y_size; ++y) {
pixel = x_start + x + (y_start + y) * width; for (int x = 0; x < x_size; ++x) {
pixels[3 * pixel + 0] = pixels[3 * ref + 0]; pixel = x_start + x + (y_start + y) * width;
pixels[3 * pixel + 1] = pixels[3 * ref + 1]; mirror = - 2 + x_start - x + (y_start + y) * width;
pixels[3 * pixel + 2] = pixels[3 * ref + 2]; pixels[3 * pixel + 0] = pixels[3 * mirror + 0];
alpha[pixel] = alpha[ref]; pixels[3 * pixel + 1] = pixels[3 * mirror + 1];
pixels[3 * pixel + 2] = pixels[3 * mirror + 2];
alpha[pixel] = alpha[mirror];
}
}
// fill top border
x_start = 0;
y_start = 0;
x_size = width;
y_size = bleed;
for (int y = 0; y < y_size; ++y) {
for (int x = 0; x < x_size; ++x) {
pixel = x_start + x + ( y_start + y) * width;
mirror = x_start + x + (2 * bleed - y) * width;
pixels[3 * pixel + 0] = pixels[3 * mirror + 0];
pixels[3 * pixel + 1] = pixels[3 * mirror + 1];
pixels[3 * pixel + 2] = pixels[3 * mirror + 2];
alpha[pixel] = alpha[mirror];
} }
} }
// fill bottom border // fill bottom border
x_start = bleed; x_start = 0;
y_start = height - bleed; y_start = height - bleed;
for (int y = 0; y < bleed; ++y) { x_size = width;
for (int x = 0; x < width - bleed - bleed; ++x) { y_size = bleed;
pixel = x_start + x + (y_start + y) * width; for (int y = 0; y < y_size; ++y) {
ref = x_start + x + (height - bleed - 1) * width; for (int x = 0; x < x_size; ++x) {
pixels[3 * pixel + 0] = pixels[3 * ref + 0]; pixel = x_start + x + ( y_start + y) * width;
pixels[3 * pixel + 1] = pixels[3 * ref + 1]; mirror = x_start + x + (- 2 + y_start - y) * width;
pixels[3 * pixel + 2] = pixels[3 * ref + 2]; pixels[3 * pixel + 0] = pixels[3 * mirror + 0];
alpha[pixel] = alpha[ref]; pixels[3 * pixel + 1] = pixels[3 * mirror + 1];
pixels[3 * pixel + 2] = pixels[3 * mirror + 2];
alpha[pixel] = alpha[mirror];
} }
} }
} }
+50 -94
View File
@@ -338,120 +338,76 @@ Image BleedEdgedImage::generate(const Options& opt) {
UInt size = width * height; UInt size = width * height;
Image img = wxImage(width, height, false); Image img = wxImage(width, height, false);
img.InitAlpha(); img.InitAlpha();
Byte* data = img.GetData(); Byte* pixels = img.GetData();
Byte* alpha = img.GetAlpha(); Byte* alpha = img.GetAlpha();
// fill with background color // fill with background color
for (UInt i = 0; i < size; ++i) { for (UInt i = 0; i < size; ++i) {
data[3 * i + 0] = background_color.Red(); pixels[3 * i + 0] = background_color.Red();
data[3 * i + 1] = background_color.Green(); pixels[3 * i + 1] = background_color.Green();
data[3 * i + 2] = background_color.Blue(); pixels[3 * i + 2] = background_color.Blue();
alpha[i] = background_color.Alpha(); alpha[i] = background_color.Alpha();
} }
// paste original image // paste original image
img.Paste(base_img, dw, dh, wxIMAGE_ALPHA_BLEND_COMPOSE); img.Paste(base_img, dw, dh, wxIMAGE_ALPHA_BLEND_COMPOSE);
// fill top left corner int pixel, mirror, x_start, y_start, x_size, y_size;
int pixel;
int x_start = 0;
int y_start = 0;
int ref = dw + dh * width;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
}
}
// fill top right corner
x_start = width - dw;
y_start = 0;
ref = x_start - 1 + dh * width;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
}
}
// fill bottom left corner
x_start = 0;
y_start = height - dh;
ref = dw + (y_start - 1) * width;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
}
}
// fill bottom right corner
x_start = width - dw;
y_start = height - dh;
ref = (x_start - 1) + (y_start - 1) * width;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
}
}
// fill left border // fill left border
x_start = 0; x_start = 0;
y_start = dh; y_start = dh;
for (int y = 0; y < height - dh - dh; ++y) { x_size = dw;
ref = dw + (y_start + y) * width; y_size = height - dh - dh;
for (int x = 0; x < dw; ++x) { for (int y = 0; y < y_size; ++y) {
for (int x = 0; x < x_size; ++x) {
pixel = x_start + x + (y_start + y) * width; pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 0] = data[3 * ref + 0]; mirror = 2 * dw - x + (y_start + y) * width;
data[3 * pixel + 1] = data[3 * ref + 1]; pixels[3 * pixel + 0] = pixels[3 * mirror + 0];
data[3 * pixel + 2] = data[3 * ref + 2]; pixels[3 * pixel + 1] = pixels[3 * mirror + 1];
alpha[pixel] = alpha[ref]; pixels[3 * pixel + 2] = pixels[3 * mirror + 2];
} alpha[pixel] = alpha[mirror];
}
// fill top border
x_start = dw;
y_start = 0;
for (int y = 0; y < dh; ++y) {
for (int x = 0; x < width - dw - dw; ++x) {
pixel = x_start + x + (y_start + y) * width;
ref = x_start + x + dh * width;
data[3 * pixel + 0] = data[3 * ref + 0];
data[3 * pixel + 1] = data[3 * ref + 1];
data[3 * pixel + 2] = data[3 * ref + 2];
alpha[pixel] = alpha[ref];
} }
} }
// fill right border // fill right border
x_start = width - dw; x_start = width - dw;
y_start = dh; y_start = dh;
for (int y = 0; y < height - dh - dh; ++y) { x_size = dw;
ref = width - dw - 1 + (y_start + y) * width; y_size = height - dh - dh;
for (int x = 0; x < dw; ++x) { for (int y = 0; y < y_size; ++y) {
pixel = x_start + x + (y_start + y) * width; for (int x = 0; x < x_size; ++x) {
data[3 * pixel + 0] = data[3 * ref + 0]; pixel = x_start + x + (y_start + y) * width;
data[3 * pixel + 1] = data[3 * ref + 1]; mirror = - 2 + x_start - x + (y_start + y) * width;
data[3 * pixel + 2] = data[3 * ref + 2]; pixels[3 * pixel + 0] = pixels[3 * mirror + 0];
alpha[pixel] = alpha[ref]; pixels[3 * pixel + 1] = pixels[3 * mirror + 1];
pixels[3 * pixel + 2] = pixels[3 * mirror + 2];
alpha[pixel] = alpha[mirror];
}
}
// fill top border
x_start = 0;
y_start = 0;
x_size = width;
y_size = dh;
for (int y = 0; y < y_size; ++y) {
for (int x = 0; x < x_size; ++x) {
pixel = x_start + x + (y_start + y) * width;
mirror = x_start + x + ( 2 * dh - y) * width;
pixels[3 * pixel + 0] = pixels[3 * mirror + 0];
pixels[3 * pixel + 1] = pixels[3 * mirror + 1];
pixels[3 * pixel + 2] = pixels[3 * mirror + 2];
alpha[pixel] = alpha[mirror];
} }
} }
// fill bottom border // fill bottom border
x_start = dw; x_start = 0;
y_start = height - dh; y_start = height - dh;
for (int y = 0; y < dh; ++y) { x_size = width;
for (int x = 0; x < width - dw - dw; ++x) { y_size = dh;
pixel = x_start + x + (y_start + y) * width; for (int y = 0; y < y_size; ++y) {
ref = x_start + x + (height - dh - 1) * width; for (int x = 0; x < x_size; ++x) {
data[3 * pixel + 0] = data[3 * ref + 0]; pixel = x_start + x + ( y_start + y) * width;
data[3 * pixel + 1] = data[3 * ref + 1]; mirror = x_start + x + (- 2 + y_start - y) * width;
data[3 * pixel + 2] = data[3 * ref + 2]; pixels[3 * pixel + 0] = pixels[3 * mirror + 0];
alpha[pixel] = alpha[ref]; pixels[3 * pixel + 1] = pixels[3 * mirror + 1];
pixels[3 * pixel + 2] = pixels[3 * mirror + 2];
alpha[pixel] = alpha[mirror];
} }
} }
// done // done