Using chunkyPng library with Sketchup
-
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- When I launch a simple test program directly from ruby 1.8.6, Its working well.
- The same code, with the same path lauched from SU (ruby console) crashs (see above).
- I've find a "dirty" solution by creating new Set and SortedSet classes (here attached).
- 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.
- 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:inrequire': 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):552a. 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 methodbest_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:into_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:insave' 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:insave' C:/TMP/PNG_TEST/pngTest.rb:30 (eval):7:in
load'
(eval):7- 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
-
Can a Moderator place this on the Developers forum so it has better chance to get a reply?
-
Done.
Advertisement