Module: Plushie::Command::Image

Defined in:
lib/plushie/command/image.rb

Overview

Image handle management commands.

Examples:

Command::Image.create_image("sprite", png_data)
Command.create_image("sprite", png_data)  # also works via delegation

Class Method Summary collapse

Class Method Details

.clear_imagesCmd

Remove all image handles.

Returns:



64
# File 'lib/plushie/command/image.rb', line 64

def clear_images = Cmd.new(type: :image_op, payload: {op: "clear"})

.create_image(handle, data) ⇒ Cmd

Create an image from encoded data (PNG/JPEG bytes).

Parameters:

  • handle (String)

    image handle name

  • data (String)

    encoded image bytes

Returns:



18
19
20
# File 'lib/plushie/command/image.rb', line 18

def create_image(handle, data)
  Cmd.new(type: :image_op, payload: {op: "create_image", handle:, data:})
end

.create_image_rgba(handle, width, height, pixels) ⇒ Cmd

Create an image from raw RGBA pixel data.

Parameters:

  • handle (String)

    image handle name

  • width (Integer)

    pixel width

  • height (Integer)

    pixel height

  • pixels (String)

    raw RGBA pixel data

Returns:



28
29
30
31
# File 'lib/plushie/command/image.rb', line 28

def create_image_rgba(handle, width, height, pixels)
  validate_pixel_buffer!(pixels, width, height)
  Cmd.new(type: :image_op, payload: {op: "create_image", handle:, pixels:, width:, height:})
end

.delete_image(handle) ⇒ Cmd

Delete an image handle.

Parameters:

  • handle (String)

Returns:



55
# File 'lib/plushie/command/image.rb', line 55

def delete_image(handle) = Cmd.new(type: :image_op, payload: {op: "delete_image", handle:})

.list_images(tag) ⇒ Cmd

List all image handles. Result via Event::System.

Parameters:

  • tag (Symbol)

Returns:



60
# File 'lib/plushie/command/image.rb', line 60

def list_images(tag) = Cmd.new(type: :image_op, payload: {op: "list", tag: tag.to_s})

.update_image(handle, data) ⇒ Cmd

Update an existing image handle from encoded bytes.

Parameters:

  • handle (String)
  • data (String)

    encoded image bytes

Returns:



37
38
39
# File 'lib/plushie/command/image.rb', line 37

def update_image(handle, data)
  Cmd.new(type: :image_op, payload: {op: "update_image", handle:, data:})
end

.update_image_rgba(handle, width, height, pixels) ⇒ Cmd

Update an existing image handle from raw RGBA pixel data.

Parameters:

  • handle (String)
  • width (Integer)

    pixel width

  • height (Integer)

    pixel height

  • pixels (String)

    raw RGBA pixel data

Returns:



47
48
49
50
# File 'lib/plushie/command/image.rb', line 47

def update_image_rgba(handle, width, height, pixels)
  validate_pixel_buffer!(pixels, width, height)
  Cmd.new(type: :image_op, payload: {op: "update_image", handle:, pixels:, width:, height:})
end

.validate_pixel_buffer!(pixels, width, height) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Validate pixel buffer size matches dimensions.

Raises:

  • (ArgumentError)


68
69
70
71
72
73
74
75
# File 'lib/plushie/command/image.rb', line 68

def validate_pixel_buffer!(pixels, width, height)
  expected = width * height * 4
  return if pixels.bytesize == expected

  raise ArgumentError,
    "pixel buffer size mismatch: expected #{expected} bytes " \
    "(#{width}x#{height}x4 RGBA) but got #{pixels.bytesize}"
end