mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[escher] The image inliner produces proper RGB565 little-endian images
Change-Id: I96f6df798911657b9582cc264ee1d2c3ebada690
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
#define MAX_FILENAME_LENGTH 255
|
||||
|
||||
void generateHeaderFromImage(FILE * file, const char * guardian, const char * variable);
|
||||
void generateImplementationFromImage(FILE * file, const char * header, const char * variable, uint32_t width, uint32_t height, uint32_t ** pixelsRowPointers);
|
||||
void generateImplementationFromImage(FILE * file, const char * header, const char * variable, uint32_t width, uint32_t height, png_bytep * pixelsRowPointers);
|
||||
void fileNameToSnakeCaseName(const char * fileName, char * snakeCaseName, size_t maxLength);
|
||||
void snakeCaseNameToUpperSnakeName(const char * snakeCaseName, char * upperSnakeCaseName, size_t maxLength);
|
||||
void camelCaseNameFromSnakeCaseNames(const char * snakeCaseName, const char * upperSnakeCaseName, char * camelCaseName, size_t maxLength);
|
||||
@@ -93,7 +93,7 @@ int main(int argc, char * argv[]) {
|
||||
fclose(header);
|
||||
|
||||
FILE * implementation = fopen(implementationPath, "w");
|
||||
generateImplementationFromImage(implementation, lowerSnakeCaseName, camelCaseName, width, height, (uint32_t **)rowPointers);
|
||||
generateImplementationFromImage(implementation, lowerSnakeCaseName, camelCaseName, width, height, rowPointers);
|
||||
fclose(implementation);
|
||||
|
||||
fclose(inputFile);
|
||||
@@ -142,19 +142,28 @@ void generateHeaderFromImage(FILE * file, const char * guardian, const char * va
|
||||
fprintf(file, "#endif\n");
|
||||
}
|
||||
|
||||
void generateImplementationFromImage(FILE * file, const char * header, const char * variable, uint32_t width, uint32_t height, uint32_t ** pixelsRowPointers) {
|
||||
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[] = {");
|
||||
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 ");
|
||||
}
|
||||
uint32_t rgba = pixelsRowPointers[j][i];
|
||||
uint16_t rgb565 = (((rgba&0xF8000000)>>16)|((rgba&0x00FC0000)>>14)|((rgba&0x0000F800)>>11));
|
||||
//if (rgba & 0xFF == 0) { rgb565 = 0xFFFF; }
|
||||
fprintf(file, "0x%02X, 0x%02X", rgb565 >> 8, rgb565 & 0xFF);
|
||||
png_bytep pixel = &(pixelRow[i*4]);
|
||||
double red = pixel[0]/255.0;
|
||||
double green = pixel[1]/255.0;
|
||||
double blue = pixel[2]/255.0;
|
||||
double alpha = pixel[3]/255.0;
|
||||
// Assume a white background (1.0, 1.0, 1.0) in the blending
|
||||
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);
|
||||
if (i!=width-1 || j!= height-1) {
|
||||
fprintf(file, ", ");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user