Module: Plushie::Command::Image
- Defined in:
- lib/plushie/command/image.rb
Overview
Image handle management commands.
Class Method Summary collapse
-
.clear_images ⇒ Cmd
Remove all image handles.
-
.create_image(handle, data) ⇒ Cmd
Create an image from encoded data (PNG/JPEG bytes).
-
.create_image_rgba(handle, width, height, pixels) ⇒ Cmd
Create an image from raw RGBA pixel data.
-
.delete_image(handle) ⇒ Cmd
Delete an image handle.
-
.list_images(tag) ⇒ Cmd
List all image handles.
-
.update_image(handle, data) ⇒ Cmd
Update an existing image handle from encoded bytes.
-
.update_image_rgba(handle, width, height, pixels) ⇒ Cmd
Update an existing image handle from raw RGBA pixel data.
-
.validate_pixel_buffer!(pixels, width, height) ⇒ Object
private
Validate pixel buffer size matches dimensions.
Class Method Details
.clear_images ⇒ Cmd
Remove all image handles.
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).
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.
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.
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.
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.
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.
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.
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 |