00001
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include "lcdc.h"
00048 #include "usart.h"
00049 #include <string.h>
00050
00051
00055 typedef struct bm_file_header_s {
00059 unsigned short bfType;
00061 unsigned int bfSize;
00063 unsigned int bfReserved;
00065 unsigned int bfOffBits;
00066 } __attribute__((__packed__)) bm_file_header_t ;
00067
00071 typedef struct bm_info_header_s {
00073 unsigned int biSize;
00075 int biWidth;
00082 int biHeight;
00084 unsigned short biPlanes;
00088 unsigned short biBitCount;
00095 unsigned int biCompression;
00096
00098 unsigned int biSizeImage;
00100 int biXPelsPerMeter;
00102 int biYPelsPerMeter;
00103 unsigned int biClrUsed;
00104 unsigned int biClrImportant;
00105 }__attribute__((__packed__)) bm_info_header_t;
00106
00113 void swap_endian_blk(unsigned char *pblock, int size)
00114 {
00115 unsigned char *pend = &pblock[size - 1];
00116 unsigned char temp;
00117 while(pblock < pend)
00118 {
00119 temp = *pblock;
00120 *pblock = *pend;
00121 *pend = temp;
00122 pblock++;
00123 pend--;
00124 }
00125 }
00132 void fill_virtual_frame_buffer_bm(lcdc_conf_t *lcdc_conf, bm_info_header_t *bm_info_header,unsigned char *data_start)
00133 {
00134 unsigned int k,l;
00135 unsigned char * framePtr, *bm;
00136
00137
00138 framePtr = (unsigned char *) (lcdc_conf->dmabaddr1 | 0xA0000000);
00139 bm = data_start;
00140
00141 bm = bm + bm_info_header->biBitCount * bm_info_header->biWidth * (bm_info_header->biHeight - 1) / 8;
00142 for (l = 0 ; l < bm_info_header->biHeight; l++){
00143 for (k = 0; k < bm_info_header->biWidth; k++) {
00144 framePtr++;
00145 *framePtr++ = *( bm + 0 );
00146 *framePtr++ = *( bm + 1 );
00147 *framePtr++ = *( bm + 2 );
00148 framePtr++;
00149 *framePtr++ = *( bm + 0 );
00150 *framePtr++ = *( bm + 1 );
00151 *framePtr++ = *( bm + 2 );
00152 bm += 3;
00153 }
00154 bm = bm - bm_info_header->biBitCount * bm_info_header->biWidth / 8;
00155 for (k = 0; k < bm_info_header->biWidth; k++) {
00156 framePtr++;
00157 *framePtr++ = *( bm + 0 );
00158 *framePtr++ = *( bm + 1 );
00159 *framePtr++ = *( bm + 2 );
00160 framePtr++;
00161 *framePtr++ = *( bm + 0 );
00162 *framePtr++ = *( bm + 1 );
00163 *framePtr++ = *( bm + 2 );
00164 bm += 3;
00165 }
00166 bm = bm - bm_info_header->biBitCount *2* bm_info_header->biWidth / 8;
00167 }
00168 }
00175 void fill_frame_buffer_bm(lcdc_conf_t *lcdc_conf, bm_info_header_t *bm_info_header,unsigned char *data_start)
00176 {
00177
00178 unsigned int k,l;
00179 unsigned char * framePtr, *bm;
00180 unsigned short * pframe;
00181 unsigned short red,green,blue;
00182
00183 framePtr = (unsigned char *) (lcdc_conf->dmabaddr1 | 0xA0000000);
00184 bm = data_start;
00185 if(lcdc_conf->pixelsize == BPP_24){
00186 if(bm_info_header->biHeight < 0){
00187 for (l = 0; l < bm_info_header->biHeight; l++){
00188 for (k = 0; k < bm_info_header->biWidth; k++) {
00189 *framePtr++ = *( bm + 0 );
00190 *framePtr++ = *( bm + 1 );
00191 *framePtr++ = *( bm + 2 );
00192 bm += 3;
00193 }
00194 if(bm_info_header->biWidth < lcdc_conf->xres)
00195 framePtr += (lcdc_conf->xres - bm_info_header->biWidth) * 3;
00196
00197 }
00198 }
00199 else {
00200 bm = bm + bm_info_header->biBitCount * bm_info_header->biWidth * (bm_info_header->biHeight - 1) / 8;
00201 for (l = 0 ; l < bm_info_header->biHeight; l++){
00202 for (k = 0; k < bm_info_header->biWidth; k++) {
00203 *framePtr++ = *(bm + 0);
00204 *framePtr++ = *(bm + 1);
00205 *framePtr++ = *(bm + 2);
00206 bm += 3;
00207 }
00208 bm = bm - bm_info_header->biBitCount *2* bm_info_header->biWidth / 8;
00209 if(bm_info_header->biWidth < lcdc_conf->xres)
00210 framePtr += (lcdc_conf->xres - bm_info_header->biWidth) * 3;
00211
00212 }
00213 }
00214 }
00215 if(lcdc_conf->pixelsize == BPP_16){
00216 pframe = (unsigned short *) framePtr;
00217 if(bm_info_header->biHeight > 0) {
00218
00219 bm = bm + bm_info_header->biBitCount * bm_info_header->biWidth * (bm_info_header->biHeight - 1) / 8;
00220 for (l = 0 ; l < bm_info_header->biHeight; l++){
00221 for (k = 0; k < bm_info_header->biWidth; k++) {
00222
00223 blue = *(bm + 2) >> 3;
00224 green = *(bm +1) >> 3;
00225 red = *bm >> 3;
00226 *pframe++ = ((blue << 10) & 0x7C00) | ((green << 5) & 0x03E0) | (red & 0x001F);
00227 bm += 3;
00228 }
00229 bm = bm - bm_info_header->biBitCount *2* bm_info_header->biWidth / 8;
00230 if(bm_info_header->biWidth < lcdc_conf->xres)
00231 pframe += (lcdc_conf->xres - bm_info_header->biWidth);
00232
00233 }
00234 }
00235 }
00236 }
00241 int display_virtual_bm(lcdc_conf_t *lcdc_conf, void * file_start){
00242
00243 bm_file_header_t bm_file_header;
00244 bm_info_header_t bm_info_header;
00245 unsigned char * data_start;
00246
00247
00248 memcpy(&bm_file_header, file_start, sizeof(bm_file_header_t));
00249 memcpy(&bm_info_header, file_start + 14, sizeof(bm_info_header_t));
00250
00251
00252 swap_endian_blk((unsigned char *) &bm_file_header.bfType, 2);
00253 swap_endian_blk((unsigned char *) &bm_file_header.bfSize, 4);
00254 swap_endian_blk((unsigned char *) &bm_file_header.bfOffBits, 4);
00255 swap_endian_blk((unsigned char *) &bm_info_header.biWidth, 4);
00256 swap_endian_blk((unsigned char *) &bm_info_header.biHeight, 4);
00257 swap_endian_blk((unsigned char *) &bm_info_header.biBitCount, 2);
00258 swap_endian_blk((unsigned char *) &bm_info_header.biCompression, 4);
00259
00260
00261 data_start = file_start + bm_file_header.bfOffBits;
00262 fill_virtual_frame_buffer_bm(lcdc_conf, &bm_info_header, data_start);
00263
00264 return 0;
00265 }
00270 int display_bm(lcdc_conf_t *lcdc_conf, void * file_start){
00271
00272 bm_file_header_t bm_file_header;
00273 bm_info_header_t bm_info_header;
00274 unsigned char * data_start;
00275
00276
00277 memcpy(&bm_file_header, file_start, sizeof(bm_file_header_t));
00278 memcpy(&bm_info_header, file_start + 14, sizeof(bm_info_header_t));
00279
00280
00281 swap_endian_blk((unsigned char *) &bm_file_header.bfType, 2);
00282 swap_endian_blk((unsigned char *) &bm_file_header.bfSize, 4);
00283 swap_endian_blk((unsigned char *) &bm_file_header.bfOffBits, 4);
00284 swap_endian_blk((unsigned char *) &bm_info_header.biWidth, 4);
00285 swap_endian_blk((unsigned char *) &bm_info_header.biHeight, 4);
00286 swap_endian_blk((unsigned char *) &bm_info_header.biBitCount, 2);
00287 swap_endian_blk((unsigned char *) &bm_info_header.biCompression, 4);
00288
00289
00290 data_start = file_start + bm_file_header.bfOffBits;
00291 fill_frame_buffer_bm(lcdc_conf, &bm_info_header, data_start);
00292
00293 return 0;
00294 }