Module: SkippyLib::ImageRepHelper
Overview
Class Method Summary collapse
-
.color_to_24bit(color) ⇒ Array(Integer, Integer, Integer)
RGBA/BGRA.
-
.color_to_32bit(color) ⇒ Array(Integer, Integer, Integer, Integer)
From C API documentation on SUColorOrder.
-
.colors_to_24bit_bytes(colors) ⇒ String
Binary byte string of raw image data.
-
.colors_to_32bit_bytes(colors) ⇒ String
Binary byte string of raw image data.
- .colors_to_image_rep(width, height, colors) ⇒ Sketchup::ImageRep
Class Method Details
.color_to_24bit(color) ⇒ Array(Integer, Integer, Integer)
Returns RGBA/BGRA.
52 53 54 |
# File 'modules/image_rep.rb', line 52 def self.color_to_24bit(color) self.color_to_32bit(color)[0, 3] end |
.color_to_32bit(color) ⇒ Array(Integer, Integer, Integer, Integer)
From C API documentation on SUColorOrder
SketchUpAPI expects the channels to be in different orders on Windows vs. Mac OS. Bitmap data is exposed in BGRA and RGBA byte orders on Windows and Mac OS, respectively.
37 38 39 40 |
# File 'modules/image_rep.rb', line 37 def self.color_to_32bit(color) r, g, b, a = color.to_a Platform::IS_WIN ? [b, g, r, a] : [r, g, b, a] end |
.colors_to_24bit_bytes(colors) ⇒ String
Returns Binary byte string of raw image data.
59 60 61 |
# File 'modules/image_rep.rb', line 59 def self.colors_to_24bit_bytes(colors) colors.map { |color| self.color_to_24bit(color) }.flatten.pack('C*') end |
.colors_to_32bit_bytes(colors) ⇒ String
Returns Binary byte string of raw image data.
45 46 47 |
# File 'modules/image_rep.rb', line 45 def self.colors_to_32bit_bytes(colors) colors.map { |color| self.color_to_32bit(color) }.flatten.pack('C*') end |
.colors_to_image_rep(width, height, colors) ⇒ Sketchup::ImageRep
17 18 19 20 21 22 23 24 25 26 |
# File 'modules/image_rep.rb', line 17 def self.colors_to_image_rep(width, height, colors) row_padding = 0 bits_per_pixel = 32 pixel_data = self.colors_to_32bit_bytes(colors) # rubocop:disable SketchupSuggestions/Compatibility image_rep = Sketchup::ImageRep.new # rubocop:enable SketchupSuggestions/Compatibility image_rep.set_data(width, height, bits_per_pixel, row_padding, pixel_data) image_rep end |