Permalink
Browse files

Unify all render code in one library

Changes:
* Create render library (move util/render.cpp to render/render.cpp)
* Move app::Zoom class to render::Zoom
* Remove doc::Image::merge() member function
* Add gfx::Clip helper class (to clip dst/src rectangles before a blit)
* Move doc::composite_image() to render::composite_image()
* Remove doc::Sprite::render()
* Replace Sprite::getPixel() with render::get_sprite_pixel()
* Remove doc::layer_render() function
* Convert DitheringMethod to a enum class
* Add AppRender to configure a render::Render with the app configuration
* Move checked background preferences as document-specific configuration
* Add doc::Sprite::layer() and palette() member functions
* Add doc::Layer::cel() member function
* Add doc::Palette::entry() member function()
* Add doc::frame_t type
* Move create_palette_from_rgb/convert_pixel_format to render library
* ExportSpriteSheet doesn't need a temporary image now that we can specify
  the source rectangle in the render routine
  • Loading branch information...
dacap committed Dec 28, 2014
1 parent 7365839 commit da1358c5dca2f2a309ffd6ecf0113fc9b9a836e3
Showing with 2,200 additions and 1,492 deletions.
  1. +10 −1 TODO.md
  2. +12 −0 data/pref.xml
  3. +3 −0 src/CMakeLists.txt
  4. +3 −2 src/README.md
  5. +1 −2 src/app/CMakeLists.txt
  6. +6 −3 src/app/app.cpp
  7. +76 −0 src/app/app_render.cpp
  8. +15 −23 src/app/{zoom.cpp → app_render.h}
  9. +2 −1 src/app/color_picker.cpp
  10. +5 −5 src/app/commands/cmd_change_pixel_format.cpp
  11. +5 −7 src/app/commands/cmd_export_sprite_sheet.cpp
  12. +6 −5 src/app/commands/cmd_import_sprite_sheet.cpp
  13. +3 −3 src/app/commands/cmd_invert_mask.cpp
  14. +6 −5 src/app/commands/cmd_merge_down_layer.cpp
  15. +21 −21 src/app/commands/cmd_options.cpp
  16. +5 −5 src/app/commands/cmd_palette_editor.cpp
  17. +27 −18 src/app/commands/cmd_preview.cpp
  18. +8 −7 src/app/commands/cmd_zoom.cpp
  19. +20 −19 src/app/commands/filters/filter_manager_impl.cpp
  20. +3 −3 src/app/commands/filters/filter_preview.cpp
  21. +15 −24 src/app/document_api.cpp
  22. +0 −1 src/app/document_api.h
  23. +8 −3 src/app/document_exporter.cpp
  24. +5 −3 src/app/file/file.cpp
  25. +5 −4 src/app/file/fli_format.cpp
  26. +18 −13 src/app/file/gif_format.cpp
  27. +1 −1 src/app/file/gif_options.h
  28. +3 −2 src/app/file/ico_format.cpp
  29. +6 −4 src/app/flatten.cpp
  30. +32 −19 src/app/pref/preferences.cpp
  31. +8 −2 src/app/pref/preferences.h
  32. +8 −9 src/app/thumbnail_generator.cpp
  33. +5 −2 src/app/tools/tool_loop.h
  34. +4 −4 src/app/tools/tool_loop_manager.cpp
  35. +78 −47 src/app/ui/editor/editor.cpp
  36. +12 −6 src/app/ui/editor/editor.h
  37. +2 −1 src/app/ui/editor/pixels_movement.cpp
  38. +1 −1 src/app/ui/editor/select_box_state.cpp
  39. +1 −1 src/app/ui/editor/standby_state.cpp
  40. +1 −1 src/app/ui/editor/tool_loop_impl.cpp
  41. +2 −2 src/app/ui/editor/zooming_state.cpp
  42. +2 −2 src/app/ui/editor/zooming_state.h
  43. +1 −1 src/app/ui/mini_editor.cpp
  44. +3 −0 src/app/ui_context.cpp
  45. +3 −2 src/app/util/clipboard.cpp
  46. +14 −10 src/app/util/expand_cel_canvas.cpp
  47. +1 −1 src/app/util/msk_file.cpp
  48. +0 −753 src/app/util/render.cpp
  49. +0 −110 src/app/util/render.h
  50. +0 −1 src/doc/CMakeLists.txt
  51. +2 −2 src/doc/algorithm/flip_image.cpp
  52. +1 −1 src/doc/algorithm/rotate.cpp
  53. +2 −2 src/doc/algorithm/rotsprite.cpp
  54. +12 −6 src/doc/blend.cpp
  55. +2 −0 src/doc/blend.h
  56. +3 −3 src/doc/dithering_method.h
  57. +0 −1 src/doc/doc.h
  58. +2 −0 src/doc/frame_number.h
  59. +4 −4 src/doc/image.h
  60. +17 −108 src/doc/image_impl.h
  61. +5 −0 src/doc/image_traits.h
  62. +10 −42 src/doc/layer.cpp
  63. +2 −2 src/doc/layer.h
  64. +1 −1 src/doc/mask.cpp
  65. +4 −0 src/doc/palette.h
  66. +5 −5 src/doc/primitives.cpp
  67. +1 −2 src/doc/primitives.h
  68. +0 −62 src/doc/quantization.h
  69. +11 −23 src/doc/sprite.cpp
  70. +2 −11 src/doc/sprite.h
  71. +1 −0 src/gfx/CMakeLists.txt
  72. +64 −0 src/gfx/clip.cpp
  73. +85 −0 src/gfx/clip.h
  74. +100 −0 src/gfx/clip_tests.cpp
  75. +4 −0 src/gfx/hsv.cpp
  76. +4 −0 src/gfx/hsv_tests.cpp
  77. +4 −0 src/gfx/packing_rects_tests.cpp
  78. +1 −1 src/gfx/rect_io.h
  79. +4 −0 src/gfx/rect_tests.cpp
  80. +4 −0 src/gfx/rgb_tests.cpp
  81. +8 −0 src/render/CMakeLists.txt
  82. +20 −0 src/render/LICENSE.txt
  83. +4 −0 src/render/README.md
  84. +8 −8 src/{doc → render}/color_histogram.h
  85. +35 −0 src/render/get_sprite_pixel.cpp
  86. +27 −0 src/render/get_sprite_pixel.h
  87. +5 −7 src/{doc → render}/median_cut.h
  88. +20 −18 src/{doc → render}/quantization.cpp
  89. +63 −0 src/render/quantization.h
  90. +738 −0 src/render/render.cpp
  91. +172 −0 src/render/render.h
  92. +221 −0 src/render/render_tests.cpp
  93. +35 −0 src/render/zoom.cpp
  94. +11 −23 src/{app → render}/zoom.h
