mirror of
https://github.com/spice2x/spice2x.github.io.git
synced 2026-08-01 22:30:42 -07:00
printer: fix orientation of resulting image (#324)
## Link to GitHub Issue, if one exists n/a ## Description of change Rotate the printer output so that it's the correct orientation (portrait, not landscape). ## Testing Tested via test image, and also in-game, for LP and SDVX.
This commit is contained in:
@@ -326,7 +326,7 @@ namespace games::shared {
|
||||
memcpy(image_data, pBandImage->baseAddr, (size_t) (image_width * image_height * 3));
|
||||
|
||||
// convert BGR to RGB
|
||||
log_info("printer", "converting BGR to RGB...");
|
||||
log_misc("printer", "converting BGR to RGB...");
|
||||
for (int pixel = 0; pixel < image_width * image_height; pixel++) {
|
||||
int index = pixel * 3;
|
||||
uint8_t tmp = image_data[index];
|
||||
@@ -334,25 +334,45 @@ namespace games::shared {
|
||||
image_data[index + 2] = tmp;
|
||||
}
|
||||
|
||||
// flip horizontally
|
||||
for (int x = 0; x < image_width / 2; x++) {
|
||||
for (int y = 0; y < image_height; y++) {
|
||||
int index1 = (y * image_width + x) * 3;
|
||||
int index2 = (y * image_width + image_width - x - 1) * 3;
|
||||
uint8_t r = image_data[index1 + 0];
|
||||
uint8_t g = image_data[index1 + 1];
|
||||
uint8_t b = image_data[index1 + 2];
|
||||
image_data[index1 + 0] = image_data[index2 + 0];
|
||||
image_data[index1 + 1] = image_data[index2 + 1];
|
||||
image_data[index1 + 2] = image_data[index2 + 2];
|
||||
image_data[index2 + 0] = r;
|
||||
image_data[index2 + 1] = g;
|
||||
image_data[index2 + 2] = b;
|
||||
if (avs::game::is_model({"KLP", "KFC"})) {
|
||||
// rotate image clockwise
|
||||
log_misc("printer", "rotate clockwise...");
|
||||
auto rotated = new uint8_t[image_width * image_height * 3];
|
||||
for (int x = 0; x < image_width; x++) {
|
||||
for (int y = 0; y < image_height; y++) {
|
||||
int index1 = (y * image_width + x) * 3;
|
||||
int index2 = (x * image_height + y) * 3;
|
||||
rotated[index2 + 0] = image_data[index1 + 0];
|
||||
rotated[index2 + 1] = image_data[index1 + 1];
|
||||
rotated[index2 + 2] = image_data[index1 + 2];
|
||||
}
|
||||
}
|
||||
delete[] image_data;
|
||||
image_data = rotated;
|
||||
std::swap(image_width, image_height);
|
||||
|
||||
} else {
|
||||
// flip horizontally
|
||||
log_misc("printer", "flip horizontally...");
|
||||
for (int x = 0; x < image_width / 2; x++) {
|
||||
for (int y = 0; y < image_height; y++) {
|
||||
int index1 = (y * image_width + x) * 3;
|
||||
int index2 = (y * image_width + image_width - x - 1) * 3;
|
||||
uint8_t r = image_data[index1 + 0];
|
||||
uint8_t g = image_data[index1 + 1];
|
||||
uint8_t b = image_data[index1 + 2];
|
||||
image_data[index1 + 0] = image_data[index2 + 0];
|
||||
image_data[index1 + 1] = image_data[index2 + 1];
|
||||
image_data[index1 + 2] = image_data[index2 + 2];
|
||||
image_data[index2 + 0] = r;
|
||||
image_data[index2 + 1] = g;
|
||||
image_data[index2 + 2] = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// iterate folders
|
||||
log_info("printer", "writing files...");
|
||||
log_misc("printer", "writing files...");
|
||||
for (const auto &path : PRINTER_PATH) {
|
||||
for (const auto &format : PRINTER_FORMAT) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user