mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
KDImage now takes a KDColor buffer as pixel data
This prevents alignment issues, visible on emscripten for example. Change-Id: I3b25a21214c5f3e4f08e5f299d4c20234a5824f6
This commit is contained in:
@@ -148,12 +148,15 @@ void generateHeaderFromImage(FILE * file, const char * guardian, const char * va
|
||||
void generateImplementationFromImage(FILE * file, const char * header, const char * variable, uint32_t width, uint32_t height, png_bytep * pixelsRowPointers) {
|
||||
fprintf(file, "// This file is auto-generated by Inliner. Do not edit manually.\n");
|
||||
fprintf(file, "#include \"%s.h\"\n\n", header);
|
||||
fprintf(file, "const unsigned char data[] = {");
|
||||
fprintf(file, "#define P(c) KDColor::RGB24(c)\n\n");
|
||||
fprintf(file, "const KDColor pixels[] = {");
|
||||
for (int j=0; j<height; j++) {
|
||||
png_bytep pixelRow = pixelsRowPointers[j];
|
||||
for (int i=0; i<width; i++) {
|
||||
if ((i+j*width) % 6 == 0) {
|
||||
fprintf(file, "\n ");
|
||||
} else {
|
||||
fprintf(file, " ");
|
||||
}
|
||||
png_bytep pixel = &(pixelRow[i*4]);
|
||||
double red = pixel[0]/255.0;
|
||||
@@ -164,15 +167,13 @@ void generateImplementationFromImage(FILE * file, const char * header, const cha
|
||||
double blendedRed = red*alpha + 1.0*(1.0-alpha);
|
||||
double blendedGreen = green*alpha + 1.0*(1.0-alpha);
|
||||
double blendedBlue = blue*alpha + 1.0*(1.0-alpha);
|
||||
// Merge in a RGB565
|
||||
uint16_t rgb565 = ((uint16_t)(blendedRed*0x1F) << 11) | ((uint16_t)(blendedGreen*0x3F) << 5) | ((uint16_t)(blendedBlue*0x1F));
|
||||
fprintf(file, "0x%02X, 0x%02X", rgb565 & 0xFF, rgb565 >> 8);
|
||||
fprintf(file, "P(0x%02X%02X%02X)", (int)(blendedRed*0xFF), (int)(blendedGreen*0xFF), (int)(blendedBlue*0xFF));
|
||||
if (i!=width-1 || j!= height-1) {
|
||||
fprintf(file, ", ");
|
||||
fprintf(file, ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
fprintf(file, "\n};\n\n");
|
||||
fprintf(file, "constexpr Image image = Image(%d, %d, data);\n\n", width, height);
|
||||
fprintf(file, "constexpr Image image = Image(%d, %d, pixels);\n\n", width, height);
|
||||
fprintf(file, "const Image * ImageStore::%s = ℑ\n", variable);
|
||||
}
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
|
||||
class Image {
|
||||
public:
|
||||
constexpr Image(KDCoordinate width, KDCoordinate height, const unsigned char * data) :
|
||||
m_width(width), m_height(height), m_data(data) {}
|
||||
constexpr Image(KDCoordinate width, KDCoordinate height, const KDColor * pixels) :
|
||||
m_width(width), m_height(height), m_pixels(pixels) {}
|
||||
KDCoordinate width() const { return m_width; }
|
||||
KDCoordinate height() const { return m_height; }
|
||||
const KDColor * pixels() const { return (const KDColor *)m_data; }
|
||||
const KDColor * pixels() const { return m_pixels; }
|
||||
private:
|
||||
KDCoordinate m_width;
|
||||
KDCoordinate m_height;
|
||||
const unsigned char * m_data;
|
||||
const KDColor * m_pixels;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user