From e8fbf39f886b2b5dbf5e14f07cd1dbefe8d48bf4 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 3 Jan 2016 17:14:28 -0300 Subject: -Replaced tinyjpg for jpgd (public domain), fixes progressive encoded jpgs and speeds up. Closes #2040 -Removed support of loading BitMap as image, now it must be load as a pnm, also closes #2040 --- tools/editor/plugins/editor_preview_plugins.cpp | 76 +++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'tools/editor/plugins/editor_preview_plugins.cpp') diff --git a/tools/editor/plugins/editor_preview_plugins.cpp b/tools/editor/plugins/editor_preview_plugins.cpp index 5f52d4c3e..a0ce29421 100644 --- a/tools/editor/plugins/editor_preview_plugins.cpp +++ b/tools/editor/plugins/editor_preview_plugins.cpp @@ -6,6 +6,7 @@ #include "scene/resources/material.h" #include "scene/resources/sample.h" #include "scene/resources/mesh.h" +#include "scene/resources/bit_mask.h" bool EditorTexturePreviewPlugin::handles(const String& p_type) const { @@ -56,6 +57,81 @@ Ref EditorTexturePreviewPlugin::generate(const RES& p_from) { EditorTexturePreviewPlugin::EditorTexturePreviewPlugin() { +} + +//////////////////////////////////////////////////////////////////////////// + +bool EditorBitmapPreviewPlugin::handles(const String& p_type) const { + + return ObjectTypeDB::is_type(p_type,"BitMap"); +} + +Ref EditorBitmapPreviewPlugin::generate(const RES& p_from) { + + Ref bm =p_from; + + if (bm->get_size()==Size2()) { + return Ref(); + } + + DVector data; + + data.resize(bm->get_size().width*bm->get_size().height); + + { + DVector::Write w=data.write(); + + for(int i=0;iget_size().width;i++) { + for(int j=0;jget_size().height;j++) { + if (bm->get_bit(Point2i(i,j))) { + w[j*bm->get_size().width+i]=255; + } else { + w[j*bm->get_size().width+i]=0; + + } + } + + } + } + + + Image img(bm->get_size().width,bm->get_size().height,0,Image::FORMAT_GRAYSCALE,data); + + int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size"); + if (img.is_compressed()) { + if (img.decompress()!=OK) + return Ref(); + } else if (img.get_format()!=Image::FORMAT_RGB && img.get_format()!=Image::FORMAT_RGBA) { + img.convert(Image::FORMAT_RGBA); + } + + int width,height; + if (img.get_width() > thumbnail_size && img.get_width() >= img.get_height()) { + + width=thumbnail_size; + height = img.get_height() * thumbnail_size / img.get_width(); + } else if (img.get_height() > thumbnail_size && img.get_height() >= img.get_width()) { + + height=thumbnail_size; + width = img.get_width() * thumbnail_size / img.get_height(); + } else { + + width=img.get_width(); + height=img.get_height(); + } + + img.resize(width,height); + + Ref ptex = Ref( memnew( ImageTexture )); + + ptex->create_from_image(img,0); + return ptex; + +} + +EditorBitmapPreviewPlugin::EditorBitmapPreviewPlugin() { + + } /////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3-70-g09d2