Merge branch 'timeline-thumbnails2' of https://github.com/pseudogames/aseprite into pseudogames-timeline-thumbnails2

This commit is contained in:
David Capello 2016-09-26 11:48:32 -03:00
commit b41ad4dd21
6 changed files with 31 additions and 63 deletions

View File

@ -278,9 +278,7 @@
<option id="enabled" type="bool" default="false" />
<option id="overlay_enabled" type="bool" default="false" />
<option id="overlay_size" type="int" default="5" />
<option id="quality" type="doc::algorithm::ResizeMethod" default="doc::algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR" />
<option id="opacity" type="int" default="255" />
<option id="background" type="app::Color" default="app::Color::fromRgb(180, 180, 180, 220)" />
</section>
<section id="onionskin">
<option id="active" type="bool" default="false" migrate="Onionskin.Enabled" />

View File

@ -20,13 +20,6 @@
<check id="thumb_overlay_enabled" text="Overlay"/>
<label text="Size:" />
<slider min="2" max="10" id="thumb_overlay_size" cell_align="horizontal" width="128" />
<label text="Quality:" />
<combobox id="thumb_quality" expansive="true" cell_hspan="2" />
<label text="Background:" />
<colorpicker id="thumb_background" expansive="true" cell_hspan="2" />
</grid>
<separator cell_hspan="2" text="Onion Skin:" left="true" horizontal="true" />

View File

