[aseprite] 44/196: she/gtk: make use of aseprite thumbnail-generator

Tobias Hansen thansen at moszumanska.debian.org
Wed Apr 20 18:49:59 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit b64ba236d3cef5e1d45e79d9093855713af4e9dc
Author: Gabriel Rauter <rauter.gabriel at gmail.com>
Date:   Mon Mar 7 18:59:15 2016 +0100

    she/gtk: make use of aseprite thumbnail-generator
    
    use the aseprite thumbnail generator for file preview
---
 src/she/CMakeLists.txt         |  3 ++-
 src/she/gtk/native_dialogs.cpp | 38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/she/CMakeLists.txt b/src/she/CMakeLists.txt
index eddf386..8d9ade3 100644
--- a/src/she/CMakeLists.txt
+++ b/src/she/CMakeLists.txt
@@ -222,5 +222,6 @@ endif()
 
 if(WITH_GTK_FILE_DIALOG_SUPPORT)
   target_link_libraries(she
-    ${GTKMM_LIBRARIES})
+    ${GTKMM_LIBRARIES}
+    app-lib)
 endif()
diff --git a/src/she/gtk/native_dialogs.cpp b/src/she/gtk/native_dialogs.cpp
index 37ce7b1..41f5fa2 100644
--- a/src/she/gtk/native_dialogs.cpp
+++ b/src/she/gtk/native_dialogs.cpp
@@ -13,8 +13,12 @@
 
 #include "she/gtk/native_dialogs.h"
 
+#include "app/thumbnail_generator.h"
+#include "app/file_system.h"
 #include "base/string.h"
 #include "she/display.h"
+#include "she/surface.h"
+#include "she/locked_surface.h"
 #include "she/error.h"
 
 #include <gtkmm/application.h>
@@ -28,7 +32,6 @@
 #include <glibmm/fileutils.h>
 
 #include <string>
-#include <map>
 
 namespace she {
 
@@ -134,8 +137,25 @@ public:
     this->set_preview_widget_active(false);
     std::string fileName = this->get_filename();
     try {
-      if (!Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
-          auto previewPixbuf = Gdk::Pixbuf::create_from_file(fileName, 256, 256, true);
+      if (!fileName.empty() && !Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
+          app::IFileItem* fileItem = app::FileSystemModule::instance()->getFileItemFromPath(fileName);
+          app::ThumbnailGenerator* generator = app::ThumbnailGenerator::instance();
+          generator->addWorkerToGenerateThumbnail(fileItem);
+          while(generator->checkWorkers()){};
+          she::LockedSurface* thumbnailSurface = fileItem->getThumbnail()->lock();
+          she::SurfaceFormatData* formatData = new she::SurfaceFormatData();
+          thumbnailSurface->getFormat(formatData);
+          uint8_t* data = thumbnailSurface->getData(0, 0);
+          auto tempPixbuf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB,
+                                                true,
+                                                8,
+                                                thumbnailSurface->lockedWidth(),
+                                                thumbnailSurface->lockedHeight());
+          ConvertBetweenBGRAandRGBA(data, thumbnailSurface->lockedWidth(),
+                                    thumbnailSurface->lockedHeight(), tempPixbuf->get_pixels());
+          auto previewPixbuf = tempPixbuf->scale_simple(thumbnailSurface->lockedWidth() * 2,
+                                                        thumbnailSurface->lockedHeight() * 2,
+                                                        Gdk::INTERP_NEAREST);
           m_preview.set(previewPixbuf);
           this->set_preview_widget_active();
       }
@@ -177,6 +197,18 @@ private:
   Display* m_display;
   bool m_cancel;
   static std::string& lastUsedDir() { static std::string lastUsedDir; return lastUsedDir; }
+  void ConvertBetweenBGRAandRGBA(uint8_t* input, int pixel_width, int pixel_height, uint8_t* output) {
+    int offset = 0;
+    for (int y = 0; y < pixel_height; y++) {
+        for (int x = 0; x < pixel_width; x++) {
+            output[offset] = input[offset + 2];
+            output[offset + 1] = input[offset + 1];
+            output[offset + 2] = input[offset];
+            output[offset + 3] = input[offset + 3];
+            offset += 4;
+        }
+    }
+  }
 };
 
 NativeDialogsGTK3::NativeDialogsGTK3()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list