Skip to content

Commit da1358c

Browse files
committed
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
1 parent 7365839 commit da1358c

94 files changed

Lines changed: 2200 additions & 1492 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

TODO.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,17 @@
4343

4444
# Refactoring
4545

46+
* Convert doc::PixelFormat to a enum class
47+
* Add doc::Spec with width/height/channels/ColorMode/ncolors
48+
* Convert doc::LayerIndex -> typedef int doc::layer_t;
49+
* Convert doc::FrameNumber -> typedef int doc::frame_t;
50+
* Replace doc::LayerImage::getCel() with doc::Layer::cel()
51+
* Replace doc::Sprite::getPalette() with doc::Sprite::palette()
52+
* Replace doc::Palette::getEntry() with doc::Palette::entry()
53+
* Remove LayerFolder, replace it with an array of layers
54+
* Add new "level" into Layer class
4655
* Refactor src/file/ in several layers.
47-
* Use streams instead of FILEs.
56+
* Use streams instead of FILEs and create load/save tests with streams.
4857
* Destroy modules/gui.h.
4958
* Convert update_screen_for_document in an event from contexts or
5059
something similar.

data/pref.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
<value id="FAST" value="0" />
4747
<value id="ROTSPRITE" value="1" />
4848
</enum>
49+
<enum id="BgType">
50+
<value id="CHECKED_16x16" value="0" />
51+
<value id="CHECKED_8x8" value="1" />
52+
<value id="CHECKED_4x4" value="2" />
53+
<value id="CHECKED_2x2" value="3" />
54+
</enum>
4955
</types>
5056

