00001 #include <stdio.h>
00002
00003 #define HEADER_SIZE 0x36
00004
00005 #define RED 2
00006 #define GREEN 1
00007 #define BLUE 0
00008
00009 #define WIDTH 320
00010 #define HEIGHT 240
00011 #define FILENAME_IN "background_image.bmp"
00012 #define FILENAME_OUT "../background_image.c"
00013 #define NAME BACKGROUND_IMAGE
00014 #define BRIEF "Application background image."
00015
00016 #define ALIGN ((-WIDTH * 3) & 3)
00017 #define STRIDE ((WIDTH * 2 + 3) & ~3)
00018
00019 #define STRINGZ(s) #s
00020 #define ASTRINGZ(s) STRINGZ(s)
00021
00022 unsigned char buf[WIDTH * HEIGHT][3];
00023
00024 static inline unsigned int min(unsigned int a, unsigned int b)
00025 {
00026 return (a < b) ? a : b;
00027 }
00028
00029 int main(void)
00030 {
00031 unsigned int r, c;
00032
00033 FILE *Fin = fopen(FILENAME_IN, "rb");
00034 FILE *Fout = fopen(FILENAME_OUT, "w");
00035
00036 fseek(Fin, HEADER_SIZE, SEEK_SET);
00037 for (r = 0; r < HEIGHT; r++)
00038 {
00039 fread(&buf[r * WIDTH], sizeof(buf[0]), WIDTH, Fin);
00040 fseek(Fin, ALIGN, SEEK_CUR);
00041 }
00042
00043 fprintf(Fout, "/*This file is prepared for Doxygen automatic documentation generation.*/\r\n"
00044 "/*! \\file *********************************************************************\r\n"
00045 " *\r\n"
00046 " * \\brief "BRIEF"\r\n"
00047 " *\r\n"
00048 " * - Compiler: IAR EWAVR32 and GNU GCC for AVR32\r\n"
00049 " * - Supported devices: All AVR32 devices can be used.\r\n"
00050 " * - AppNote:\r\n"
00051 " *\r\n"
00052 " * \author Atmel Corporation: http://www.atmel.com \\n\r\n"
00053 " * Support and FAQ: http://support.atmel.no/\r\n"
00054 " *\r\n"
00055 " ******************************************************************************/\r\n"
00056 "\r\n"
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 "\r\n"
00088 "#ifndef _"ASTRINGZ(NAME)"_H_\r\n"
00089 "#define _"ASTRINGZ(NAME)"_H_\r\n"
00090 "\r\n"
00091 "\r\n"
00092 "const unsigned short int background_image[] =\r\n"
00093 "{\r\n"
00094 " ");
00095
00096 for (r = 0; r < HEIGHT; r++)
00097 {
00098 for (c = 0; c < STRIDE; )
00099 {
00100 if (c < WIDTH * 2)
00101 {
00102 unsigned short pixel = (min(buf[(HEIGHT - r - 1) * WIDTH + c / 2][RED ] + 0x04, 0xFF) >> (8 - 5)) << (6 + 5) |
00103 (min(buf[(HEIGHT - r - 1) * WIDTH + c / 2][GREEN] + 0x02, 0xFF) >> (8 - 6)) << 5 |
00104 (min(buf[(HEIGHT - r - 1) * WIDTH + c / 2][BLUE ] + 0x04, 0xFF) >> (8 - 5));
00105 fprintf(Fout, "0x%.2hhX%.2hhX, ", (unsigned char)(pixel >> 8), (unsigned char)pixel);
00106 c += 2;
00107 }
00108 else
00109 {
00110 fputs("0x0000, ", Fout);
00111 c++;
00112 }
00113 if (!((r * STRIDE + c) % 16) && (r != HEIGHT - 1 || c != STRIDE)) fputs("\r\n ", Fout);
00114 }
00115 }
00116
00117 fputs("\r\n"
00118 "};\r\n"
00119 "\r\n"
00120 "#endif\r\n"
00121 "\r\n", Fout);
00122
00123 fclose(Fout);
00124 fclose(Fin);
00125 }