ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::ImageRep

Inherits:
Object
  • Object
show all

Overview

Pixel buffer. From file #load_file or #new(path), or #set_data with RGB(A) bytes. PNG/JPEG encoding/decoding uses the host (Qt + QImage +). Without a host, #new(path) throws an error.

Examples:

ModraUp::ImageRep.new.width  #=> 0

Class Method Summary # collapse

Instance Method Summary # collapse

Class Method Details

ImageRep.new ⇒ image_repImageRep.new(filepath) ⇒ image_rep

Initialize with an empty buffer or decode a PNG/JPEG from a path.

Parameters:

  • filepath (String)

Returns:

  • (ModraUp::ImageRep)

Raises:

  • [ArgumentError] The path is invalid or the file cannot be decoded.

Examples:

ModraUp::ImageRep.new

Instance Method Details

image_rep.load_file(filepath) ⇒ true

Fill pixels from PNG/JPEG.

Parameters:

  • filepath (String)

Returns:

  • (true)

Raises:

  • [ArgumentError] The path is invalid or the file cannot be decoded.

Examples:

ModraUp::ImageRep.new.load_file("missing.png") rescue true

image_rep.save_file(filepath) ⇒ trueimage_rep.save_file(filepath, quality) ⇒ trueimage_rep.save_file(filepath, extra) ⇒ true

Write as PNG or JPEG. The extension determines the format; JPEG accepts quality (0–100) or a hash :quality.

Parameters:

  • filepath (String)
  • quality (Integer, Hash)

Returns:

  • (true)

Raises:

  • [ArgumentError] No pixels or write failed

Examples:

ModraUp::ImageRep.new.save_file("/tmp/x.png") rescue true

image_rep.width ⇒ Integer

Pixel width. An empty buffer is 0.

Returns:

  • (Integer)

Examples:

ModraUp::ImageRep.new.width  #=> 0

image_rep.height ⇒ Integer

Pixel height. Empty buffer is 0.

Returns:

  • (Integer)

Examples:

ModraUp::ImageRep.new.height  #=> 0

image_rep.bits_per_pixel ⇒ Integer

Bits per pixel: 8 / 24 / 32. Empty buffer: 0.

Returns:

  • (Integer)

Examples:

ModraUp::ImageRep.new.bits_per_pixel  #=> 0

image_rep.row_padding ⇒ Integer

Number of bytes to fill at the end of each row.

Returns:

  • (Integer)

Examples:

ModraUp::ImageRep.new.row_padding  #=> 0

image_rep.size ⇒ Integer

The number of bytes in #data.

Returns:

  • (Integer)

Examples:

ModraUp::ImageRep.new.size  #=> 0

image_rep.data ⇒ String, nil

Pixel bytes (ASCII-8BIT). An empty buffer is nil. Byte order is RGB(A).

Returns:

  • (String, nil)

Examples:

ModraUp::ImageRep.new.data  #=> nil

image_rep.set_data(width, height, bits_per_pixel, row_padding, pixel_data) ⇒ image_rep

Replace the buffer with original pixels. bits_per_pixel is 8 / 24 / 32.

Parameters:

  • width (Integer)
  • height (Integer)
  • bits_per_pixel (Integer)
  • row_padding (Integer)
  • pixel_data (String)

Returns:

  • (ModraUp::ImageRep)

Raises:

  • [ArgumentError] Invalid size or byte count

Examples:

pix = [255, 0, 0, 255].pack("C*")
ModraUp::ImageRep.new.set_data(1, 1, 32, 0, pix).width  #=> 1

image_rep.color_at_uv(u, v) ⇒ ModraUp::Color, nilimage_rep.color_at_uv(u, v, bilinear) ⇒ ModraUp::Color, nil

Samples the color at UV coordinates.(0,0) is the bottom-left, and (1,1) is the top-right. A nil buffer returns nil.

Parameters:

  • u (Float)
  • v (Float)
  • bilinear (Boolean)

Returns:

  • (ModraUp::Color, nil)

Examples:

pix = [255, 0, 0, 255].pack("C*")
ModraUp::ImageRep.new.set_data(1, 1, 32, 0, pix).color_at_uv(0.5, 0.5).red  #=> 255

image_rep.colors ⇒ Array<ModraUp::Color>, nil

Each pixel a ModraUp::Color, row-major order (top to bottom). An empty buffer is nil.

Returns:

  • (Array<ModraUp::Color>, nil)

Examples:

ModraUp::ImageRep.new.colors  #=> nil