Convert thumbnails to sRGB color space + don't use EditorRender from thumbnails workers

This commit is contained in:
David Capello 2019-03-28 10:22:46 -03:00
parent 30798435d1
commit d9aa0d5c68
4 changed files with 79 additions and 17 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -70,16 +70,15 @@ static doc::ImageRef convert_image_color_space(const doc::Image* srcImage,
return dstImage;
}
void convert_color_profile(doc::Sprite* sprite, const gfx::ColorSpacePtr& newCS)
void convert_color_profile(doc::Sprite* sprite,
const gfx::ColorSpacePtr& newCS)
{
os::System* system = os::instance();
ASSERT(sprite->colorSpace());
ASSERT(newCS);
os::System* system = os::instance();
auto srcOCS = system->createColorSpace(sprite->colorSpace());
auto dstOCS = system->createColorSpace(newCS);
ASSERT(srcOCS);
ASSERT(dstOCS);
@ -122,6 +121,46 @@ void convert_color_profile(doc::Sprite* sprite, const gfx::ColorSpacePtr& newCS)
static_cast<Doc*>(sprite->document())->notifyColorSpaceChanged();
}
void convert_color_profile(doc::Image* image,
doc::Palette* palette,
const gfx::ColorSpacePtr& oldCS,
const gfx::ColorSpacePtr& newCS)
{
ASSERT(oldCS);
ASSERT(newCS);
os::System* system = os::instance();
auto srcOCS = system->createColorSpace(oldCS);
auto dstOCS = system->createColorSpace(newCS);
ASSERT(srcOCS);
ASSERT(dstOCS);
auto conversion = system->convertBetweenColorSpace(srcOCS, dstOCS);
if (conversion) {
switch (image->pixelFormat()) {
case doc::IMAGE_RGB:
case doc::IMAGE_GRAYSCALE: {
ImageRef newImage = convert_image_color_space(
image, newCS, conversion.get());
image->copy(newImage.get(), gfx::Clip(image->bounds()));
break;
}
case doc::IMAGE_INDEXED: {
for (int i=0; i<palette->size(); ++i) {
color_t oldCol, newCol;
oldCol = newCol = palette->entry(i);
conversion->convertRgba((uint32_t*)&newCol,
(const uint32_t*)&oldCol, 1);
palette->setEntry(i, newCol);
}
break;
}
}
}
}
ConvertColorProfile::ConvertColorProfile(doc::Sprite* sprite, const gfx::ColorSpacePtr& newCS)
: WithSprite(sprite)
{

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2018-2019 Igara Studio S.A.
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -17,6 +17,11 @@ namespace gfx {
class ColorSpace;
}
namespace doc {
class Image;
class Palette;
}
namespace app {
namespace cmd {
@ -39,7 +44,13 @@ namespace cmd {
// Converts the sprite to the new color profile without undo information.
// TODO how to merge this function with cmd::ConvertColorProfile
void convert_color_profile(doc::Sprite* sprite, const gfx::ColorSpacePtr& newCS);
void convert_color_profile(doc::Sprite* sprite,
const gfx::ColorSpacePtr& newCS);
void convert_color_profile(doc::Image* image,
doc::Palette* palette,
const gfx::ColorSpacePtr& oldCS,
const gfx::ColorSpacePtr& newCS);
} // namespace cmd
} // namespace app

View File

@ -12,13 +12,12 @@
#include "app/thumbnail_generator.h"
#include "app/app.h"
#include "app/cmd/convert_color_profile.h"
#include "app/doc.h"
#include "app/file/file.h"
#include "app/file_system.h"
#include "app/ui/editor/editor_render.h"
#include "base/bind.h"
#include "base/scoped_lock.h"
#include "base/scoped_lock.h"
#include "base/thread.h"
#include "doc/algorithm/rotate.h"
#include "doc/conversion_to_surface.h"
@ -28,6 +27,7 @@
#include "doc/sprite.h"
#include "os/system.h"
#include "render/projection.h"
#include "render/render.h"
#include <memory>
#include <thread>
@ -125,12 +125,20 @@ private:
render::Projection proj(sprite->pixelRatio(),
render::Zoom(thumb_w, w));
EditorRender render;
render.setupBackground(NULL, thumbnailImage->pixelFormat());
render::Render render;
render.setBgType(render::BgType::TRANSPARENT);
render.setProjection(proj);
render.renderSprite(
thumbnailImage.get(), sprite, frame_t(0),
gfx::Clip(0, 0, 0, 0, w, h));
// Convert the image to sRGB color space
auto cs = sprite->colorSpace();
if (cs && !cs->nearlyEqual(*gfx::ColorSpace::MakeSRGB())) {
app::cmd::convert_color_profile(
thumbnailImage.get(), palette.get(),
cs, gfx::ColorSpace::MakeSRGB());
}
}
// Close file
@ -138,9 +146,10 @@ private:
// Set the thumbnail of the file-item.
if (thumbnailImage) {
os::Surface* thumbnail = os::instance()->createRgbaSurface(
thumbnailImage->width(),
thumbnailImage->height());
os::Surface* thumbnail =
os::instance()->createRgbaSurface(
thumbnailImage->width(),
thumbnailImage->height());
convert_image_to_surface(
thumbnailImage.get(), palette.get(), thumbnail,

View File

@ -429,7 +429,6 @@ void FileList::onPaint(ui::PaintEvent& ev)
g->fillRect(theme->colors.background(), bounds);
// g->fillRect(bgcolor, gfx::Rect(bounds.x, y, bounds.w, itemSize.h));
// os::Surface* mainThumbnail = nullptr;
int i = 0, selectedIndex = -1;
for (IFileItem* fi : m_list) {
if (m_selected != fi) {
@ -452,10 +451,14 @@ void FileList::onPaint(ui::PaintEvent& ev)
m_selected &&
m_selected->getThumbnail()) {
gfx::Rect tbounds = mainThumbnailBounds();
tbounds.enlarge(1);
g->drawRect(gfx::rgba(0, 0, 0, 64), tbounds);
tbounds.shrink(1);
g->blit(m_selected->getThumbnail(),
0, 0, tbounds.x, tbounds.y, tbounds.w, tbounds.h);
os::Surface* thumbnail = m_selected->getThumbnail();
g->drawRgbaSurface(thumbnail,
gfx::Rect(0, 0, thumbnail->width(), thumbnail->height()),
tbounds);
}
}