sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6a introduces important bugfixes for Fredo's Extensions Update

    Using chunkyPng library with Sketchup

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 3 Posters 741 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L Offline
      LFloissac
      last edited by

      I need to write a PNG image processed into a Sketchup plugin.
      Note: this image is not a screen copy of Sketchup scene but a process result. So, the SU usual PNG save image method is not suitable for that.

      This is ChunkyPNG library job !
      see http://rubydoc.info/gems/chunky_png/frames

      1. When I launch a simple test program directly from ruby 1.8.6, Its working well.
      2. The same code, with the same path lauched from SU (ruby console) crashs (see above).
      3. I've find a "dirty" solution by creating new Set and SortedSet classes (here attached).
      4. Does someone have a better solution ?

      The problem seems to come from the "set" ruby command who could be overided in the SU ruby engine.

      1. The code of a simple test case:
        $LOAD_PATH.unshift(File.dirname(FILE))
        $LOAD_PATH.unshift File.join(File.dirname(FILE), 'lib')
        $LOAD_PATH.unshift File.join(File.dirname(FILE), 'lib', 'chunky_png')

      require 'chunky_png'

      Creating an image from scratch, save as an interlaced PNG

      png = ChunkyPNG::Image.new(201, 201, ChunkyPNG::Color::TRANSPARENT)
      for y in 0..200
      for x in 1..200
      png[x,y] = ChunkyPNG::Color.rgba(x, y, 0, 255)
      end
      end
      png.save('c:/TMP/testChunky_pngFile.png', :interlace => true)
      puts "Image saved"

      2a. The first error message is :
      load "C:/TMP/PNG_TEST/pngTest.rb"
      $LOAD_PATH: C:/TMP/PNG_TEST/lib/chunky_pngC:/TMP/PNG_TEST/libC:/TMP/PNG_TESTC:/Program Files (x86)/Google/Google SketchUp 8/Plugins/ProgressBar/squall/classC:/Program Files (x86)/Google/Google SketchUp 8/PluginsC:/Program Files (x86)/Google/Google SketchUp 8/PluginsC:/Program Files (x86)/Google/Google SketchUp 8/Tools
      Error: #<LoadError: C:/TMP/PNG_TEST/lib/chunky_png/chunky_png.rb:2:in require': no such file to load -- set> C:/TMP/PNG_TEST/pngTest.rb:7 C:/TMP/PNG_TEST/lib/chunky_png/chunky_png.rb:2 C:/TMP/PNG_TEST/pngTest.rb:7:in require'
      C:/TMP/PNG_TEST/pngTest.rb:7
      (eval):55:in `load'
      (eval):55

      2a. If I add the "standard ruby" set.rb class into the path a second eror message appears
      load "C:/TMP/PNG_TEST/pngTest.rb"
      $LOAD_PATH: C:/TMP/PNG_TEST/lib/chunky_pngC:/TMP/PNG_TEST/libC:/TMP/PNG_TESTC:/TMP/PNG_TEST/lib/chunky_pngC:/TMP/PNG_TEST/libC:/TMP/PNG_TESTC:/Program Files (x86)/Google/Google SketchUp 8/Plugins/ProgressBar/squall/classC:/Program Files (x86)/Google/Google SketchUp 8/PluginsC:/Program Files (x86)/Google/Google SketchUp 8/PluginsC:/Program Files (x86)/Google/Google SketchUp 8/Tools
      Error: #<NoMethodError: undefined method best_color_settings' for #<Set: {4278190335, 0, 16711935, 64255}>> C:/TMP/PNG_TEST/lib/chunky_png/canvas/png_encoding.rb:125 C:/TMP/PNG_TEST/lib/chunky_png/canvas/png_encoding.rb:75:in to_datastream'
      C:/TMP/PNG_TEST/lib/chunky_png/image.rb:62:in to_datastream' C:/TMP/PNG_TEST/lib/chunky_png/canvas/png_encoding.rb:35:in write'
      C:/TMP/PNG_TEST/lib/chunky_png/canvas/png_encoding.rb:43:in save' C:/TMP/PNG_TEST/lib/chunky_png/canvas/png_encoding.rb:43:in open'
      C:/TMP/PNG_TEST/lib/chunky_png/canvas/png_encoding.rb:43:in save' C:/TMP/PNG_TEST/pngTest.rb:30 (eval):7:in load'
      (eval):7

      1. The following "dirty patch" (here attached) works well:
        a. Duplicate "set.rb" file from "standard ruby 1.8.6". Rename it "set_bis.rb"
        b. In this new file "set_bis", rename classes "Set" and "SortedSet" into "Set_bis" and "SortedSet_bis"
        c. Change require 'Set' to require 'Set_bis' into chunky_png.rb
        d. Rename "Set" and "SortedSet" calls into "Palette.rb". These calls became "Set_bis" and "SortedSet_bis"

      Note: The following ressources also need to be in the load path.

      • enumerator.so
      • stringio.so
      • zlib.so
      • bibliothèque zlib

      chunkyPng_bis.zip

      1 Reply Last reply Reply Quote 0
      • renderizaR Offline
        renderiza
        last edited by

        Can a Moderator place this on the Developers forum so it has better chance to get a reply?

        [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

        1 Reply Last reply Reply Quote 0
        • massimoM Offline
          massimo Moderator
          last edited by

          Done.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement