summaryrefslogtreecommitdiff
path: root/scene/resources/texture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/texture.cpp')
-rw-r--r--scene/resources/texture.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index a378c517ed..d719aa6126 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -1087,8 +1087,12 @@ bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const {
if (!atlas.is_valid())
return true;
- int x = p_x + region.position.x + margin.position.x;
- int y = p_y + region.position.y + margin.position.y;
+ int x = p_x + region.position.x - margin.position.x;
+ int y = p_y + region.position.y - margin.position.y;
+
+ // margin edge may outside of atlas
+ if (x < 0 || x >= atlas->get_width()) return false;
+ if (y < 0 || y >= atlas->get_height()) return false;
return atlas->is_pixel_opaque(x, y);
}
@@ -1205,6 +1209,17 @@ Ref<Texture> LargeTexture::get_piece_texture(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, pieces.size(), Ref<Texture>());
return pieces[p_idx].texture;
}
+Ref<Image> LargeTexture::to_image() const {
+
+ Ref<Image> img = memnew(Image(this->get_width(), this->get_height(), false, Image::FORMAT_RGBA8));
+ for (int i = 0; i < pieces.size(); i++) {
+
+ Ref<Image> src_img = pieces[i].texture->get_data();
+ img->blit_rect(src_img, Rect2(0, 0, src_img->get_width(), src_img->get_height()), pieces[i].offset);
+ }
+
+ return img;
+}
void LargeTexture::_bind_methods() {