mananapr/pxlart

Image Export (via PPM format)

PaulBatchelor opened this issue · 6 comments

I noticed you had image export on your TODO list. Last night, I managed to hack out that feature! I did some non-trivial changes, so I thought I'd make an issue first before making a PR.

The biggest change in design that I made was creating a struct in C to store screen data: each character "cell" stores the ascii character, and the foreground/background color pair. When a project gets saved, it dumps the contents of this data to a text file.

The data file written to disk can then be parsed by a small C utility I wrote which generates a PPM file, which can then be converted to a PNG file via imagemagick. The program uses the color lookup table adapted from the gist you linked in your README, and a bitmap font which I converted to a C header include file via image magick, some light vim-ing, and xxd.

Not currently at the computer with the code on it, but I'll post some examples when I get the chance.

If this looks interesting to you, I can make a PR with the changes I made.

Here's what renders look like:

hello

This is really impressive work! Feel free to make a PR, I'll merge the changes into master. Thanks for showing interest in my project and contributing!

I was playing around with pxlart and noticed that if I have unicode characters in the window, mkppm segfaults. Is this the expected behavior? I haven't had a chance to look at the code yet

The actual offset is calculated here:

pxlart/mkppm.c

Lines 23 to 26 in 58acac0

letter_offset = c - 32;
letter_offset =
(letter_offset % GLYPHROW)*FONT_WIDTH +
BITMAP_SKIP*(letter_offset/GLYPHROW);

Might make sense to do bounds checking for c inside this function. One could also do it when reading the input:

pxlart/mkppm.c

Lines 121 to 126 in 58acac0

for(r = 0; r < rows; r++) {
for(c = 0; c < cols; c++) {
fscanf(df, "%d %d %d\n", &fg, &bg, &glyph);
draw_glyph(data, c, r, w, h, (unsigned char)glyph, fg, bg);
}
}

I forget what exactly the bounds should be at the moment, but the number corresponds with the ascii character number.

I haven't been getting a lot of free time so I couldn't go through the code myself. Thanks for fixing it