Module: FreeImage::Information
- Included in:
- Bitmap
- Defined in:
- lib/free-image/modules/information.rb
Overview
Once a bitmap is loaded into memory, you can use the following methods to retrieve information about is type, dimensions, colors, etc.
Instance Method Summary collapse
-
#background_color ⇒ Object
Returns the background color of a bitmap.
-
#background_color=(value) ⇒ Object
Set the background color of a bitmap.
-
#bits_per_pixel ⇒ Object
(also: #bpp)
Returns the size of one pixel in the bitmap in bits.
-
#blue_mask ⇒ Object
Returns a bit pattern describing the blue color component of a pixel in a bitmap.
- #color_type ⇒ Object
-
#dib_size ⇒ Object
Returns the size of the DIB-element of a bitmap in memory, which is the header size + palette size + data bits.
-
#dots_per_meter_x ⇒ Object
Returns the horizontal resolution, in pixels-per-meter, of the target device for the bitmap.
-
#dots_per_meter_x=(value) ⇒ Object
Sets the horizontal resolution, in pixels-per-meter, of the target device for the bitmap.
-
#dots_per_meter_y ⇒ Object
Returns the vertical resolution, in pixels-per-meter, of the target device for the bitmap.
-
#dots_per_meter_y=(value) ⇒ Object
Sets the vertical resolution, in pixels-per-meter, of the target device for the bitmap.
-
#green_mask ⇒ Object
Returns a bit pattern describing the green color component of a pixel in a bitmap.
-
#has_background_color ⇒ Object
Returns true when the image has a file background color, false otherwise.
-
#has_pixels ⇒ Object
Returns true if the bitmap contains pixel data, otherwise false.
- #has_rgb_masks ⇒ Object
-
#height ⇒ Object
Returns the height of the bitmap in pixel units.
-
#image_type ⇒ Object
Returns the image type of a bitmap.
- #info_header ⇒ Object
-
#line ⇒ Object
Returns the width of the bitmap in bytes.
-
#palette ⇒ Object
Returns a bitmap’s palette.
-
#pitch ⇒ Object
Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary, also known as pitch or stride or scan width.
-
#red_mask ⇒ Object
Returns a bit pattern describing the red color component of a pixel in a bitmap.
-
#transparency_count ⇒ Object
Returns the number of transparent colors in a palletized bitmap, otherwise returns 0.
-
#transparent ⇒ Object
Returns true if the transparency table is enabled (1-, 4- or 8-bit images) or when the input dib contains alpha values (32-bit images, RGBA16 or RGBAF images).
-
#transparent=(value) ⇒ Object
Tells FreeImage if it should make use of the transparency table or the alpha channel that may accompany a bitmap.
-
#transparent_index ⇒ Object
Returns the palette entry used as transparent color for the image specified.
-
#transparent_index=(value) ⇒ Object
Sets the index of the palette entry to be used as transparent color for the image specified.
-
#width ⇒ Object
Returns the width of the bitmap in pixel units.
Instance Method Details
#background_color ⇒ Object
Returns the background color of a bitmap. For 8-bit images, the color index in the palette is returned in the rgbReserved member of the bkcolor parameter.
89 90 91 92 93 94 |
# File 'lib/free-image/modules/information.rb', line 89 def background_color ptr = FFI::MemoryPointer.new(:pointer) FreeImage.FreeImage_GetBackgroundColor(self, ptr) FreeImage.check_last_error RGBQuad.new(ptr) end |
#background_color=(value) ⇒ Object
Set the background color of a bitmap. The color should be an instance of RGBQuad.
When saving an image to PNG, this background color is transparently saved to the PNG file. When the bkcolor parameter is nil, the background color is removed from the image.
102 103 104 105 106 107 108 |
# File 'lib/free-image/modules/information.rb', line 102 def background_color=(value) result = FreeImage.FreeImage_GetBackgroundColor(self, value) FreeImage.check_last_error if !result raise(RuntimeError, "Could not save background color") end end |
#bits_per_pixel ⇒ Object Also known as: bpp
Returns the size of one pixel in the bitmap in bits. For example if each pixel takes 32-bits of space in the bitmap, this function returns 32. Possible bit depths are 1, 4, 8, 16, 24, 32 for standard bitmaps and 16-, 32-, 48-, 64-, 96- and 128-bit for non standard bitmaps
114 115 116 117 118 |
# File 'lib/free-image/modules/information.rb', line 114 def bits_per_pixel result = FreeImage.FreeImage_GetBPP(self) FreeImage.check_last_error result end |
#blue_mask ⇒ Object
Returns a bit pattern describing the blue color component of a pixel in a bitmap.
122 123 124 125 126 |
# File 'lib/free-image/modules/information.rb', line 122 def blue_mask result = FreeImage.FreeImage_GetBlueMask(self) FreeImage.check_last_error result end |
#color_type ⇒ Object
128 129 130 131 132 |
# File 'lib/free-image/modules/information.rb', line 128 def color_type result = FreeImage.FreeImage_GetColorType(self) FreeImage.check_last_error result end |
#dib_size ⇒ Object
Returns the size of the DIB-element of a bitmap in memory, which is the header size + palette size + data bits. Note that this is not the real size of a bitmap, just the size of its DIB-element.
137 138 139 140 141 |
# File 'lib/free-image/modules/information.rb', line 137 def dib_size result = FreeImage.FreeImage_GetDIBSize(self) FreeImage.check_last_error result end |
#dots_per_meter_x ⇒ Object
Returns the horizontal resolution, in pixels-per-meter, of the target device for the bitmap.
145 146 147 148 149 |
# File 'lib/free-image/modules/information.rb', line 145 def dots_per_meter_x result = FreeImage.FreeImage_GetDotsPerMeterX(self) FreeImage.check_last_error result end |
#dots_per_meter_x=(value) ⇒ Object
Sets the horizontal resolution, in pixels-per-meter, of the target device for the bitmap.
153 154 155 156 157 |
# File 'lib/free-image/modules/information.rb', line 153 def dots_per_meter_x=(value) result = FreeImage.FreeImage_SetDotsPerMeterX(self, value) FreeImage.check_last_error result end |
#dots_per_meter_y ⇒ Object
Returns the vertical resolution, in pixels-per-meter, of the target device for the bitmap.
161 162 163 164 165 |
# File 'lib/free-image/modules/information.rb', line 161 def dots_per_meter_y result = FreeImage.FreeImage_GetDotsPerMeterY(self) FreeImage.check_last_error result end |
#dots_per_meter_y=(value) ⇒ Object
Sets the vertical resolution, in pixels-per-meter, of the target device for the bitmap.
169 170 171 172 173 |
# File 'lib/free-image/modules/information.rb', line 169 def dots_per_meter_y=(value) result = FreeImage.FreeImage_SetDotsPerMeterY(self, value) FreeImage.check_last_error result end |
#green_mask ⇒ Object
Returns a bit pattern describing the green color component of a pixel in a bitmap.
176 177 178 179 180 |
# File 'lib/free-image/modules/information.rb', line 176 def green_mask result = FreeImage.FreeImage_GetGreenMask(self) FreeImage.check_last_error result end |
#has_background_color ⇒ Object
Returns true when the image has a file background color, false otherwise
183 184 185 186 187 |
# File 'lib/free-image/modules/information.rb', line 183 def has_background_color result = FreeImage.FreeImage_HasBackgroundColor(self) FreeImage.check_last_error result end |
#has_pixels ⇒ Object
Returns true if the bitmap contains pixel data, otherwise false. Bitmaps can be loaded using the FIF_LOAD_NOPIXELS load flag whic tells the decoder to read header data and available metadata and skip pixel data decoding. This reduces memory usage and load speed.
193 194 195 196 197 |
# File 'lib/free-image/modules/information.rb', line 193 def has_pixels result = FreeImage.FreeImage_HasPixels(self) FreeImage.check_last_error result end |
#has_rgb_masks ⇒ Object
199 200 201 202 203 |
# File 'lib/free-image/modules/information.rb', line 199 def has_rgb_masks result = FreeImage.FreeImage_HasRGBMasks(self) FreeImage.check_last_error result end |
#height ⇒ Object
Returns the height of the bitmap in pixel units
206 207 208 209 210 |
# File 'lib/free-image/modules/information.rb', line 206 def height result = FreeImage.FreeImage_GetHeight(self) FreeImage.check_last_error result end |
#image_type ⇒ Object
Returns the image type of a bitmap.
213 214 215 216 217 |
# File 'lib/free-image/modules/information.rb', line 213 def image_type result = FreeImage.FreeImage_GetImageType(self) FreeImage.check_last_error result end |
#info_header ⇒ Object
219 220 221 222 223 |
# File 'lib/free-image/modules/information.rb', line 219 def info_header result = FreeImage::InfoHeader.new(FreeImage.FreeImage_GetInfoHeader(self)) FreeImage.check_last_error result end |
#line ⇒ Object
Returns the width of the bitmap in bytes. See also FreeImage::Information.pitch. There has been some criticism on the name of this function. Some people expect it to return a scanline in the pixel data, while it actually returns the width of the bitmap in bytes. As far as I know the term Line is common terminology for the width of a bitmap in bytes. It is at least used by Microsoft DirectX.
230 231 232 233 234 |
# File 'lib/free-image/modules/information.rb', line 230 def line result = FreeImage.FreeImage_GetLine(self) FreeImage.check_last_error result end |
#palette ⇒ Object
Returns a bitmap’s palette. If the bitmap doesn’t have a palette (i.e. when the pixel bit depth is greater than 8), this return nil.
238 239 240 |
# File 'lib/free-image/modules/information.rb', line 238 def palette @palette ||= Palette.new(self) end |
#pitch ⇒ Object
Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary, also known as pitch or stride or scan width. In FreeImage each scanline starts at a 32-bit boundary for performance reasons. This accessor is essential when using low level pixel manipulation functions.
247 248 249 250 251 |
# File 'lib/free-image/modules/information.rb', line 247 def pitch result = FreeImage.FreeImage_GetPitch(self) FreeImage.check_last_error result end |
#red_mask ⇒ Object
Returns a bit pattern describing the red color component of a pixel in a bitmap.
254 255 256 257 258 |
# File 'lib/free-image/modules/information.rb', line 254 def red_mask result = FreeImage.FreeImage_GetRedMask(self) FreeImage.check_last_error result end |
#transparency_count ⇒ Object
Returns the number of transparent colors in a palletized bitmap, otherwise returns 0.
262 263 264 265 266 |
# File 'lib/free-image/modules/information.rb', line 262 def transparency_count result = FreeImage.FreeImage_GetTransparencyCount(self) FreeImage.check_last_error result end |
#transparent ⇒ Object
Returns true if the transparency table is enabled (1-, 4- or 8-bit images) or when the input dib contains alpha values (32-bit images, RGBA16 or RGBAF images). Returns false otherwise.
271 272 273 274 275 |
# File 'lib/free-image/modules/information.rb', line 271 def transparent result = FreeImage.FreeImage_IsTransparent(self) FreeImage.check_last_error result end |
#transparent=(value) ⇒ Object
Tells FreeImage if it should make use of the transparency table or the alpha channel that may accompany a bitmap. When calling this function with a bitmap whose bitdepth is different from 1-, 4-, 8- or 32-bit, transparency is disabled whatever the value of the Boolean parameter.
281 282 283 284 285 |
# File 'lib/free-image/modules/information.rb', line 281 def transparent=(value) result = FreeImage.FreeImage_SetTransparent(self, value) FreeImage.check_last_error result end |
#transparent_index ⇒ Object
Returns the palette entry used as transparent color for the image specified. Works for palletised images only and returns -1 for high color images or if the image has no color set to be transparent. Although it is possible for palletised images to have more than one transparent color, this function always returns the index of the first palette entry, set to be transparent.
293 294 295 296 297 |
# File 'lib/free-image/modules/information.rb', line 293 def transparent_index result = FreeImage.FreeImage_GetTransparentIndex(self) FreeImage.check_last_error result end |
#transparent_index=(value) ⇒ Object
Sets the index of the palette entry to be used as transparent color for the image specified. This works on palletised images only and does nothing for high color images.
Although it is possible for palletised images to have more than one transparent color, this method sets the palette entry specified as the single transparent color for the image. All other colors will be set to be non-transparent by this method.
As with FreeImage::Bitmap.transparency_table=, this method also sets the image’s transparency property to true for palletised images.
309 310 311 312 313 |
# File 'lib/free-image/modules/information.rb', line 309 def transparent_index=(value) result = FreeImage.FreeImage_SetTransparentIndex(self, value) FreeImage.check_last_error result end |
#width ⇒ Object
Returns the width of the bitmap in pixel units
320 321 322 323 324 |
# File 'lib/free-image/modules/information.rb', line 320 def width result = FreeImage.FreeImage_GetWidth(self) FreeImage.check_last_error result end |