Class: PSD::Image
- Inherits:
-
Object
- Object
- PSD::Image
- Extended by:
- Forwardable
- Includes:
- Export::PNG, PSD::ImageFormat::RAW, PSD::ImageFormat::RLE, PSD::ImageMode::CMYK, PSD::ImageMode::Greyscale, PSD::ImageMode::RGB
- Defined in:
- lib/psd/image.rb,
lib/psd/image_exports/png.rb
Overview
Parses the full preview image at the end of the PSD document.
Direct Known Subclasses
Defined Under Namespace
Modules: Export
Constant Summary collapse
- COMPRESSIONS =
All of the possible compression formats Photoshop uses.
[ 'Raw', 'RLE', 'ZIP', 'ZIPPrediction' ].freeze
Instance Attribute Summary collapse
-
#has_mask ⇒ Object
(also: #has_mask?)
readonly
Returns the value of attribute has_mask.
-
#opacity ⇒ Object
readonly
Returns the value of attribute opacity.
-
#pixel_data ⇒ Object
readonly
Returns the value of attribute pixel_data.
Instance Method Summary collapse
-
#initialize(file, header) ⇒ Image
constructor
Store a reference to the file and the header.
-
#parse ⇒ Object
Begins parsing the image by first figuring out the compression format used, and then by reading the image data.
Methods included from Export::PNG
Constructor Details
#initialize(file, header) ⇒ Image
Store a reference to the file and the header. We also do a few simple calculations to figure out the number of pixels in the image and the length of each channel.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/psd/image.rb', line 35 def initialize(file, header) @file = file @header = header @num_pixels = width * height @num_pixels *= 2 if depth == 16 calculate_length set_channels_info @channel_data = [] @pixel_data = [] @opacity = 1.0 @has_mask = false @start_pos = @file.tell @end_pos = @start_pos + @length PSD.logger.debug "Image: #{width}x#{height}, length = #{@length}, mode = #{@header.mode_name}, position = #{@start_pos}" end |
Instance Attribute Details
#has_mask ⇒ Object (readonly) Also known as: has_mask?
Returns the value of attribute has_mask.
19 20 21 |
# File 'lib/psd/image.rb', line 19 def has_mask @has_mask end |
#opacity ⇒ Object (readonly)
Returns the value of attribute opacity.
19 20 21 |
# File 'lib/psd/image.rb', line 19 def opacity @opacity end |
#pixel_data ⇒ Object (readonly)
Returns the value of attribute pixel_data.
19 20 21 |
# File 'lib/psd/image.rb', line 19 def pixel_data @pixel_data end |
Instance Method Details
#parse ⇒ Object
Begins parsing the image by first figuring out the compression format used, and then by reading the image data.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/psd/image.rb', line 58 def parse @compression = parse_compression! # ZIP not implemented if [2, 3].include?(@compression) PSD.logger.debug "Warning: ZIP image compression not supported yet. Skipping." @file.seek @end_pos and return end PSD.logger.debug "Compression: id = #{@compression}, name = #{COMPRESSIONS[@compression]}" parse_image_data! return self end |