| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include "Texture.h"
- #include "piaf/Archive.h"
- #include "utility/Rect.h"
- #include "render/Pixel.h"
- #include "utility/misc.h"
- #include "lodepng.h"
- #include "Input.h"
- #include "Graphics.h"
- using WalrusRPG::Graphics::Black;
- using WalrusRPG::Graphics::Pixel;
- using WalrusRPG::Graphics::Texture;
- using WalrusRPG::Utils::Rect;
- using WalrusRPG::PIAF::File;
- namespace
- {
- /*
- texture_data_t loadPNG(char *data)
- {
- // TODO : stuff
- UNUSED(data);
- return nullptr;
- }
- */
- }
- Texture::Texture(File entry)
- {
- unsigned char* pic;
- unsigned width, height;
- signed result = lodepng_decode_memory(&pic, &width, &height, (unsigned char*)entry.get(), entry.file_size, LCT_RGBA, 8);
- UNUSED(result);
-
- data = new uint16_t[width * height + 3];
- data[0] = width;
- data[1] = height;
- for(unsigned y = 0; y < height; y++)
- {
- for (unsigned x = 0; x < width; x++) {
- uint16_t color = (pic[(y*width + x)*4]>>3)<<11;
- color |= (pic[(y*width + x)*4 + 1]>>2)<<5;
- color |= (pic[(y*width + x)*4 + 2]>>3);
- if(pic[(y*width + x)*4+3] == 0)
- {
- data[2] = color;
- }
- data[y*width + x+3] = color;
- }
- }
- delete[] pic;
- }
- Texture::Texture(char *data) : data((texture_data_t) data)
- {
- }
- Texture::~Texture()
- {
- // Don't deallocate for now since we still hardcode the data
- // delete (data);
- }
- Rect Texture::get_dimensions()
- {
- return Rect(0, 0, data[0], data[1]);
- }
- const Pixel Texture::get_pixel(unsigned x, unsigned y)
- {
- return Pixel(data[2 + data[0] * y + x]);
- }
|