Cassiiopeia/projectops / skills/pro-image
pro-image
VerifiedMake image assets (backgrounds, characters, icons, illustrations, items) that fit the project's own style: you write the prompt from a per-repo harness, Codex or Antigravity draws it, the CLI fixes size and transparency. Use for 'make an image', 'draw', 'generate an icon'.
scripts/pro_image/png_codec.py
View on GitHub"""PNG read/write (stdlib zlib): 8-bit, non-interlaced > RGBA pixel bytes
Supported color types 4: 0 gray, 2 RGB, 4 gray+alpha, 6 RGBA (palette, 16-bit, interlaced unsupported > go through a converter)
"""
from __future__ import annotations
import struct
import zlib
from pathlib import Path
PNG_SIGNATURE = b"\x89PNG\r\n\x1a\n"
# Color type > channels per pixel
CHANNELS_BY_COLOR_TYPE = {0: 1, 2: 3, 4: 2, 6: 4}
class UnsupportedPng(ValueError):
pass
def _chunks(data: bytes):
position = len(PNG_SIGNATURE)
while position < len(data):
length = struct.unpack(">I", data[position:position + 4])[0]
kind = data[position + 4:position + 8]
yield kind, data[position + 8:position + 8 + length]
position += 12 + length
def _paeth(left: int, up: int, up_left: int) -> int:
estimate = left + up - up_left
left_distance, up_distance, corner_distance = abs(estimate - left), abs(estimate - up), abs(estimate - up_left)
if left_distance <= up_distance and left_distance <= corner_distance:
return left
return up if up_distance <= corner_distance else up_left
def _unfilter(raw: bytes, width: int, height: int, channels: int) -> bytearray:
"""Undo the 5 per-row filters (None, Sub, Up, Average, Paeth)"""
stride = width * channels
pixels = bytearray(stride * height)
previous = bytearray(stride)
position = 0
for row in range(height):
filter_type = raw[position]
line = bytearray(raw[position + 1:position + 1 + stride])
position += 1 + stride
for index in range(stride):
left = line[index - channels] if index >= channels else 0
up = previous[index]
if filter_type == 1:
line[index] = (line[index] + left) & 0xFF
elif filter_type == 2:
line[index] = (line[index] + up) & 0xFF
elif filter_type == 3:
line[index] = (line[index] + ((left + up) >> 1)) & 0xFF
elif filter_type == 4:
up_left = previous[index - channels] if index >= channels else 0
line[index] = (line[index] + _paeth(left, up, up_left)) & 0xFF
pixels[row * stride:(row + 1) * stride] = line
previous = line
return pixels
def _to_rgba(pixels: bytearray, color_type: int) -> bytearray:
if color_type == 6:
return pixels
rgba = bytearray()
channels = CHANNELS_BY_COLOR_TYPE[color_type]
for index in range(0, len(pixels), channels):
if color_type == 2:
rgba += pixels[index:index + 3] + b"\xff"
elif color_type == 0:
rgba += bytes((pixels[index],) * 3) + b"\xff"
else:
rgba += bytes((pixels[index],) * 3) + bytes((pixels[index + 1],))
return rgba
def read_rgba(path: Path) -> tuple[int, int, bytearray]:
"""PNG > (width, height, RGBA bytes)"""
data = path.read_bytes()
if data[:8] != PNG_SIGNATURE:
raise UnsupportedPng("not a PNG file")
header, compressed = None, bytearray()
for kind, body in _chunks(data):
if kind == b"IHDR":
header = struct.unpack(">IIBBBBB", body)
elif kind == b"IDAT":
compressed += body
if header is None:
raise UnsupportedPng("missing IHDR")
width, height, bit_depth, color_type, _, _, interlace = header
if bit_depth != 8 or interlace != 0 or color_type not in CHANNELS_BY_COLOR_TYPE:
raise UnsupportedPng(f"bit depth {bit_depth}, color type {color_type}, interlace {interlace}")
pixels = _unfilter(zlib.decompress(bytes(compressed)), width, height, CHANNELS_BY_COLOR_TYPE[color_type])
return width, height, _to_rgba(pixels, color_type)
def write_rgba(path: Path, width: int, height: int, rgba: bytes) -> None:
"""RGBA bytes > PNG (filter 0, compression 6)"""
stride = width * 4
raw = b"".join(b"\x00" + bytes(rgba[row * stride:(row + 1) * stride]) for row in range(height))
def chunk(kind: bytes, body: bytes) -> bytes:
return struct.pack(">I", len(body)) + kind + body + struct.pack(">I", zlib.crc32(kind + body) & 0xFFFFFFFF)
header = struct.pack(">IIBBBBB", width, height, 8, 6, 0, 0, 0)
path.write_bytes(PNG_SIGNATURE + chunk(b"IHDR", header) + chunk(b"IDAT", zlib.compress(raw, 6))
+ chunk(b"IEND", b""))
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |