Compare commits
2 Commits
fd51ee9046
...
aa8bacc18f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa8bacc18f | ||
|
|
47278807f6 |
@@ -65,7 +65,7 @@ std::optional<TextureEntry> BitsetImageLoader::haveToTexture(TextureUploaderI& t
|
||||
BitsetImageLoader::BitsetImageLoader(void) {
|
||||
}
|
||||
|
||||
TextureLoaderResult BitsetImageLoader::load(TextureUploaderI& tu, ObjectHandle o, uint32_t w, uint32_t h) {
|
||||
TextureLoaderResult BitsetImageLoader::load(TextureUploaderI& tu, ObjectHandle o, uint32_t /*w*/, uint32_t /*h*/) {
|
||||
if (!static_cast<bool>(o)) {
|
||||
std::cerr << "BIL error: trying to load invalid object\n";
|
||||
return {};
|
||||
|
||||
@@ -6,9 +6,14 @@
|
||||
#include "./image_scaler.hpp"
|
||||
|
||||
ImageLoaderI::ImageResult ImageLoaderI::ImageResult::crop(int32_t c_x, int32_t c_y, int32_t c_w, int32_t c_h) const {
|
||||
// TODO: proper error handling
|
||||
assert(c_x+c_w <= width);
|
||||
assert(c_y+c_h <= height);
|
||||
if (
|
||||
c_x < 0 || c_y < 0 || c_w < 1 || c_h < 1 ||
|
||||
int64_t(c_x) + int64_t(c_w) > int64_t(width) || int64_t(c_y) + int64_t(c_h) > int64_t(height)
|
||||
) {
|
||||
// unreachable
|
||||
assert(false && "invalid image crop");
|
||||
return *this;
|
||||
}
|
||||
|
||||
ImageLoaderI::ImageResult new_image;
|
||||
new_image.width = c_w;
|
||||
@@ -19,7 +24,7 @@ ImageLoaderI::ImageResult ImageLoaderI::ImageResult::crop(int32_t c_x, int32_t c
|
||||
auto& new_frame = new_image.frames.emplace_back();
|
||||
new_frame.ms = input_frame.ms;
|
||||
|
||||
// TODO: improve this, this is super inefficent
|
||||
// TODO: improve this, this is inefficent
|
||||
for (int64_t y = c_y; y < c_y + c_h; y++) {
|
||||
for (int64_t x = c_x; x < c_x + c_w; x++) {
|
||||
new_frame.data.push_back(input_frame.data.at(y*width*4+x*4+0));
|
||||
|
||||
@@ -89,8 +89,8 @@ std::vector<uint8_t> ImageEncoderSTBPNG::encodeToMemoryRGBA(const ImageResult& i
|
||||
struct Context {
|
||||
std::vector<uint8_t> new_data;
|
||||
} context;
|
||||
auto write_f = +[](void* context, void* data, int size) -> void {
|
||||
Context* ctx = reinterpret_cast<Context*>(context);
|
||||
auto write_f = +[](void* context_, void* data, int size) -> void {
|
||||
Context* ctx = reinterpret_cast<Context*>(context_);
|
||||
uint8_t* d = reinterpret_cast<uint8_t*>(data);
|
||||
ctx->new_data.insert(ctx->new_data.cend(), d, d + size);
|
||||
};
|
||||
@@ -126,8 +126,8 @@ std::vector<uint8_t> ImageEncoderSTBJpeg::encodeToMemoryRGBA(const ImageResult&
|
||||
struct Context {
|
||||
std::vector<uint8_t> new_data;
|
||||
} context;
|
||||
auto write_f = +[](void* context, void* data, int size) -> void {
|
||||
Context* ctx = reinterpret_cast<Context*>(context);
|
||||
auto write_f = +[](void* context_, void* data, int size) -> void {
|
||||
Context* ctx = reinterpret_cast<Context*>(context_);
|
||||
uint8_t* d = reinterpret_cast<uint8_t*>(data);
|
||||
ctx->new_data.insert(ctx->new_data.cend(), d, d + size);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user