Class: GD2::Image::IndexedColor
- Inherits:
-
GD2::Image
- Object
- GD2::Image
- GD2::Image::IndexedColor
- Defined in:
- lib/gd2/image.rb
Overview
Description
IndexedColor images select pixel colors indirectly through a palette of up to 256 colors. Use Image#palette to access the associated Palette object.
Instance Attribute Summary
Attributes inherited from GD2::Image
Class Method Summary collapse
-
.create_image_sym ⇒ Object
:nodoc:.
-
.palette_class ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#alpha_blending=(bool) ⇒ Object
:nodoc:.
-
#alpha_blending? ⇒ Boolean
:nodoc:.
-
#color2pixel(color) ⇒ Object
:nodoc:.
-
#merge_from(other, dst_x, dst_y, src_x, src_y, w, h, pct, gray = false) ⇒ Object
Like Image#merge_from except an optional final argument can be specified to preserve the hue of the source by converting the destination pixels to grey scale before the merge.
-
#optimize_palette ⇒ Object
:nodoc:.
-
#pixel2color(pixel) ⇒ Object
:nodoc:.
-
#to_indexed_color(colors = MAX_COLORS, dither = true) ⇒ Object
:nodoc:.
-
#to_true_color ⇒ Object
:nodoc:.
Methods inherited from GD2::Image
#==, #[], #[]=, #aspect, #clipping, #clips?, #compare, #copy_from, #copy_from_rotated, create_image_ptr, #crop, #crop!, #draw, #dup, #each, #export, extract_format, #gd, #gd2, #get_pixel, #gif, #height, import, #init_with_image, #init_with_size, #inspect, #interlaced=, #interlaced?, #jpeg, load, new, #png, #polar_transform, #polar_transform!, #resize, #resize!, #rotate, #rotate!, #save_alpha=, #save_alpha?, #set_pixel, #sharpen, #size, #transparent, #transparent=, #true_color?, #uncrop, #uncrop!, #wbmp, #width, #with_clipping
Class Method Details
.create_image_sym ⇒ Object
:nodoc:
724 725 726 |
# File 'lib/gd2/image.rb', line 724 def self.create_image_sym #:nodoc: :gdImageCreate end |
.palette_class ⇒ Object
:nodoc:
728 729 730 |
# File 'lib/gd2/image.rb', line 728 def self.palette_class #:nodoc: Palette::IndexedColor end |
Instance Method Details
#alpha_blending=(bool) ⇒ Object
:nodoc:
744 745 746 |
# File 'lib/gd2/image.rb', line 744 def alpha_blending=(bool) #:nodoc: raise 'Alpha blending mode not available for indexed color images' if bool end |
#alpha_blending? ⇒ Boolean
:nodoc:
740 741 742 |
# File 'lib/gd2/image.rb', line 740 def alpha_blending? #:nodoc: false end |
#color2pixel(color) ⇒ Object
:nodoc:
736 737 738 |
# File 'lib/gd2/image.rb', line 736 def color2pixel(color) #:nodoc: color.from_palette?(palette) ? color.index : palette.exact!(color).index end |
#merge_from(other, dst_x, dst_y, src_x, src_y, w, h, pct, gray = false) ⇒ Object
Like Image#merge_from except an optional final argument can be specified to preserve the hue of the source by converting the destination pixels to grey scale before the merge.
781 782 783 784 785 786 |
# File 'lib/gd2/image.rb', line 781 def merge_from(other, dst_x, dst_y, src_x, src_y, w, h, pct, gray = false) return super(other, dst_x, dst_y, src_x, src_y, w, h, pct) unless gray ::GD2::GD2FFI.send(:gdImageCopyMergeGray, image_ptr, other.image_ptr, dst_x.to_i, dst_y.to_i, src_x.to_i, src_y.to_i, w.to_i, h.to_i, pct.to_percent.round.to_i) self end |
#optimize_palette ⇒ Object
:nodoc:
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
# File 'lib/gd2/image.rb', line 748 def optimize_palette #:nodoc: # first map duplicate colors to a single palette index map, cache = palette.inject([{}, Array.new(MAX_COLORS)]) do |ary, color| ary.at(0)[color.rgba] = color.index ary.at(1)[color.index] = color.rgba ary end each_with_index do |row, y| row.each_with_index do |pixel, x| set_pixel(x, y, map[cache.at(pixel)]) end end # now clean up the palette palette.deallocate_unused end |
#pixel2color(pixel) ⇒ Object
:nodoc:
732 733 734 |
# File 'lib/gd2/image.rb', line 732 def pixel2color(pixel) #:nodoc: palette[pixel] end |
#to_indexed_color(colors = MAX_COLORS, dither = true) ⇒ Object
:nodoc:
774 775 776 |
# File 'lib/gd2/image.rb', line 774 def to_indexed_color(colors = MAX_COLORS, dither = true) #:nodoc: palette.used <= colors ? self : super end |