View
11 TODO.md
@@ -43,8 +43,17 @@
# Refactoring
* Convert doc::PixelFormat to a enum class
* Add doc::Spec with width/height/channels/ColorMode/ncolors
* Convert doc::LayerIndex -> typedef int doc::layer_t;
* Convert doc::FrameNumber -> typedef int doc::frame_t;
* Replace doc::LayerImage::getCel() with doc::Layer::cel()
* Replace doc::Sprite::getPalette() with doc::Sprite::palette()
* Replace doc::Palette::getEntry() with doc::Palette::entry()
* Remove LayerFolder, replace it with an array of layers
* Add new "level" into Layer class
* Refactor src/file/ in several layers.
* Use streams instead of FILEs.
* Use streams instead of FILEs and create load/save tests with streams.
* Destroy modules/gui.h.
* Convert update_screen_for_document in an event from contexts or
something similar.
View
@@ -46,6 +46,12 @@
<value id="FAST" value="0" />
<value id="ROTSPRITE" value="1" />
</enum>
<enum id="BgType">
<value id="CHECKED_16x16" value="0" />
<value id="CHECKED_8x8" value="1" />
<value id="CHECKED_4x4" value="2" />
<value id="CHECKED_2x2" value="3" />
</enum>
</types>
<global>
@@ -116,6 +122,12 @@
<option id="opacity" type="int" default="160" />
<option id="auto_opacity" type="bool" default="true" />
</section>
<section id="bg">
<option id="type" type="BgType" default="BgType::CHECKED_16x16" migrate="Option.CheckedBgType" />
<option id="zoom" type="bool" default="true" migrate="Option.CheckedBgZoom" />
<option id="color1" type="app::Color" default="app::Color::fromRgb(128, 128, 128)" migrate="Option.CheckedBgColor1" />
<option id="color2" type="app::Color" default="app::Color::fromRgb(192, 192, 192)" migrate="Option.CheckedBgColor2" />
</section>
<section id="onionskin">
<option id="active" type="bool" default="false" />
<option id="prev_frames" type="int" default="1" />
View
@@ -28,6 +28,7 @@ set(aseprite_libraries
cfg-lib
css-lib
doc-lib
render-lib
scripting-lib
undo-lib
filters-lib
@@ -210,6 +211,7 @@ add_subdirectory(base)
add_subdirectory(cfg)
add_subdirectory(css)
add_subdirectory(doc)
add_subdirectory(render)
add_subdirectory(filters)
add_subdirectory(fixmath)
add_subdirectory(gen)
@@ -328,6 +330,7 @@ endfunction()
find_tests(base base-lib ${sys_libs})
find_tests(gfx gfx-lib base-lib ${libs3rdparty} ${sys_libs})
find_tests(doc doc-lib gfx-lib base-lib ${libs3rdparty} ${sys_libs})
find_tests(render render-lib doc-lib gfx-lib base-lib ${libs3rdparty} ${sys_libs})
find_tests(css css-lib gfx-lib base-lib ${libs3rdparty} ${sys_libs})
find_tests(ui ui-lib she gfx-lib base-lib ${libs3rdparty} ${sys_libs})
find_tests(app/file ${all_libs})
View
@@ -32,16 +32,17 @@ because they don't depend on any other component.
## Level 2
* [filters](filters/) (base, doc, gfx): Effects for images.
* [render](render/) (base, gfx, doc): Library to render documents.
* [ui](ui/) (base, gfx, she): Portable UI library (buttons, windows, text fields, etc.)
* [updater](updater/) (base, net): Component to check for updates.
## Level 3
* [iff](iff/) (base, doc): Image File Formats library (load/save documents).
* [iff](iff/) (base, doc, render): Image File Formats library (load/save documents).
## Level 4
* [app](app/) (allegro, base, doc, filters, gfx, iff, scripting, she, ui, undo, updater, webserver)
* [app](app/) (allegro, base, doc, filters, gfx, iff, render, scripting, she, ui, undo, updater, webserver)
## Level 5
View
@@ -50,6 +50,7 @@ add_library(app-lib
app.cpp
app_menus.cpp
app_options.cpp
app_render.cpp
backup.cpp
check_update.cpp
color.cpp
@@ -303,10 +304,8 @@ add_library(app-lib
util/msk_file.cpp
util/pic_file.cpp
util/range_utils.cpp
util/render.cpp
webserver.cpp
widget_loader.cpp
xml_document.cpp
xml_exception.cpp
zoom.cpp
${generated_files})
View
@@ -64,7 +64,6 @@
#include "app/ui/toolbar.h"
#include "app/ui_context.h"
#include "app/util/boundary.h"
#include "app/util/render.h"
#include "app/webserver.h"
#include "base/exception.h"
#include "base/fs.h"
@@ -75,6 +74,7 @@
#include "doc/layer.h"
#include "doc/palette.h"
#include "doc/sprite.h"
#include "render/render.h"
#include "scripting/engine.h"
#include "she/display.h"
#include "she/error.h"
@@ -153,8 +153,6 @@ void App::initialize(const AppOptions& options)
// init editor cursor
Editor::editor_cursor_init();
// Load RenderEngine configuration
RenderEngine::loadConfig();
if (isPortable())
PRINTF("Running in portable mode\n");
@@ -492,6 +490,11 @@ App::~App()
m_instance = NULL;
}
catch (const std::exception& e) {
she::error_message(e.what());
// no re-throw
}
catch (...) {
she::error_message("Error closing ASE.\n(uncaught exception)");
View
@@ -0,0 +1,76 @@
/* Aseprite
* Copyright (C) 2001-2014 David Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/app_render.h"
#include "app/app.h"
#include "app/color_utils.h"
#include "app/pref/preferences.h"
#include "render/render.h"
namespace app {
AppRender::AppRender()
{
}
AppRender::AppRender(app::Document* doc, doc::PixelFormat pixelFormat)
{
setupBackground(doc, pixelFormat);
}
void AppRender::setupBackground(app::Document* doc, doc::PixelFormat pixelFormat)
{
DocumentPreferences& docPref = App::instance()->preferences().document(doc);
render::BgType bgType;
gfx::Size tile;
switch (docPref.bg.type()) {
case app::gen::BgType::CHECKED_16x16:
bgType = render::BgType::CHECKED;
tile = gfx::Size(16, 16);
break;
case app::gen::BgType::CHECKED_8x8:
bgType = render::BgType::CHECKED;
tile = gfx::Size(8, 8);
break;
case app::gen::BgType::CHECKED_4x4:
bgType = render::BgType::CHECKED;
tile = gfx::Size(4, 4);
break;
case app::gen::BgType::CHECKED_2x2:
bgType = render::BgType::CHECKED;
tile = gfx::Size(2, 2);
break;
default:
bgType = render::BgType::TRANSPARENT;
break;
}
setBgType(bgType);
setBgZoom(docPref.bg.zoom());
setBgColor1(color_utils::color_for_image(docPref.bg.color1(), pixelFormat));
setBgColor2(color_utils::color_for_image(docPref.bg.color2(), pixelFormat));
setBgCheckedSize(tile);
}
}
@@ -1,5 +1,5 @@
/* Aseprite
* Copyright (C) 2001-2014 David Capello
* Copyright (C) 2001-2013 David Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,32 +16,24 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef APP_RENDER_H_INCLUDED
#define APP_RENDER_H_INCLUDED
#pragma once
#include "app/zoom.h"
#include "doc/pixel_format.h"
#include "render/render.h"
namespace app {
class Document;
void Zoom::in()
{
if (m_den > 1) {
m_den--;
}
else if (m_num < 64) {
m_num++;
}
}
class AppRender : public render::Render {
public:
AppRender();
AppRender(app::Document* doc, doc::PixelFormat pixelFormat);
void Zoom::out()
{
if (m_num > 1) {
m_num--;
}
else if (m_den < 32) {
m_den++;
}
}
void setupBackground(app::Document* doc, doc::PixelFormat pixelFormat);
};
} // namespace app
#endif // APP_RENDER_H_INCLUDED
View
@@ -28,6 +28,7 @@
#include "doc/primitives.h"
#include "doc/sprite.h"
#include "gfx/point.h"
#include "render/get_sprite_pixel.h"
namespace app {
@@ -47,7 +48,7 @@ void ColorPicker::pickColor(const DocumentLocation& location,
if (mode == FromComposition) { // Pick from the composed image
m_color = app::Color::fromImage(
location.sprite()->pixelFormat(),
location.sprite()->getPixel(pos.x, pos.y, location.frame()));
render::get_sprite_pixel(location.sprite(), pos.x, pos.y, location.frame()));
doc::CelList cels;
location.sprite()->pickCels(pos.x, pos.y, location.frame(), 128, cels);
@@ -54,7 +54,7 @@ ChangePixelFormatCommand::ChangePixelFormatCommand()
CmdUIOnlyFlag)
{
m_format = IMAGE_RGB;
m_dithering = DITHERING_NONE;
m_dithering = DitheringMethod::NONE;
}
void ChangePixelFormatCommand::onLoadParams(Params* params)
@@ -66,9 +66,9 @@ void ChangePixelFormatCommand::onLoadParams(Params* params)
std::string dithering = params->get("dithering");
if (dithering == "ordered")
m_dithering = DITHERING_ORDERED;
m_dithering = DitheringMethod::ORDERED;
else
m_dithering = DITHERING_NONE;
m_dithering = DitheringMethod::NONE;
}
bool ChangePixelFormatCommand::onEnabled(Context* context)
@@ -79,7 +79,7 @@ bool ChangePixelFormatCommand::onEnabled(Context* context)
if (sprite != NULL &&
sprite->pixelFormat() == IMAGE_INDEXED &&
m_format == IMAGE_INDEXED &&
m_dithering == DITHERING_ORDERED)
m_dithering == DitheringMethod::ORDERED)
return false;
return sprite != NULL;
@@ -93,7 +93,7 @@ bool ChangePixelFormatCommand::onChecked(Context* context)
if (sprite != NULL &&
sprite->pixelFormat() == IMAGE_INDEXED &&
m_format == IMAGE_INDEXED &&
m_dithering == DITHERING_ORDERED)
m_dithering == DitheringMethod::ORDERED)
return false;
return
@@ -328,17 +328,15 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
columns = sheet_w / sprite->width();
base::UniquePtr<Image> resultImage(Image::create(sprite->pixelFormat(), sheet_w, sheet_h));
base::UniquePtr<Image> tempImage(Image::create(sprite->pixelFormat(), sprite->width(), sprite->height()));
doc::clear_image(resultImage, 0);
render::Render render;
int column = 0, row = 0;
for (FrameNumber frame(0); frame<nframes; ++frame) {
// TODO "tempImage" could not be necessary if we could specify
// destination clipping bounds in Sprite::render() function.
tempImage->clear(0);
sprite->render(tempImage, 0, 0, frame);
resultImage->copy(tempImage, column*sprite->width(), row*sprite->height(),
0, 0, tempImage->width(), tempImage->height());
render.renderSprite(resultImage, sprite, frame,
gfx::Clip(column*sprite->width(), row*sprite->height(),
sprite->bounds()));
if (++column >= columns) {
column = 0;
@@ -165,17 +165,18 @@ class ImportSpriteSheetWindow : public Window,
try {
Sprite* sprite = m_document->sprite();
FrameNumber currentFrame = m_context->activeLocation().frame();
render::Render render;
// As first step, we cut each tile and add them into "animation" list.
for (int y=m_rect.y; y<sprite->height(); y += m_rect.h) {
for (int x=m_rect.x; x<sprite->width(); x += m_rect.w) {
base::UniquePtr<Image> resultImage(Image::create(sprite->pixelFormat(), m_rect.w, m_rect.h));
// Clear the image with mask color.
doc::clear_image(resultImage, 0);
base::UniquePtr<Image> resultImage(
Image::create(sprite->pixelFormat(), m_rect.w, m_rect.h));
// Render the portion of sheet.
sprite->render(resultImage, -x, -y, currentFrame);
render.renderSprite(resultImage, sprite, currentFrame,
gfx::Clip(0, 0, x, y, m_rect.w, m_rect.h));
animation.push_back(resultImage);
resultImage.release();
}
@@ -98,9 +98,9 @@ void InvertMaskCommand::onExecute(Context* context)
if (document->mask()->bitmap()) {
// Copy the inverted region in the new mask
doc::copy_image(mask->bitmap(),
document->mask()->bitmap(),
document->mask()->bounds().x,
document->mask()->bounds().y);
document->mask()->bitmap(),
document->mask()->bounds().x,
document->mask()->bounds().y);
}
// We need only need the area inside the sprite
Oops, something went wrong.

0 comments on commit da1358c

Please sign in to comment.