@ -32,29 +32,51 @@ namespace app {
DocumentPreferences& docPref = Preferences::instance().document(document);
int opacity = docPref.thumbnails.opacity();
gfx::Color background = color_utils::color_for_ui(docPref.thumbnails.background());
doc::algorithm::ResizeMethod resize_method = docPref.thumbnails.quality();
doc::color_t bg1 = color_utils::color_for_image(docPref.bg.color1(), image->pixelFormat());
doc::color_t bg2 = color_utils::color_for_image(docPref.bg.color2(), image->pixelFormat());
gfx::Size image_size = image->size();
if (cel_image_on_thumb.isEmpty()) {
double zw = thumb_size.w / (double)image_size.w;
double zh = thumb_size.h / (double)image_size.h;
double zoom = MIN(1, MIN(zw, zh));
double zoom = MIN(1.0, MIN(zw, zh));
cel_image_on_thumb = gfx::Rect(
(int)(thumb_size.w * 0.5 - image_size.w * zoom * 0.5),
(int)(thumb_size.h * 0.5 - image_size.h * zoom * 0.5),
(int)(image_size.w * zoom),
(int)(image_size.h * zoom)
MAX(1, (int)(image_size.w * zoom)),
MAX(1, (int)(image_size.h * zoom))
);
}
const doc::Sprite* sprite = document->sprite();
// TODO doc::Image::createCopy() from pre-rendered checkered background
base::UniquePtr<doc::Image> thumb_img(doc::Image::create(
image->pixelFormat(), thumb_size.w, thumb_size.h));
clear_image(thumb_img.get(), background);
double alpha = opacity / 255.0;
uint8_t bg_r[] = { rgba_getr(bg1), rgba_getr(bg2) };
uint8_t bg_g[] = { rgba_getg(bg1), rgba_getg(bg2) };
uint8_t bg_b[] = { rgba_getb(bg1), rgba_getb(bg2) };
uint8_t bg_a[] = { rgba_geta(bg1), rgba_geta(bg2) };
doc::color_t bg[] = {
rgba(bg_r[0], bg_g[0], bg_b[0], (int)(bg_a[0] * alpha)),
rgba(bg_r[1], bg_g[1], bg_b[1], (int)(bg_a[1] * alpha))
};
int block_size = MID(4, thumb_size.w/8, 16);
for (int dst_y = 0; dst_y < thumb_size.h; dst_y++) {
for (int dst_x = 0; dst_x < thumb_size.w; dst_x++) {
thumb_img->putPixel(dst_x, dst_y,
bg[
((dst_x / block_size) % 2) ^
((dst_y / block_size) % 2)
]
);
}
}
base::UniquePtr<doc::Image> scale_img;
const doc::Image* source = image;
@ -65,7 +87,7 @@ namespace app {
doc::algorithm::resize_image(
image, scale_img,
resize_method,
doc::algorithm::ResizeMethod::RESIZE_METHOD_NEAREST_NEIGHBOR,
sprite->palette(frame),
sprite->rgbMap(frame),
sprite->transparentColor());

View File

@ -63,15 +63,9 @@ ConfigureTimelinePopup::ConfigureTimelinePopup()
m_box->infront()->Click.connect(base::Bind<void>(&ConfigureTimelinePopup::onPositionChange, this));
m_box->thumbOpacity()->Change.connect(base::Bind<void>(&ConfigureTimelinePopup::onThumbOpacityChange, this));
m_box->thumbBackground()->Change.connect(&ConfigureTimelinePopup::onThumbBackgroundChange, this);
m_box->thumbEnabled()->Click.connect(base::Bind<void>(&ConfigureTimelinePopup::onThumbEnabledChange, this));
m_box->thumbOverlayEnabled()->Click.connect(base::Bind<void>(&ConfigureTimelinePopup::onThumbOverlayEnabledChange, this));
m_box->thumbOverlaySize()->Change.connect(base::Bind<void>(&ConfigureTimelinePopup::onThumbOverlaySizeChange, this));
m_box->thumbQuality()->addItem("Nearest-neighbor");
m_box->thumbQuality()->addItem("Bilinear");
// m_box->thumbQuality()->addItem("RotSprite");
m_box->thumbQuality()->Change.connect(&ConfigureTimelinePopup::onThumbQualityChange, this);
}
app::Document* ConfigureTimelinePopup::doc()
@ -129,21 +123,7 @@ void ConfigureTimelinePopup::updateWidgetsFromCurrentSettings()
break;
}
switch (docPref.thumbnails.quality()) {
case doc::algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR:
m_box->thumbQuality()->setSelectedItemIndex(0);
break;
case doc::algorithm::RESIZE_METHOD_BILINEAR:
m_box->thumbQuality()->setSelectedItemIndex(1);
break;
default:
docPref.thumbnails.quality(doc::algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR);
m_box->thumbQuality()->setSelectedItemIndex(0);
break;
}
m_box->thumbOpacity()->setValue(docPref.thumbnails.opacity());
m_box->thumbBackground()->setColor(docPref.thumbnails.background());
m_box->thumbEnabled()->setSelected(docPref.thumbnails.enabled());
m_box->thumbOverlayEnabled()->setSelected(docPref.thumbnails.overlayEnabled());
m_box->thumbOverlaySize()->setValue(docPref.thumbnails.overlaySize());
@ -237,27 +217,6 @@ void ConfigureTimelinePopup::onThumbOpacityChange()
docPref().thumbnails.opacity(m_box->thumbOpacity()->getValue());
}
void ConfigureTimelinePopup::onThumbQualityChange()
{
switch (m_box->thumbQuality()->getSelectedItemIndex()) {
case 0:
docPref().thumbnails.quality(doc::algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR);
break;
case 1:
docPref().thumbnails.quality(doc::algorithm::RESIZE_METHOD_BILINEAR);
break;
default:
docPref().thumbnails.quality(doc::algorithm::RESIZE_METHOD_NEAREST_NEIGHBOR);
m_box->thumbQuality()->setSelectedItemIndex(0);
break;
}
}
void ConfigureTimelinePopup::onThumbBackgroundChange(const app::Color& color)
{
docPref().thumbnails.background(color);
}
void ConfigureTimelinePopup::onThumbEnabledChange()
{
docPref().thumbnails.enabled(m_box->thumbEnabled()->isSelected());

View File

@ -42,8 +42,6 @@ namespace app {
void onPositionChange();
void onThumbOpacityChange();
void onThumbQualityChange();
void onThumbBackgroundChange(const app::Color& color);
void onThumbEnabledChange();
void onThumbOverlayEnabledChange();
void onThumbOverlaySizeChange();

View File

@ -1861,11 +1861,9 @@ void Timeline::drawCelOverlay(ui::Graphics* g)
she::Surface* overlay_surf = thumb::get_cel_thumbnail(cel, overlay_size, cel_image_on_overlay);
gfx::Color background = color_utils::color_for_ui(docPref().thumbnails.background());
gfx::Color border = color_utils::blackandwhite_neg(background);
g->drawRgbaSurface(overlay_surf,
m_thumbnailsOverlayInner.x, m_thumbnailsOverlayInner.y);
g->drawRect(border, m_thumbnailsOverlayOuter);
g->drawRect(gfx::rgba(0,0,0,255), m_thumbnailsOverlayOuter);
overlay_surf->dispose();
}