housekeeping

This commit is contained in:
scawful
2022-07-08 23:52:11 -04:00
parent 260f9d5166
commit e9c8152453
10 changed files with 77 additions and 99 deletions

View File

@@ -38,6 +38,21 @@ void Bitmap::Create(int width, int height, int depth, uchar *data) {
surface_->pixels = pixel_data_;
}
void Bitmap::Create(int width, int height, int depth, int size) {
width_ = width;
height_ = height;
depth_ = depth;
surface_ = SDL_CreateRGBSurfaceWithFormat(0, width, height, depth,
SDL_PIXELFORMAT_INDEX8);
// Default grayscale palette
for (int i = 0; i < 8; i++) {
surface_->format->palette->colors[i].r = i * 31;
surface_->format->palette->colors[i].g = i * 31;
surface_->format->palette->colors[i].b = i * 31;
}
surface_->pixels = pixel_data_;
}
void Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) {
texture_ = SDL_CreateTextureFromSurface(renderer.get(), surface_);
}

View File

@@ -16,15 +16,17 @@ class Bitmap {
Bitmap(int width, int height, int depth, uchar *data);
void Create(int width, int height, int depth, uchar *data);
void Create(int width, int height, int depth, int data_size);
int GetWidth() const { return width_; }
int GetHeight() const { return height_; }
void CreateTexture(std::shared_ptr<SDL_Renderer> renderer);
inline SDL_Texture *GetTexture() const { return texture_; }
SDL_Texture *GetTexture() const { return texture_; }
private:
int width_;
int height_;
int depth_;
int data_size_;
uchar *pixel_data_;
SDL_Surface *surface_;
SDL_Texture *texture_;

View File

@@ -82,13 +82,13 @@ SNESPalette::SNESPalette(const std::vector<ImVec4> & cols) {
}
char* SNESPalette::encode() {
auto data = std::make_shared<char>(size_ * 2);
auto data = new char[size_ * 2];
for (unsigned int i = 0; i < size_; i++) {
std::cout << colors[i].snes << std::endl;
data[i * 2] = (char)(colors[i].snes & 0xFF);
data[i * 2 + 1] = (char)(colors[i].snes >> 8);
}
return data.get();
return data;
}
SDL_Palette* SNESPalette::GetSDL_Palette() {