forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_sprite_pixel.cpp
47 lines (37 loc) · 1.21 KB
/
get_sprite_pixel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Aseprite Render Library
// Copyright (c) 2019 Igara Studio S.A.
// Copyright (c) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "doc/doc.h"
#include "gfx/clip.h"
#include "render/render.h"
namespace render {
using namespace doc;
color_t get_sprite_pixel(const Sprite* sprite,
const double x,
const double y,
const frame_t frame,
const Projection& proj,
const bool newBlend)
{
color_t color = 0;
if ((x >= 0.0) && (x < sprite->width()) && (y >= 0.0) && (y < sprite->height())) {
std::unique_ptr<Image> image(Image::create(sprite->pixelFormat(), 1, 1));
render::Render render;
render.setNewBlend(newBlend);
render.setRefLayersVisiblity(true);
render.setProjection(proj);
render.renderSprite(image.get(),
sprite,
frame,
gfx::ClipF(0, 0, proj.applyX(x), proj.applyY(y), 1, 1));
color = get_pixel(image.get(), 0, 0);
}
return color;
}
} // namespace render