mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
Added screenshot feature (F2 key)
This commit is contained in:
parent
d42d2dc294
commit
3723cf491f
9 changed files with 113 additions and 11 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "ImageData.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdexcept>
|
||||
|
||||
inline int min(int a, int b) {
|
||||
return (a < b) ? a : b;
|
||||
|
|
@ -23,7 +24,52 @@ ImageData::~ImageData() {
|
|||
}
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
void ImageData::flipX() {
|
||||
uint size;
|
||||
switch (format) {
|
||||
case ImageFormat::rgb888:
|
||||
case ImageFormat::rgba8888: {
|
||||
size = (format == ImageFormat::rgba8888) ? 4 : 3;
|
||||
ubyte* pixels = (ubyte*)data;
|
||||
for (uint y = 0; y < height; y++) {
|
||||
for (uint x = 0; x < width/2; x++) {
|
||||
for (uint c = 0; c < size; c++) {
|
||||
ubyte temp = pixels[(y * width + x) * size + c];
|
||||
pixels[(y * width + x) * size + c] = pixels[(y * width + (width - x - 1)) * size + c];
|
||||
pixels[(y * width + (width - x - 1)) * size + c] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw std::runtime_error("format is not supported");
|
||||
}
|
||||
}
|
||||
|
||||
void ImageData::flipY() {
|
||||
uint size;
|
||||
switch (format) {
|
||||
case ImageFormat::rgb888:
|
||||
case ImageFormat::rgba8888: {
|
||||
size = (format == ImageFormat::rgba8888) ? 4 : 3;
|
||||
ubyte* pixels = (ubyte*)data;
|
||||
for (uint y = 0; y < height/2; y++) {
|
||||
for (uint x = 0; x < width; x++) {
|
||||
for (uint c = 0; c < size; c++) {
|
||||
ubyte temp = pixels[(y * width + x) * size + c];
|
||||
pixels[(y * width + x) * size + c] = pixels[((height-y-1) * width + x) * size + c];
|
||||
pixels[((height-y-1) * width + x) * size + c] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw std::runtime_error("format is not supported");
|
||||
}
|
||||
}
|
||||
|
||||
ImageData* add_atlas_margins(ImageData* image, int grid_size) {
|
||||
// RGBA is only supported
|
||||
assert(image->getFormat() == ImageFormat::rgba8888);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue