Skip to content

Commit

Permalink
Unify all render code in one library
Browse files Browse the repository at this point in the history
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 da1358c
Show file tree
Hide file tree
Showing 94 changed files with 2,200 additions and 1,492 deletions.
11 changes: 10 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions data/pref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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" />
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(aseprite_libraries
cfg-lib
css-lib
doc-lib
render-lib
scripting-lib
undo-lib
filters-lib
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down
5 changes: 3 additions & 2 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})
9 changes: 6 additions & 3 deletions src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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)");

Expand Down
76 changes: 76 additions & 0 deletions src/app/app_render.cpp
Original file line number Diff line number Diff line change
@@ -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);
}

}
38 changes: 15 additions & 23 deletions src/app/zoom.cpp → src/app/app_render.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion src/app/color_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "doc/primitives.h"
#include "doc/sprite.h"
#include "gfx/point.h"
#include "render/get_sprite_pixel.h"

namespace app {

Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/app/commands/cmd_change_pixel_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ChangePixelFormatCommand::ChangePixelFormatCommand()
CmdUIOnlyFlag)
{
m_format = IMAGE_RGB;
m_dithering = DITHERING_NONE;
m_dithering = DitheringMethod::NONE;
}

void ChangePixelFormatCommand::onLoadParams(Params* params)
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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
Expand Down
12 changes: 5 additions & 7 deletions src/app/commands/cmd_export_sprite_sheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions src/app/commands/cmd_import_sprite_sheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/commands/cmd_invert_mask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit da1358c

Please sign in to comment.