Converts the canvas to an SDS string representing the UTF8 characters to * print to the terminal in order to obtain a graphical representaiton of the * logical canvas. The actual returned string will require a terminal that is * width/2 large and height/4 tall in order to hold the whole image without * overflowing or scrolling, since each Barille character is 2x4. */
| 107 | * width/2 large and height/4 tall in order to hold the whole image without |
| 108 | * overflowing or scrolling, since each Barille character is 2x4. */ |
| 109 | static sds renderCanvas(lwCanvas *canvas) { |
| 110 | sds text = sdsempty(); |
| 111 | for (int y = 0; y < canvas->height; y += 4) { |
| 112 | for (int x = 0; x < canvas->width; x += 2) { |
| 113 | /* We need to emit groups of 8 bits according to a specific |
| 114 | * arrangement. See lwTranslatePixelsGroup() for more info. */ |
| 115 | int byte = 0; |
| 116 | if (lwGetPixel(canvas,x,y)) byte |= (1<<0); |
| 117 | if (lwGetPixel(canvas,x,y+1)) byte |= (1<<1); |
| 118 | if (lwGetPixel(canvas,x,y+2)) byte |= (1<<2); |
| 119 | if (lwGetPixel(canvas,x+1,y)) byte |= (1<<3); |
| 120 | if (lwGetPixel(canvas,x+1,y+1)) byte |= (1<<4); |
| 121 | if (lwGetPixel(canvas,x+1,y+2)) byte |= (1<<5); |
| 122 | if (lwGetPixel(canvas,x,y+3)) byte |= (1<<6); |
| 123 | if (lwGetPixel(canvas,x+1,y+3)) byte |= (1<<7); |
| 124 | char unicode[3]; |
| 125 | lwTranslatePixelsGroup(byte,unicode); |
| 126 | text = sdscatlen(text,unicode,3); |
| 127 | } |
| 128 | if (y != canvas->height-1) text = sdscatlen(text,"\n",1); |
| 129 | } |
| 130 | return text; |
| 131 | } |
| 132 | |
| 133 | /* The LOLWUT command: |
| 134 | * |
no test coverage detected