mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 03:32:48 +00:00
create_palette_from_rgb(): avoid processing the same (linked) image
This commit is contained in:
parent
9740cfd08c
commit
ad8ed256de
@ -26,6 +26,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace render {
|
namespace render {
|
||||||
|
|
||||||
@ -49,7 +50,6 @@ Palette* create_palette_from_rgb(
|
|||||||
palette = new Palette(frame_t(0), 256);
|
palette = new Palette(frame_t(0), 256);
|
||||||
|
|
||||||
bool has_background_layer = (sprite->backgroundLayer() != NULL);
|
bool has_background_layer = (sprite->backgroundLayer() != NULL);
|
||||||
Image* flat_image;
|
|
||||||
|
|
||||||
ImagesCollector images(
|
ImagesCollector images(
|
||||||
sprite->folder(), // All layers
|
sprite->folder(), // All layers
|
||||||
@ -58,24 +58,29 @@ Palette* create_palette_from_rgb(
|
|||||||
false); // forWrite=false, read only
|
false); // forWrite=false, read only
|
||||||
|
|
||||||
// Add a flat image with the current sprite's frame rendered
|
// Add a flat image with the current sprite's frame rendered
|
||||||
flat_image = Image::create(sprite->pixelFormat(),
|
ImageRef flat_image(Image::create(sprite->pixelFormat(),
|
||||||
sprite->width(), sprite->height());
|
sprite->width(), sprite->height()));
|
||||||
|
|
||||||
render::Render().renderSprite(flat_image, sprite, frameNumber);
|
render::Render().renderSprite(flat_image, sprite, frameNumber);
|
||||||
|
|
||||||
// Create an array of images
|
// Create an array of images
|
||||||
size_t nimage = images.size() + 1; // +1 for flat_image
|
std::vector<Image*> image_array;
|
||||||
std::vector<Image*> image_array(nimage);
|
std::map<ObjectId, Image*> used_images;
|
||||||
|
|
||||||
size_t c = 0;
|
for (auto it=images.begin(); it!=images.end(); ++it) {
|
||||||
for (ImagesCollector::ItemsIterator it=images.begin(); it!=images.end(); ++it)
|
Image* image = it->image();
|
||||||
image_array[c++] = it->image();
|
ObjectId imageId = image->id();
|
||||||
image_array[c++] = flat_image; // The 'flat_image'
|
|
||||||
|
if (used_images.find(imageId) == used_images.end()) {
|
||||||
|
used_images.insert(std::make_pair(imageId, image));
|
||||||
|
image_array.push_back(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
image_array.push_back(flat_image);
|
||||||
|
|
||||||
// Generate an optimized palette for all images
|
// Generate an optimized palette for all images
|
||||||
create_palette_from_images(image_array, palette, has_background_layer);
|
create_palette_from_images(image_array, palette, has_background_layer);
|
||||||
|
|
||||||
delete flat_image;
|
|
||||||
return palette;
|
return palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user