| 1 |
package sixel |
| 2 |
|
| 3 |
import ( |
| 4 |
"bufio" |
| 5 |
"errors" |
| 6 |
"fmt" |
| 7 |
"image" |
| 8 |
"image/color" |
| 9 |
"io" |
| 10 |
"slices" |
| 11 |
) |
| 12 |
|
| 13 |
// Decoder is a Sixel image decoder. It reads Sixel image data from an |
| 14 |
// io.Reader and decodes it into an image.Image. |
| 15 |
type Decoder struct{} |
| 16 |
|
| 17 |
// Decode will parse sixel image data into an image or return an error. Because |
| 18 |
// the sixel image format does not have a predictable size, the end of the sixel |
| 19 |
// image data can only be identified when ST, ESC, or BEL has been read from a reader. |
| 20 |
// In order to avoid reading bytes from a reader one at a time to avoid missing |
| 21 |
// the end, this method simply accepts a byte slice instead of a reader. Callers |
| 22 |
// should read the entire escape sequence and pass the Ps..Ps portion of the sequence |
| 23 |
// to this method. |
| 24 |
func (d *Decoder) Decode(r io.Reader) (image.Image, error) { |
| 25 |
rd := bufio.NewReader(r) |
| 26 |
peeked, err := rd.Peek(1) |
| 27 |
if err != nil { |
| 28 |
return nil, err //nolint:wrapcheck |
| 29 |
} |
| 30 |
|
| 31 |
var bounds image.Rectangle |
| 32 |
var raster Raster |
| 33 |
if peeked[0] == RasterAttribute { |
| 34 |
var read int |
| 35 |
n := 16 |
| 36 |
for { |
| 37 |
peeked, err = rd.Peek(n) // random number, just need to read a few bytes |
| 38 |
if err != nil { |
| 39 |
return nil, err //nolint:wrapcheck |
| 40 |
} |
| 41 |
|
| 42 |
raster, read = DecodeRaster(peeked) |
| 43 |
if read == 0 { |
| 44 |
return nil, ErrInvalidRaster |
| 45 |
} |
| 46 |
if read >= n { |
| 47 |
// We need to read more bytes to get the full raster |
| 48 |
n *= 2 |
| 49 |
continue |
| 50 |
} |
| 51 |
|
| 52 |
rd.Discard(read) //nolint:errcheck,gosec,gosec |
| 53 |
break |
| 54 |
} |
| 55 |
|
| 56 |
bounds = image.Rect(0, 0, raster.Ph, raster.Pv) |
| 57 |
} |
| 58 |
|
| 59 |
if bounds.Max.X == 0 || bounds.Max.Y == 0 { |
| 60 |
// We're parsing the image with no pixel metrics so unread the byte for the |
| 61 |
// main read loop |
| 62 |
// Peek the whole buffer to get the size of the image before we start |
| 63 |
// decoding it. |
| 64 |
var data []byte |
| 65 |
toPeak := 64 // arbitrary number of bytes to peak |
| 66 |
for { |
| 67 |
data, err = rd.Peek(toPeak) |
| 68 |
if err != nil || len(data) < toPeak { |
| 69 |
break |
| 70 |
} |
| 71 |
toPeak *= 2 |
| 72 |
} |
| 73 |
|
| 74 |
width, height := d.scanSize(data) |
| 75 |
bounds = image.Rect(0, 0, width, height) |
| 76 |
} |
| 77 |
|
| 78 |
img := image.NewRGBA(bounds) |
| 79 |
palette := DefaultPalette() |
| 80 |
var currentX, currentBandY, currentPaletteIndex int |
| 81 |
|
| 82 |
// data buffer used to decode Sixel commands |
| 83 |
data := make([]byte, 0, 6) // arbitrary number of bytes to read |
| 84 |
// i := 0 // keeps track of the data buffer index |
| 85 |
for { |
| 86 |
b, err := rd.ReadByte() |
| 87 |
if err != nil { |
| 88 |
return img, d.readError(err) |
| 89 |
} |
| 90 |
|
| 91 |
count := 1 // default count for Sixel commands |
| 92 |
switch { |
| 93 |
case b == LineBreak: // LF |
| 94 |
currentBandY++ |
| 95 |
currentX = 0 |
| 96 |
case b == CarriageReturn: // CR |
| 97 |
currentX = 0 |
| 98 |
case b == ColorIntroducer: // # |
| 99 |
data = data[:0] |
| 100 |
data = append(data, b) |
| 101 |
for { |
| 102 |
b, err = rd.ReadByte() |
| 103 |
if err != nil { |
| 104 |
return img, d.readError(err) |
| 105 |
} |
| 106 |
// Read bytes until we hit a non-color byte i.e. non-numeric |
| 107 |
// and non-; |
| 108 |
if (b < '0' || b > '9') && b != ';' { |
| 109 |
rd.UnreadByte() //nolint:errcheck,gosec |
| 110 |
break |
| 111 |
} |
| 112 |
|
| 113 |
data = append(data, b) |
| 114 |
} |
| 115 |
|
| 116 |
// Palette operation |
| 117 |
c, n := DecodeColor(data) |
| 118 |
if n == 0 { |
| 119 |
return img, ErrInvalidColor |
| 120 |
} |
| 121 |
|
| 122 |
currentPaletteIndex = c.Pc |
| 123 |
if c.Pu > 0 { |
| 124 |
// Non-zero Pu means we have a color definition to set. |
| 125 |
palette[currentPaletteIndex] = c |
| 126 |
} |
| 127 |
case b == RepeatIntroducer: // ! |
| 128 |
data = data[:0] |
| 129 |
data = append(data, b) |
| 130 |
for { |
| 131 |
b, err = rd.ReadByte() |
| 132 |
if err != nil { |
| 133 |
return img, d.readError(err) |
| 134 |
} |
| 135 |
// Read bytes until we hit a non-numeric and non-repeat byte. |
| 136 |
if (b < '0' || b > '9') && (b < '?' || b > '~') { |
| 137 |
rd.UnreadByte() //nolint:errcheck,gosec |
| 138 |
break |
| 139 |
} |
| 140 |
|
| 141 |
data = append(data, b) |
| 142 |
} |
| 143 |
|
| 144 |
// RLE operation |
| 145 |
r, n := DecodeRepeat(data) |
| 146 |
if n == 0 { |
| 147 |
return img, ErrInvalidRepeat |
| 148 |
} |
| 149 |
|
| 150 |
count = r.Count |
| 151 |
b = r.Char |
| 152 |
fallthrough |
| 153 |
case b >= '?' && b <= '~': |
| 154 |
color := palette[currentPaletteIndex] |
| 155 |
for range count { |
| 156 |
d.writePixel(currentX, currentBandY, b, color, img) |
| 157 |
currentX++ |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
// writePixel will accept a sixel byte (from ? to ~) that defines 6 vertical pixels |
| 164 |
// and write any filled pixels to the image. |
| 165 |
func (d *Decoder) writePixel(x int, bandY int, sixel byte, color color.Color, img *image.RGBA) { |
| 166 |
maskedSixel := (sixel - '?') & 63 |
| 167 |
yOffset := 0 |
| 168 |
for maskedSixel != 0 { |
| 169 |
if maskedSixel&1 != 0 { |
| 170 |
img.Set(x, bandY*6+yOffset, color) |
| 171 |
} |
| 172 |
|
| 173 |
yOffset++ |
| 174 |
maskedSixel >>= 1 |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
// scanSize is only used for legacy sixel images that do not define pixel metrics |
| 179 |
// near the header (technically permitted). In this case, we need to quickly scan |
| 180 |
// the image to figure out what the height and width are. Different terminals |
| 181 |
// treat unfilled pixels around the border of the image diffently, but in our case |
| 182 |
// we will treat all pixels, even empty ones, as part of the image. However, |
| 183 |
// we will allow the image to end with an LF code without increasing the size |
| 184 |
// of the image. |
| 185 |
// |
| 186 |
// In the interest of speed, this method doesn't really parse the image in any |
| 187 |
// meaningful way: pixel codes (? to ~), and the RLE, CR, and LF indicators |
| 188 |
// (!, $, -) cannot appear within a sixel image except as themselves, so we |
| 189 |
// just ignore everything else. The only thing we actually take the time to parse |
| 190 |
// is the number after the RLE indicator to know how much width to add to the current |
| 191 |
// line. |
| 192 |
func (d *Decoder) scanSize(data []byte) (int, int) { |
| 193 |
var maxWidth, bandCount int |
| 194 |
|
| 195 |
// Pixel values are ? to ~. Each one of these encountered increases the max width. |
| 196 |
// a - is a LF and increases the max band count by one. a $ is a CR and resets |
| 197 |
// current width. (char - '?') will get a 6-bit number and the highest bit is |
| 198 |
// the lowest y value, which we should use to increment maxBandPixels. |
| 199 |
// |
| 200 |
// a ! is a RLE indicator, and we should add the numeral to the current width |
| 201 |
var currentWidth int |
| 202 |
newBand := true |
| 203 |
for i := 0; i < len(data); i++ { |
| 204 |
b := data[i] |
| 205 |
switch { |
| 206 |
case b == LineBreak: |
| 207 |
// LF |
| 208 |
currentWidth = 0 |
| 209 |
// The image may end with an LF, so we shouldn't increment the band |
| 210 |
// count until we encounter a pixel |
| 211 |
newBand = true |
| 212 |
case b == CarriageReturn: |
| 213 |
// CR |
| 214 |
currentWidth = 0 |
| 215 |
case b == RepeatIntroducer || (b <= '~' && b >= '?'): |
| 216 |
count := 1 |
| 217 |
if b == RepeatIntroducer { |
| 218 |
// Get the run length for the RLE operation |
| 219 |
r, n := DecodeRepeat(data[i:]) |
| 220 |
if n == 0 { |
| 221 |
return maxWidth, bandCount * 6 |
| 222 |
} |
| 223 |
|
| 224 |
// 1 is added in the loop |
| 225 |
i += n - 1 |
| 226 |
count = r.Count |
| 227 |
} |
| 228 |
|
| 229 |
currentWidth += count |
| 230 |
if newBand { |
| 231 |
newBand = false |
| 232 |
bandCount++ |
| 233 |
} |
| 234 |
|
| 235 |
maxWidth = max(maxWidth, currentWidth) |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
return maxWidth, bandCount * 6 |
| 240 |
} |
| 241 |
|
| 242 |
// readError will take any error returned from a read method (ReadByte, |
| 243 |
// FScanF, etc.) and either wrap or ignore the error. An encountered EOF |
| 244 |
// indicates that it's time to return the completed image so we just |
| 245 |
// return it. |
| 246 |
func (d *Decoder) readError(err error) error { |
| 247 |
if errors.Is(err, io.EOF) { |
| 248 |
return nil |
| 249 |
} |
| 250 |
|
| 251 |
return fmt.Errorf("failed to read sixel data: %w", err) |
| 252 |
} |
| 253 |
|
| 254 |
// The default palette for Sixel images. This is a combination of the Sixel |
| 255 |
// default colors and the xterm colors. |
| 256 |
var colorPalette = [256]color.Color{ |
| 257 |
// Sixel-specific default colors |
| 258 |
0: color.RGBA{0, 0, 0, 255}, |
| 259 |
1: color.RGBA{51, 51, 204, 255}, |
| 260 |
2: color.RGBA{204, 36, 36, 255}, |
| 261 |
3: color.RGBA{51, 204, 51, 255}, |
| 262 |
4: color.RGBA{204, 51, 204, 255}, |
| 263 |
5: color.RGBA{51, 204, 204, 255}, |
| 264 |
6: color.RGBA{204, 204, 51, 255}, |
| 265 |
7: color.RGBA{120, 120, 120, 255}, |
| 266 |
8: color.RGBA{69, 69, 69, 255}, |
| 267 |
9: color.RGBA{87, 87, 153, 255}, |
| 268 |
10: color.RGBA{153, 69, 69, 255}, |
| 269 |
11: color.RGBA{87, 153, 87, 255}, |
| 270 |
12: color.RGBA{153, 87, 153, 255}, |
| 271 |
13: color.RGBA{87, 153, 153, 255}, |
| 272 |
14: color.RGBA{153, 153, 87, 255}, |
| 273 |
15: color.RGBA{204, 204, 204, 255}, |
| 274 |
|
| 275 |
// xterm colors |
| 276 |
16: color.RGBA{0, 0, 0, 255}, // Black1 |
| 277 |
17: color.RGBA{0, 0, 95, 255}, // DarkBlue2 |
| 278 |
18: color.RGBA{0, 0, 135, 255}, // DarkBlue1 |
| 279 |
19: color.RGBA{0, 0, 175, 255}, // DarkBlue |
| 280 |
20: color.RGBA{0, 0, 215, 255}, // Blue3 |
| 281 |
21: color.RGBA{0, 0, 255, 255}, // Blue2 |
| 282 |
22: color.RGBA{0, 95, 0, 255}, // DarkGreen4 |
| 283 |
23: color.RGBA{0, 95, 95, 255}, // DarkGreenBlue5 |
| 284 |
24: color.RGBA{0, 95, 135, 255}, // DarkGreenBlue4 |
| 285 |
25: color.RGBA{0, 95, 175, 255}, // DarkGreenBlue3 |
| 286 |
26: color.RGBA{0, 95, 215, 255}, // GreenBlue8 |
| 287 |
27: color.RGBA{0, 95, 255, 255}, // GreenBlue7 |
| 288 |
28: color.RGBA{0, 135, 0, 255}, // DarkGreen3 |
| 289 |
29: color.RGBA{0, 135, 95, 255}, // DarkGreen2 |
| 290 |
30: color.RGBA{0, 135, 0, 255}, // DarkGreenBlue2 |
| 291 |
31: color.RGBA{0, 135, 175, 255}, // DarkGreenBlue1 |
| 292 |
32: color.RGBA{0, 125, 215, 255}, // GreenBlue6 |
| 293 |
33: color.RGBA{0, 135, 255, 255}, // GreenBlue5 |
| 294 |
34: color.RGBA{0, 175, 0, 255}, // DarkGreen1 |
| 295 |
35: color.RGBA{0, 175, 95, 255}, // DarkGreen |
| 296 |
36: color.RGBA{0, 175, 135, 255}, // DarkBlueGreen |
| 297 |
37: color.RGBA{0, 175, 175, 255}, // DarkGreenBlue |
| 298 |
38: color.RGBA{0, 175, 215, 255}, // GreenBlue4 |
| 299 |
39: color.RGBA{0, 175, 255, 255}, // GreenBlue3 |
| 300 |
40: color.RGBA{0, 215, 0, 255}, // Green7 |
| 301 |
41: color.RGBA{0, 215, 95, 255}, // Green6 |
| 302 |
42: color.RGBA{0, 215, 135, 255}, // Green5 |
| 303 |
43: color.RGBA{0, 215, 175, 255}, // BlueGreen1 |
| 304 |
44: color.RGBA{0, 215, 215, 255}, // GreenBlue2 |
| 305 |
45: color.RGBA{0, 215, 255, 255}, // GreenBlue1 |
| 306 |
46: color.RGBA{0, 255, 0, 255}, // Green4 |
| 307 |
47: color.RGBA{0, 255, 95, 255}, // Green3 |
| 308 |
48: color.RGBA{0, 255, 135, 255}, // Green2 |
| 309 |
49: color.RGBA{0, 255, 175, 255}, // Green1 |
| 310 |
50: color.RGBA{0, 255, 215, 255}, // BlueGreen |
| 311 |
51: color.RGBA{0, 255, 255, 255}, // GreenBlue |
| 312 |
52: color.RGBA{95, 0, 0, 255}, // DarkRed2 |
| 313 |
53: color.RGBA{95, 0, 95, 255}, // DarkPurple4 |
| 314 |
54: color.RGBA{95, 0, 135, 255}, // DarkBluePurple2 |
| 315 |
55: color.RGBA{95, 0, 175, 255}, // DarkBluePurple1 |
| 316 |
56: color.RGBA{95, 0, 215, 255}, // PurpleBlue |
| 317 |
57: color.RGBA{95, 0, 255, 255}, // Blue1 |
| 318 |
58: color.RGBA{95, 95, 0, 255}, // DarkYellow4 |
| 319 |
59: color.RGBA{95, 95, 95, 255}, // Gray3 |
| 320 |
60: color.RGBA{95, 95, 135, 255}, // PlueBlue8 |
| 321 |
61: color.RGBA{95, 95, 175, 255}, // PaleBlue7 |
| 322 |
62: color.RGBA{95, 95, 215, 255}, // PaleBlue6 |
| 323 |
63: color.RGBA{95, 95, 255, 255}, // PaleBlue5 |
| 324 |
64: color.RGBA{95, 135, 0, 255}, // DarkYellow3 |
| 325 |
65: color.RGBA{95, 135, 95, 255}, // PaleGreen12 |
| 326 |
66: color.RGBA{95, 135, 135, 255}, // PaleGreen11 |
| 327 |
67: color.RGBA{95, 135, 175, 255}, // PaleGreenBlue10 |
| 328 |
68: color.RGBA{95, 135, 215, 255}, // PaleGreenBlue9 |
| 329 |
69: color.RGBA{95, 135, 255, 255}, // PaleBlue4 |
| 330 |
70: color.RGBA{95, 175, 0, 255}, // DarkGreenYellow |
| 331 |
71: color.RGBA{95, 175, 95, 255}, // PaleGreen11 |
| 332 |
72: color.RGBA{95, 175, 135, 255}, // PaleGreen10 |
| 333 |
73: color.RGBA{95, 175, 175, 255}, // PaleGreenBlue8 |
| 334 |
74: color.RGBA{95, 175, 215, 255}, // PaleGreenBlue7 |
| 335 |
75: color.RGBA{95, 175, 255, 255}, // PaleGreenBlue6 |
| 336 |
76: color.RGBA{95, 215, 0, 255}, // YellowGreen1 |
| 337 |
77: color.RGBA{95, 215, 95, 255}, // PaleGreen9 |
| 338 |
78: color.RGBA{95, 215, 135, 255}, // PaleGreen8 |
| 339 |
79: color.RGBA{95, 215, 175, 255}, // PaleGreen7 |
| 340 |
80: color.RGBA{95, 215, 215, 255}, // PaleGreenBlue5 |
| 341 |
81: color.RGBA{95, 215, 255, 255}, // PaleGreenBlue4 |
| 342 |
82: color.RGBA{95, 255, 0, 255}, // YellowGreen |
| 343 |
83: color.RGBA{95, 255, 95, 255}, // PaleGreen6 |
| 344 |
84: color.RGBA{95, 255, 135, 255}, // PaleGreen5 |
| 345 |
85: color.RGBA{95, 255, 175, 255}, // PaleGreen4 |
| 346 |
86: color.RGBA{95, 255, 215, 255}, // PaleGreen3 |
| 347 |
87: color.RGBA{95, 255, 255, 255}, // PaleGreenBlue3 |
| 348 |
88: color.RGBA{135, 0, 0, 255}, // DarkRed1 |
| 349 |
89: color.RGBA{135, 0, 95, 255}, // DarkPurple3 |
| 350 |
90: color.RGBA{135, 0, 135, 255}, // DarkPurple2 |
| 351 |
91: color.RGBA{135, 0, 175, 255}, // DarkBluePurple |
| 352 |
92: color.RGBA{135, 0, 215, 255}, // BluePurple4 |
| 353 |
93: color.RGBA{135, 0, 255, 255}, // BluePurple3 |
| 354 |
94: color.RGBA{135, 95, 0, 255}, // DarkOrange1 |
| 355 |
95: color.RGBA{135, 95, 95, 255}, // PaleRed5 |
| 356 |
96: color.RGBA{135, 95, 135, 255}, // PalePurple7 |
| 357 |
97: color.RGBA{135, 95, 175, 255}, // PalePurpleBlue |
| 358 |
98: color.RGBA{135, 95, 215, 255}, // PaleBlue3 |
| 359 |
99: color.RGBA{135, 95, 255, 255}, // PaleBlue2 |
| 360 |
100: color.RGBA{135, 135, 0, 255}, // DarkYellow2 |
| 361 |
101: color.RGBA{135, 135, 95, 255}, // PaleYellow7 |
| 362 |
102: color.RGBA{135, 135, 135, 255}, // Gray2 |
| 363 |
103: color.RGBA{135, 135, 175, 255}, // PaleBlue1 |
| 364 |
104: color.RGBA{135, 135, 215, 255}, // PaleBlue |
| 365 |
105: color.RGBA{135, 135, 255, 255}, // LightPaleBlue4 |
| 366 |
106: color.RGBA{135, 175, 0, 255}, // DarkYellow1 |
| 367 |
107: color.RGBA{135, 175, 95, 255}, // PaleYellowGreen3 |
| 368 |
108: color.RGBA{135, 175, 135, 255}, // PaleGreen2 |
| 369 |
109: color.RGBA{135, 175, 175, 255}, // PaleGreenBlue2 |
| 370 |
110: color.RGBA{135, 175, 215, 255}, // PaleGreenBlue1 |
| 371 |
111: color.RGBA{135, 175, 255, 255}, // LightPaleGreenBlue6 |
| 372 |
112: color.RGBA{135, 215, 0, 255}, // Yellow6 |
| 373 |
113: color.RGBA{135, 215, 95, 255}, // PaleYellowGreen2 |
| 374 |
114: color.RGBA{135, 215, 135, 255}, // PaleGreen1 |
| 375 |
115: color.RGBA{135, 215, 175, 255}, // PaleGreen |
| 376 |
116: color.RGBA{135, 215, 215, 255}, // PaleGreenBlue |
| 377 |
117: color.RGBA{135, 215, 255, 255}, // LightPaleGreenBlue5 |
| 378 |
118: color.RGBA{135, 255, 0, 255}, // GreenYellow |
| 379 |
119: color.RGBA{135, 255, 95, 255}, // PaleYellowGreen1 |
| 380 |
120: color.RGBA{135, 255, 135, 255}, // LightPaleGreen6 |
| 381 |
121: color.RGBA{135, 255, 175, 255}, // LightPaleGreen5 |
| 382 |
122: color.RGBA{135, 255, 215, 255}, // LightPaleGreen4 |
| 383 |
123: color.RGBA{135, 255, 255, 255}, // LightPaleGreenBlue4 |
| 384 |
124: color.RGBA{175, 0, 0, 255}, // DarkRed |
| 385 |
125: color.RGBA{175, 0, 95, 255}, // DarkRedPurple |
| 386 |
126: color.RGBA{175, 0, 135, 255}, // DarkPurple1 |
| 387 |
127: color.RGBA{175, 0, 175, 255}, // DarkPurple |
| 388 |
128: color.RGBA{175, 0, 215, 255}, // BluePurple2 |
| 389 |
129: color.RGBA{175, 0, 255, 255}, // BluePurple1 |
| 390 |
130: color.RGBA{175, 95, 0, 255}, // DarkOrange |
| 391 |
131: color.RGBA{175, 95, 95, 255}, // PaleRed4 |
| 392 |
132: color.RGBA{175, 95, 135, 255}, // PalePurpleRed3 |
| 393 |
133: color.RGBA{175, 95, 175, 255}, // PalePurple6 |
| 394 |
134: color.RGBA{175, 95, 215, 255}, // PaleBluePurple3 |
| 395 |
135: color.RGBA{175, 95, 255, 255}, // PaleBluePurple2 |
| 396 |
136: color.RGBA{175, 135, 0, 255}, // DarkYellowOrange |
| 397 |
137: color.RGBA{175, 135, 95, 255}, // PaleRedOrange3 |
| 398 |
138: color.RGBA{175, 135, 135, 255}, // PaleRed3 |
| 399 |
139: color.RGBA{175, 135, 175, 255}, // PalePurple5 |
| 400 |
140: color.RGBA{175, 135, 215, 255}, // PaleBluePurple1 |
| 401 |
141: color.RGBA{175, 135, 255, 255}, // LightPaleBlue3 |
| 402 |
142: color.RGBA{175, 175, 0, 255}, // DarkYellow |
| 403 |
143: color.RGBA{175, 175, 95, 255}, // PaleYellow6 |
| 404 |
144: color.RGBA{175, 175, 135, 255}, // PaleYellow5 |
| 405 |
145: color.RGBA{175, 175, 175, 255}, // Gray1 |
| 406 |
146: color.RGBA{175, 175, 215, 255}, // LightPaleBlue2 |
| 407 |
147: color.RGBA{175, 175, 255, 255}, // LightPaleBlue1 |
| 408 |
148: color.RGBA{175, 215, 0, 255}, // Yellow5 |
| 409 |
149: color.RGBA{175, 215, 95, 255}, // PaleYellow4 |
| 410 |
150: color.RGBA{175, 215, 135, 255}, // PaleGreenYellow |
| 411 |
151: color.RGBA{175, 215, 175, 255}, // LightPaleGreen3 |
| 412 |
152: color.RGBA{175, 215, 215, 255}, // LightPaleGreenBlue3 |
| 413 |
153: color.RGBA{175, 215, 255, 255}, // LightPaleGreenBlue2 |
| 414 |
154: color.RGBA{175, 255, 0, 255}, // Yellow4 |
| 415 |
155: color.RGBA{175, 255, 95, 255}, // PaleYellowGreen |
| 416 |
156: color.RGBA{175, 255, 135, 255}, // LightPaleYellowGreen1 |
| 417 |
157: color.RGBA{175, 255, 215, 255}, // LightPaleGreen2 |
| 418 |
158: color.RGBA{175, 255, 215, 255}, // LightPaleGreen1 |
| 419 |
159: color.RGBA{175, 255, 255, 255}, // LightPaleGreenBlue1 |
| 420 |
160: color.RGBA{215, 0, 0, 255}, // Red2 |
| 421 |
161: color.RGBA{215, 0, 95, 255}, // PurpleRed1 |
| 422 |
162: color.RGBA{215, 0, 135, 255}, // Purple6 |
| 423 |
163: color.RGBA{215, 0, 175, 255}, // Purple5 |
| 424 |
164: color.RGBA{215, 0, 215, 255}, // Purple4 |
| 425 |
165: color.RGBA{215, 0, 255, 255}, // BluePurple |
| 426 |
166: color.RGBA{215, 95, 0, 255}, // RedOrange1 |
| 427 |
167: color.RGBA{215, 95, 95, 255}, // PaleRed2 |
| 428 |
168: color.RGBA{215, 95, 135, 255}, // PalePurpleRed2 |
| 429 |
169: color.RGBA{215, 95, 175, 255}, // PalePurple4 |
| 430 |
170: color.RGBA{215, 95, 215, 255}, // PalePurple3 |
| 431 |
171: color.RGBA{215, 95, 255, 255}, // PaleBluePurple |
| 432 |
172: color.RGBA{215, 135, 0, 255}, // Orange2 |
| 433 |
173: color.RGBA{215, 135, 95, 255}, // PaleRedOrange2 |
| 434 |
174: color.RGBA{215, 135, 135, 255}, // PaleRed1 |
| 435 |
175: color.RGBA{215, 135, 175, 255}, // PaleRedPurple |
| 436 |
176: color.RGBA{215, 135, 215, 255}, // PalePurple2 |
| 437 |
177: color.RGBA{215, 135, 255, 255}, // LightPaleBluePurple |
| 438 |
178: color.RGBA{215, 175, 0, 255}, // OrangeYellow1 |
| 439 |
179: color.RGBA{215, 175, 95, 255}, // PaleOrange1 |
| 440 |
180: color.RGBA{215, 175, 135, 255}, // PaleRedOrange1 |
| 441 |
181: color.RGBA{215, 175, 175, 255}, // LightPaleRed3 |
| 442 |
182: color.RGBA{215, 175, 215, 255}, // LightPalePurple4 |
| 443 |
183: color.RGBA{215, 175, 255, 255}, // LightPalePurpleBlue |
| 444 |
184: color.RGBA{215, 215, 0, 255}, // Yellow3 |
| 445 |
185: color.RGBA{215, 215, 95, 255}, // PaleYellow3 |
| 446 |
186: color.RGBA{215, 215, 135, 255}, // PaleYellow2 |
| 447 |
187: color.RGBA{215, 215, 175, 255}, // LightPaleYellow4 |
| 448 |
188: color.RGBA{215, 215, 215, 255}, // LightGray |
| 449 |
189: color.RGBA{215, 215, 255, 255}, // LightPaleBlue |
| 450 |
190: color.RGBA{215, 255, 0, 255}, // Yellow2 |
| 451 |
191: color.RGBA{215, 255, 95, 255}, // PaleYellow1 |
| 452 |
192: color.RGBA{215, 255, 135, 255}, // LightPaleYellow3 |
| 453 |
193: color.RGBA{215, 255, 175, 255}, // LightPaleYellowGreen |
| 454 |
194: color.RGBA{215, 255, 215, 255}, // LightPaleGreen |
| 455 |
195: color.RGBA{215, 255, 255, 255}, // LightPaleGreenBlue |
| 456 |
196: color.RGBA{255, 0, 0, 255}, // Red1 |
| 457 |
197: color.RGBA{255, 0, 95, 255}, // PurpleRed |
| 458 |
198: color.RGBA{255, 0, 135, 255}, // RedPurple |
| 459 |
199: color.RGBA{255, 0, 175, 255}, // Purple3 |
| 460 |
200: color.RGBA{255, 0, 215, 255}, // Purple2 |
| 461 |
201: color.RGBA{255, 0, 255, 255}, // Purple1 |
| 462 |
202: color.RGBA{255, 95, 0, 255}, // RedOrange |
| 463 |
203: color.RGBA{255, 95, 95, 255}, // PaleRed |
| 464 |
204: color.RGBA{255, 95, 135, 255}, // PalePurpleRed1 |
| 465 |
205: color.RGBA{255, 95, 175, 255}, // PalePurpleRed |
| 466 |
206: color.RGBA{255, 95, 215, 255}, // PalePurple1 |
| 467 |
207: color.RGBA{255, 95, 255, 255}, // PalePurple |
| 468 |
208: color.RGBA{255, 135, 0, 255}, // Orange1 |
| 469 |
209: color.RGBA{255, 135, 95, 255}, // PaleOrangeRed |
| 470 |
210: color.RGBA{255, 135, 135, 255}, // LightPaleRed2 |
| 471 |
211: color.RGBA{255, 135, 175, 255}, // LightPalePurpleRed1 |
| 472 |
212: color.RGBA{255, 135, 215, 255}, // LightPalePurple3 |
| 473 |
213: color.RGBA{255, 135, 255, 255}, // LightPalePurple2 |
| 474 |
214: color.RGBA{255, 175, 0, 255}, // Orange |
| 475 |
215: color.RGBA{255, 175, 95, 255}, // PaleRedOrange |
| 476 |
216: color.RGBA{255, 175, 135, 255}, // LightPaleRedOrange1 |
| 477 |
217: color.RGBA{255, 175, 175, 255}, // LightPaleRed1 |
| 478 |
218: color.RGBA{255, 175, 215, 255}, // LightPalePurpleRed |
| 479 |
219: color.RGBA{255, 175, 255, 255}, // LightPalePurple1 |
| 480 |
220: color.RGBA{255, 215, 0, 255}, // OrangeYellow |
| 481 |
221: color.RGBA{255, 215, 95, 255}, // PaleOrange |
| 482 |
222: color.RGBA{255, 215, 135, 255}, // LightPaleOrange |
| 483 |
223: color.RGBA{255, 215, 175, 255}, // LightPaleRedOrange |
| 484 |
224: color.RGBA{255, 215, 215, 255}, // LightPaleRed |
| 485 |
225: color.RGBA{255, 215, 255, 255}, // LightPalePurple |
| 486 |
226: color.RGBA{255, 255, 0, 255}, // Yellow1 |
| 487 |
227: color.RGBA{255, 255, 95, 255}, // PaleYellow |
| 488 |
228: color.RGBA{255, 255, 135, 255}, // LightPaleYellow2 |
| 489 |
229: color.RGBA{255, 255, 175, 255}, // LightPaleYellow1 |
| 490 |
230: color.RGBA{255, 255, 215, 255}, // LightPaleYellow |
| 491 |
231: color.RGBA{255, 255, 255, 255}, // White1 |
| 492 |
232: color.RGBA{8, 8, 8, 255}, // Gray4 |
| 493 |
233: color.RGBA{18, 18, 18, 255}, // Gray8 |
| 494 |
234: color.RGBA{28, 28, 28, 255}, // Gray11 |
| 495 |
235: color.RGBA{38, 38, 38, 255}, // Gray15 |
| 496 |
236: color.RGBA{48, 48, 48, 255}, // Gray19 |
| 497 |
237: color.RGBA{58, 58, 58, 255}, // Gray23 |
| 498 |
238: color.RGBA{68, 68, 68, 255}, // Gray27 |
| 499 |
239: color.RGBA{78, 78, 78, 255}, // Gray31 |
| 500 |
240: color.RGBA{88, 88, 88, 255}, // Gray35 |
| 501 |
241: color.RGBA{98, 98, 98, 255}, // Gray39 |
| 502 |
242: color.RGBA{108, 108, 108, 255}, // Gray43 |
| 503 |
243: color.RGBA{118, 118, 118, 255}, // Gray47 |
| 504 |
244: color.RGBA{128, 128, 128, 255}, // Gray51 |
| 505 |
245: color.RGBA{138, 138, 138, 255}, // Gray55 |
| 506 |
246: color.RGBA{148, 148, 148, 255}, // Gray59 |
| 507 |
247: color.RGBA{158, 158, 158, 255}, // Gray62 |
| 508 |
248: color.RGBA{168, 168, 168, 255}, // Gray66 |
| 509 |
249: color.RGBA{178, 178, 178, 255}, // Gray70 |
| 510 |
250: color.RGBA{188, 188, 188, 255}, // Gray74 |
| 511 |
251: color.RGBA{198, 198, 198, 255}, // Gray78 |
| 512 |
252: color.RGBA{208, 208, 208, 255}, // Gray82 |
| 513 |
253: color.RGBA{218, 218, 218, 255}, // Gray86 |
| 514 |
254: color.RGBA{228, 228, 228, 255}, // Gray90 |
| 515 |
255: color.RGBA{238, 238, 238, 255}, // Gray94 |
| 516 |
} |
| 517 |
|
| 518 |
// DefaultPalette is the default palette used when decoding a Sixel image. |
| 519 |
// It contains the 256 colors defined by the xterm 256-color palette. |
| 520 |
func DefaultPalette() color.Palette { |
| 521 |
// Undefined colors in sixel images use a set of default colors: 0-15 |
| 522 |
// are sixel-specific, 16-255 are the same as the xterm 256-color values |
| 523 |
palette := slices.Clone(colorPalette[:]) |
| 524 |
return palette[:] |
| 525 |
} |