{
  "openapi": "3.1.1",
  "info": {
    "title": "Pixel Grid Transform API",
    "version": "1.0.0",
    "summary": "Flip, rotate or shift an indexed pixel sprite without blur.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://fliplinepixeltransform.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Flip, rotate or shift an indexed pixel sprite without blur.",
        "description": "Enter a compact pixel grid and HEX palette. Transform it with exact integer coordinates, optional wrapping and transparent pixels, then download an editable Flipline Pixel Studio project.\n\nMethodology:\n- Grid index 0 is transparent; 1–9 and A–W refer to palette entries 1–32. Rows must have equal width, at most 128 pixels per side.\n- Rotation is clockwise and swaps width and height. Shift clips outside pixels or wraps them to the opposite edge. No interpolation or color changes.\n- The same transform powers Pixel Studio. Open the downloaded .flipline-pixels.json file with the main Open button or Open sprite.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "flipline_pixel_transform",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FliplinePixelTransformInput"
              },
              "examples": {
                "example1": {
                  "summary": "Rotate a tiny sprite",
                  "value": {
                    "rows": "1..\n.2.",
                    "palette": "#213b45,#65a87b",
                    "operation": "rotate"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FliplinePixelTransformResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "FliplinePixelTransformInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "rows": {
            "title": "Pixel rows (. = transparent; 1–9 then A–W = palette entries)",
            "type": "string",
            "maxLength": 16640,
            "default": "..1..\n.121.\n12321\n.121.\n..1.."
          },
          "palette": {
            "title": "HEX palette (comma separated)",
            "type": "string",
            "maxLength": 300,
            "default": "#213b45,#65a87b,#e6af61"
          },
          "operation": {
            "title": "Operation",
            "type": "string",
            "enum": [
              "flip-x",
              "flip-y",
              "rotate",
              "shift"
            ],
            "default": "rotate"
          },
          "dx": {
            "title": "Shift X (pixels)",
            "type": "integer",
            "minimum": -128,
            "maximum": 128,
            "default": 1
          },
          "dy": {
            "title": "Shift Y (pixels)",
            "type": "integer",
            "minimum": -128,
            "maximum": 128,
            "default": 0
          },
          "wrap": {
            "title": "Wrap shifted pixels",
            "type": "boolean",
            "default": false
          }
        },
        "required": []
      },
      "FliplinePixelTransformResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "width",
              "height",
              "rows",
              "project"
            ],
            "properties": {
              "width": {
                "type": "integer"
              },
              "height": {
                "type": "integer"
              },
              "rows": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "project": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "format",
                  "version",
                  "name",
                  "width",
                  "height",
                  "fps",
                  "background",
                  "palette",
                  "frames",
                  "layers"
                ],
                "properties": {
                  "format": {
                    "const": "flipline-pixels"
                  },
                  "version": {
                    "const": 1
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "width": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 128
                  },
                  "height": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 128
                  },
                  "fps": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 30
                  },
                  "background": {
                    "type": "string",
                    "pattern": "^#[a-fA-F0-9]{6}$"
                  },
                  "palette": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 32,
                    "items": {
                      "type": "string",
                      "pattern": "^#[a-fA-F0-9]{6}$"
                    }
                  },
                  "frames": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 24,
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "hold",
                        "label"
                      ],
                      "properties": {
                        "hold": {
                          "type": "integer",
                          "minimum": 1,
                          "maximum": 10
                        },
                        "label": {
                          "type": "string",
                          "maxLength": 80
                        }
                      }
                    }
                  },
                  "layers": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 4,
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "name",
                        "visible",
                        "locked",
                        "opacity",
                        "cels"
                      ],
                      "properties": {
                        "name": {
                          "type": "string",
                          "maxLength": 80
                        },
                        "visible": {
                          "type": "boolean"
                        },
                        "locked": {
                          "type": "boolean"
                        },
                        "opacity": {
                          "type": "number",
                          "minimum": 0,
                          "maximum": 1
                        },
                        "cels": {
                          "type": "array",
                          "minItems": 1,
                          "maxItems": 24,
                          "items": {
                            "type": "array",
                            "minItems": 1,
                            "maxItems": 16384,
                            "items": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 32
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "description": "Palette indices: 0 is transparent; 1–32 refer to palette entries. Every cel has width × height pixels and every layer has one cel per frame. Indices cannot exceed palette length. Maximum 524288 total stored cel pixels. Layers are front to back. Files: .flipline-pixels.json."
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}