5157
<global>
@@ -116,6 +122,12 @@
116122
<option id="opacity" type="int" default="160" />
117123
<option id="auto_opacity" type="bool" default="true" />
118124
</section>
125+
<section id="bg">
126+
<option id="type" type="BgType" default="BgType::CHECKED_16x16" migrate="Option.CheckedBgType" />
127+
<option id="zoom" type="bool" default="true" migrate="Option.CheckedBgZoom" />
128+
<option id="color1" type="app::Color" default="app::Color::fromRgb(128, 128, 128)" migrate="Option.CheckedBgColor1" />
129+
<option id="color2" type="app::Color" default="app::Color::fromRgb(192, 192, 192)" migrate="Option.CheckedBgColor2" />
130+
</section>
119131
<section id="onionskin">
120132
<option id="active" type="bool" default="false" />
121133
<option id="prev_frames" type="int" default="1" />

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ set(aseprite_libraries
2828
cfg-lib
2929
css-lib
3030
doc-lib
31+
render-lib
3132
scripting-lib
3233
undo-lib
3334
filters-lib
@@ -210,6 +211,7 @@ add_subdirectory(base)
210211
add_subdirectory(cfg)
211212
add_subdirectory(css)
212213
add_subdirectory(doc)
214+
add_subdirectory(render)
213215
add_subdirectory(filters)
214216
add_subdirectory(fixmath)
215217
add_subdirectory(gen)
@@ -328,6 +330,7 @@ endfunction()
328330
find_tests(base base-lib ${sys_libs})
329331
find_tests(gfx gfx-lib base-lib ${libs3rdparty} ${sys_libs})
330332
find_tests(doc doc-lib gfx-lib base-lib ${libs3rdparty} ${sys_libs})
333+
find_tests(render render-lib doc-lib gfx-lib base-lib ${libs3rdparty} ${sys_libs})
331334
find_tests(css css-lib gfx-lib base-lib ${libs3rdparty} ${sys_libs})
332335
find_tests(ui ui-lib she gfx-lib base-lib ${libs3rdparty} ${sys_libs})
333336
find_tests(app/file ${all_libs})

src/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@ because they don't depend on any other component.
3232
## Level 2
3333

3434
* [filters](filters/) (base, doc, gfx): Effects for images.
35+
* [render](render/) (base, gfx, doc): Library to render documents.
3536
* [ui](ui/) (base, gfx, she): Portable UI library (buttons, windows, text fields, etc.)
3637
* [updater](updater/) (base, net): Component to check for updates.
3738

3839
## Level 3
3940

40-
* [iff](iff/) (base, doc): Image File Formats library (load/save documents).
41+
* [iff](iff/) (base, doc, render): Image File Formats library (load/save documents).
4142

4243
## Level 4
4344

44-
* [app](app/) (allegro, base, doc, filters, gfx, iff, scripting, she, ui, undo, updater, webserver)
45+
* [app](app/) (allegro, base, doc, filters, gfx, iff, render, scripting, she, ui, undo, updater, webserver)
4546

4647
## Level 5
4748

src/app/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ add_library(app-lib
5050
app.cpp
5151
app_menus.cpp
5252
app_options.cpp
53+
app_render.cpp
5354
backup.cpp
5455
check_update.cpp
5556
color.cpp
@@ -303,10 +304,8 @@ add_library(app-lib
303304
util/msk_file.cpp
304305
util/pic_file.cpp
305306
util/range_utils.cpp
306-
util/render.cpp
307307
webserver.cpp
308308
widget_loader.cpp
309309
xml_document.cpp
310310
xml_exception.cpp
311-
zoom.cpp
312311
${generated_files})

src/app/app.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
#include "app/ui/toolbar.h"
6565
#include "app/ui_context.h"
6666
#include "app/util/boundary.h"
67-
#include "app/util/render.h"
6867
#include "app/webserver.h"
6968
#include "base/exception.h"
7069
#include "base/fs.h"
@@ -75,6 +74,7 @@
7574
#include "doc/layer.h"
7675
#include "doc/palette.h"
7776
#include "doc/sprite.h"
77+
#include "render/render.h"
7878
#include "scripting/engine.h"
7979
#include "she/display.h"
8080
#include "she/error.h"
@@ -153,8 +153,6 @@ void App::initialize(const AppOptions& options)
153153
// init editor cursor
154154
Editor::editor_cursor_init();
155155

156-
// Load RenderEngine configuration
157-
RenderEngine::loadConfig();
158156
if (isPortable())
159157
PRINTF("Running in portable mode\n");
160158

@@ -492,6 +490,11 @@ App::~App()
492490

493491
m_instance = NULL;
494492
}
493+
catch (const std::exception& e) {
494+
she::error_message(e.what());
495+
496+
// no re-throw
497+
}
495498
catch (...) {
496499
she::error_message("Error closing ASE.\n(uncaught exception)");
497500

src/app/app_render.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* Aseprite
2+
* Copyright (C) 2001-2014 David Capello
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
19+
#ifdef HAVE_CONFIG_H
20+
#include "config.h"
21+
#endif
22+
23+
#include "app/app_render.h"
24+
25+
#include "app/app.h"
26+
#include "app/color_utils.h"
27+
#include "app/pref/preferences.h"
28+
#include "render/render.h"
29+
30+
namespace app {
31+
32+
AppRender::AppRender()
33+
{
34+
}
35+
36+
AppRender::AppRender(app::Document* doc, doc::PixelFormat pixelFormat)
37+
{
38+
setupBackground(doc, pixelFormat);
39+
}
40+
41+
void AppRender::setupBackground(app::Document* doc, doc::PixelFormat pixelFormat)
42+
{
43+
DocumentPreferences& docPref = App::instance()->preferences().document(doc);
44+
render::BgType bgType;
45+
46+
gfx::Size tile;
47+
switch (docPref.bg.type()) {
48+
case app::gen::BgType::CHECKED_16x16:
49+
bgType = render::BgType::CHECKED;
50+
tile = gfx::Size(16, 16);
51+
break;
52+
case app::gen::BgType::CHECKED_8x8:
53+
bgType = render::BgType::CHECKED;
54+
tile = gfx::Size(8, 8);
55+
break;
56+
case app::gen::BgType::CHECKED_4x4:
57+
bgType = render::BgType::CHECKED;
58+
tile = gfx::Size(4, 4);
59+
break;
60+
case app::gen::BgType::CHECKED_2x2:
61+
bgType = render::BgType::CHECKED;
62+
tile = gfx::Size(2, 2);
63+
break;
64+
default:
65+
bgType = render::BgType::TRANSPARENT;
66+
break;
67+
}
68+
69+
setBgType(bgType);
70+
setBgZoom(docPref.bg.zoom());
71+
setBgColor1(color_utils::color_for_image(docPref.bg.color1(), pixelFormat));
72+
setBgColor2(color_utils::color_for_image(docPref.bg.color2(), pixelFormat));
73+
setBgCheckedSize(tile);
74+
}
75+
76+
}
Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Aseprite
2-
* Copyright (C) 2001-2014 David Capello
2+
* Copyright (C) 2001-2013 David Capello
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -16,32 +16,24 @@
1616
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1717
*/
1818

19-
#ifdef HAVE_CONFIG_H
20-
#include "config.h"
21-
#endif
19+
#ifndef APP_RENDER_H_INCLUDED
20+
#define APP_RENDER_H_INCLUDED
21+
#pragma once
2222

23-
#include "app/zoom.h"
23+
#include "doc/pixel_format.h"
24+
#include "render/render.h"
2425

2526
namespace app {
27+
class Document;
2628

27-
void Zoom::in()
28-
{
29-
if (m_den > 1) {
30-
m_den--;
31-
}
32-
else if (m_num < 64) {
33-
m_num++;
34-
}
35-
}
29+
class AppRender : public render::Render {
30+
public:
31+
AppRender();
32+
AppRender(app::Document* doc, doc::PixelFormat pixelFormat);
3633

37-
void Zoom::out()
38-
{
39-
if (m_num > 1) {
40-
m_num--;
41-
}
42-
else if (m_den < 32) {
43-
m_den++;
44-
}
45-
}
34+
void setupBackground(app::Document* doc, doc::PixelFormat pixelFormat);
35+
};
4636

4737
} // namespace app
38+
39+
#endif // APP_RENDER_H_INCLUDED

src/app/color_picker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "doc/primitives.h"
2929
#include "doc/sprite.h"
3030
#include "gfx/point.h"
31+
#include "render/get_sprite_pixel.h"
3132

3233
namespace app {
3334

@@ -47,7 +48,7 @@ void ColorPicker::pickColor(const DocumentLocation& location,
4748
if (mode == FromComposition) { // Pick from the composed image
4849
m_color = app::Color::fromImage(
4950
location.sprite()->pixelFormat(),
50-
location.sprite()->getPixel(pos.x, pos.y, location.frame()));
51+
render::get_sprite_pixel(location.sprite(), pos.x, pos.y, location.frame()));
5152

5253
doc::CelList cels;
5354
location.sprite()->pickCels(pos.x, pos.y, location.frame(), 128, cels);

src/app/commands/cmd_change_pixel_format.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ChangePixelFormatCommand::ChangePixelFormatCommand()
5454
CmdUIOnlyFlag)
5555
{
5656
m_format = IMAGE_RGB;
57-
m_dithering = DITHERING_NONE;
57+
m_dithering = DitheringMethod::NONE;
5858
}
5959

6060
void ChangePixelFormatCommand::onLoadParams(Params* params)
@@ -66,9 +66,9 @@ void ChangePixelFormatCommand::onLoadParams(Params* params)
6666

6767
std::string dithering = params->get("dithering");
6868
if (dithering == "ordered")
69-
m_dithering = DITHERING_ORDERED;
69+
m_dithering = DitheringMethod::ORDERED;
7070
else
71-
m_dithering = DITHERING_NONE;
71+
m_dithering = DitheringMethod::NONE;
7272
}
7373

7474
bool ChangePixelFormatCommand::onEnabled(Context* context)
@@ -79,7 +79,7 @@ bool ChangePixelFormatCommand::onEnabled(Context* context)
7979
if (sprite != NULL &&
8080
sprite->pixelFormat() == IMAGE_INDEXED &&
8181
m_format == IMAGE_INDEXED &&
82-
m_dithering == DITHERING_ORDERED)
82+
m_dithering == DitheringMethod::ORDERED)
8383
return false;
8484

8585
return sprite != NULL;
@@ -93,7 +93,7 @@ bool ChangePixelFormatCommand::onChecked(Context* context)
9393
if (sprite != NULL &&
9494
sprite->pixelFormat() == IMAGE_INDEXED &&
9595
m_format == IMAGE_INDEXED &&
96-
m_dithering == DITHERING_ORDERED)
96+
m_dithering == DitheringMethod::ORDERED)
9797
return false;
9898

9999
return

0 commit comments

Comments
 (0)