Last active
November 12, 2022 04:13
-
-
Save MCJack123/fdf2594065f1e65bb4828aa107862434 to your computer and use it in GitHub Desktop.
Converts TI-84+ CE .8ci bitmap pictures/images to PNG files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// requires libpng and png++ (brew install png++) (sudo apt-get install libpng++-dev) | |
// compile with g++ -o 8ci-png 8ci-png.cpp -lpng | |
// add -I/usr/local/include if on mac and errors out with "png++/png.hpp: no such file or directory" | |
#include <iostream> | |
#include <fstream> | |
#include <vector> | |
#include <png++/png.hpp> | |
//-----------8ci palette--------------- | |
std::vector<png::rgb_pixel> colors = { | |
{255, 255, 255}, // white/none | |
{0, 0, 255}, // BLUE | |
{255, 0, 0}, // RED | |
{0, 0, 0}, // BLACK | |
{255, 0, 255}, // MAGENTA | |
{0, 255, 0}, // GREEN | |
{255, 160, 0}, // ORANGE | |
{128, 32, 0}, // BROWN | |
{0, 0, 128}, // NAVY | |
{0, 144, 255}, // LTBLUE | |
{255, 255, 0}, // YELLOW | |
{255, 255, 255}, // WHITE | |
{192, 192, 192}, // LTGRAY | |
{128, 128, 128}, // MEDGRAY | |
{96, 96, 96}, // GRAY | |
{64, 64, 64} // DARKGRAY | |
}; | |
enum colors { | |
COLOR_NONE, | |
COLOR_BLUE, | |
COLOR_RED, | |
COLOR_BLACK, | |
COLOR_MAGENTA, | |
COLOR_GREEN, | |
COLOR_ORANGE, | |
COLOR_BROWN, | |
COLOR_NAVY, | |
COLOR_LTBLUE, | |
COLOR_YELLOW, | |
COLOR_WHITE, | |
COLOR_LTGRAY, | |
COLOR_MEDGRAY, | |
COLOR_GRAY, | |
COLOR_DARKGRAY | |
}; | |
//------------------------------------- | |
int main(int argc, const char * argv[]) { | |
if (argc < 2) { | |
std::cerr << "Usage: " << argv[0] << " <input.8ci> [output.png]\n"; | |
return 1; | |
} | |
std::string out = std::string(argv[1]) + ".png"; | |
if (argc > 2) out = std::string(argv[2]); | |
std::ifstream in(argv[1]); | |
if (!in.is_open()) { | |
std::cerr << "Could not open " << argv[1] << ".\n"; | |
return 2; | |
} | |
in.seekg(74); // this may or may not always hold true | |
png::image<png::rgb_pixel> img(266, 165); // same here | |
int x = 0, y = 0; | |
while (!in.eof() && y < 165) { | |
char ch = in.get(); | |
img.set_pixel(x++, y, colors[(ch & 0xF0) >> 4]); | |
img.set_pixel(x++, y, colors[ch & 0x0F]); | |
if (x > 265) {x = 0; y++;} | |
} | |
img.write(out); | |
std::cout << "Wrote image\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment