Add scad_format for CGX, COL, OBJ files

This commit is contained in:
scawful
2023-08-09 00:19:07 -04:00
parent a3f68b70b4
commit c336c60066
12 changed files with 485 additions and 91 deletions

View File

@@ -104,6 +104,19 @@ void Bitmap::Create(int width, int height, int depth, Bytes data) {
GrayscalePalette(surface_->format->palette);
}
void Bitmap::CreateFromSurface(SDL_Surface *surface) {
active_ = true;
width_ = surface->w;
height_ = surface->h;
depth_ = 8;
pixel_data_ = static_cast<uchar *>(surface->pixels);
surface_ = std::unique_ptr<SDL_Surface, SDL_Surface_Deleter>(
SDL_CreateRGBSurfaceWithFormat(0, width_, height_, depth_,
SDL_PIXELFORMAT_INDEX8),
SDL_Surface_Deleter());
surface_->pixels = pixel_data_;
}
void Bitmap::Apply(Bytes data) {
pixel_data_ = data.data();
data_ = data;
@@ -124,6 +137,11 @@ void Bitmap::UpdateTexture(std::shared_ptr<SDL_Renderer> renderer) {
SDL_Texture_Deleter{}};
}
void Bitmap::SetSurface(SDL_Surface *surface) {
surface_ = std::unique_ptr<SDL_Surface, SDL_Surface_Deleter>(
surface, SDL_Surface_Deleter());
}
// Convert SNESPalette to SDL_Palette for surface.
void Bitmap::ApplyPalette(const SNESPalette &palette) {
palette_ = palette;
@@ -144,6 +162,17 @@ void Bitmap::ApplyPalette(const SNESPalette &palette) {
SDL_LockSurface(surface_.get());
}
void Bitmap::ApplyPalette(const std::vector<SDL_Color> &palette) {
SDL_UnlockSurface(surface_.get());
for (int i = 0; i < palette.size(); ++i) {
surface_->format->palette->colors[i].r = palette[i].r;
surface_->format->palette->colors[i].g = palette[i].g;
surface_->format->palette->colors[i].b = palette[i].b;
surface_->format->palette->colors[i].a = palette[i].a;
}
SDL_LockSurface(surface_.get());
}
} // namespace gfx
} // namespace app
} // namespace yaze