summaryrefslogtreecommitdiff
path: root/core/image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/image.cpp')
-rw-r--r--core/image.cpp100
1 files changed, 99 insertions, 1 deletions
diff --git a/core/image.cpp b/core/image.cpp
index 52946bbb85..57496683ef 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -30,7 +30,7 @@
#include "hash_map.h"
#include "core/io/image_loader.h"
#include "core/os/copymem.h"
-
+#include "hq2x.h"
#include "print_string.h"
#include <stdio.h>
@@ -901,6 +901,104 @@ static void _generate_po2_mipmap(const uint8_t* p_src, uint8_t* p_dst, uint32_t
}
+void Image::expand_x2_hq2x() {
+
+ ERR_FAIL_COND(format>=FORMAT_INDEXED);
+
+ Format current = format;
+ bool mipmaps=get_mipmaps();
+ if (mipmaps) {
+ clear_mipmaps();
+ }
+
+ if (current!=FORMAT_RGBA)
+ convert(FORMAT_RGBA);
+
+ DVector<uint8_t> dest;
+ dest.resize(width*2*height*2*4);
+
+ {
+ DVector<uint8_t>::Read r = data.read();
+ DVector<uint8_t>::Write w = dest.write();
+
+ hq2x_resize((const uint32_t*)r.ptr(),width,height,(uint32_t*)w.ptr());
+
+ }
+
+ width*=2;
+ height*=2;
+ data=dest;
+
+
+ if (current!=FORMAT_RGBA)
+ convert(current);
+
+ if (mipmaps) {
+ generate_mipmaps();
+ }
+
+}
+
+void Image::shrink_x2() {
+
+ ERR_FAIL_COND(format==FORMAT_INDEXED || format==FORMAT_INDEXED_ALPHA);
+ ERR_FAIL_COND( data.size()==0 );
+
+
+
+ if (mipmaps) {
+
+ //just use the lower mipmap as base and copy all
+ DVector<uint8_t> new_img;
+
+ int ofs = get_mipmap_offset(1);
+
+ int new_size = data.size()-ofs;
+ new_img.resize(new_size);
+
+
+ {
+ DVector<uint8_t>::Write w=new_img.write();
+ DVector<uint8_t>::Read r=data.read();
+
+ copymem(w.ptr(),&r[ofs],new_size);
+ }
+
+ mipmaps--;
+ width/=2;
+ height/=2;
+ data=new_img;
+
+ } else {
+
+ DVector<uint8_t> new_img;
+
+ ERR_FAIL_COND( format>=FORMAT_INDEXED );
+ int ps = get_format_pixel_size(format);
+ new_img.resize((width/2)*(height/2)*ps);
+
+ {
+ DVector<uint8_t>::Write w=new_img.write();
+ DVector<uint8_t>::Read r=data.read();
+
+ switch(format) {
+
+ case FORMAT_GRAYSCALE:
+ case FORMAT_INTENSITY: _generate_po2_mipmap<1>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_GRAYSCALE_ALPHA: _generate_po2_mipmap<2>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_RGB: _generate_po2_mipmap<3>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_RGBA: _generate_po2_mipmap<4>(r.ptr(), w.ptr(), width,height); break;
+ default: {}
+ }
+ }
+
+ width/=2;
+ height/=2;
+ data=new_img;
+
+ }
+}
+
Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
if (!_can_modify(format)) {