From 044ad7c3987460ede48ff27afd6bdb0ca05a0432 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 4 Jul 2011 20:52:54 +0200 Subject: import at91lib from at91lib_20100901_softpack_1_9_v_1_0_svn_v15011 it's sad to see that atmel doesn't publish their svn repo or has a centralized location or even puts proper version/release info into the library itself --- .../pc-tools/CreateDemoBin/src/CreateDemoBin.cpp | 1102 ++++++++++++++++++++ .../pc-tools/CreateDemoBin/src/ScriptParse.cpp | 851 +++++++++++++++ .../demo-fw/pc-tools/CreateDemoBin/src/main.cpp | 268 +++++ 3 files changed, 2221 insertions(+) create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/src/CreateDemoBin.cpp create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/src/ScriptParse.cpp create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/src/main.cpp (limited to 'utility/demo-fw/pc-tools/CreateDemoBin/src') diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/src/CreateDemoBin.cpp b/utility/demo-fw/pc-tools/CreateDemoBin/src/CreateDemoBin.cpp new file mode 100644 index 0000000..393880b --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/src/CreateDemoBin.cpp @@ -0,0 +1,1102 @@ +#include +#include +#include +#include +#include +#include "regex.h" +#include "EasyBMP.h" +#include "ScriptParse.h" +#include "DemoBinHeader.h" +#include "CreateDemoBin.h" + +using namespace std; + +#define _GNU_SOURCE + +/////////////////////////////////////////////////////////////////////////////////////////// +//variable used +////////////////////////////////////////////////////////////////////////////////////////// + +//slide bmp file name array +static char pptSlidesBmp[MAXSLIDESPERBIN][256]; +//converted slide bmp file name array; +static char pptSlidesResizedBmp[MAXSLIDESPERBIN][256]; + +//generated PPT information txt file,default set as Sam3DEMO.txt +//will be changed based execution argument +static char pptScriptLink[256] = "Sam3DEMO.txt"; +//generated demo bin file name +//will be changed based on execution argument +static char pAtmlDemoBin[256] = "Sam3DEMO.bin"; +//temp file to link all bitmap file, used during creation,will be removed +//in the end of conversion +static char pBinContent[256] = "Sam3DEMOContent.tmp"; + +//variables for parsing script file +static char line[6*MAXSCRIPTSTRINGLINE];//[6][128]; +static unsigned int slidecnt, slidewidth, slideheight; +static unsigned int linkcnt, linktop, linkleft, linkwidth, linkheight; +static unsigned int dispboxtop, dispboxleft, dispboxwidth, dispboxheight; +static char linkaddr[MAXLINKLEN]; +static char oninitcmds[MAXLINKLEN], onrefreshcmds[MAXLINKLEN], onclosecmds[MAXLINKLEN]; + +//used to count slides parsed. +static unsigned int loop=0; +//binfile header +static DemoBINHeader binhead; +//each slide information. valid count is binhead.slidecount +static SlideINFOHeader slideinfo[MAXSLIDESPERBIN]; +//used to store parsed slides index for reading slide bmp file +static unsigned int parsedslides[MAXSLIDESPERBIN]; + +////////////////////////////////////////////////////////////////////////////////// +//Internal function +///////////////////////////////////////////////////////////////////////////////// + +//rotate BMP with clockwise angel 90 degree +static bool Rotate90(BMP &Input, BMP &Output) +{ + bool bRet = true; + int srcHeight = Input.TellHeight(); + int srcWidth = Input.TellWidth(); + + bRet &= Output.SetSize(srcHeight,srcWidth); + + for(int xpos = 0;xpos < srcWidth; xpos++) + { + for(int ypos=0;ypos=0){ + sprintf(&pptSlidesBmp[i][0],"%s\\\\speedway_loop_medium00%d.bmp",name, i+1); + } else if (i <99) { + sprintf(&pptSlidesBmp[i][0],"%s\\\\speedway_loop_medium0%d.bmp",name, i+1); + } else{ + sprintf(&pptSlidesBmp[i][0],"%s\\\\speedway_loop_medium%d.bmp",name, i+1); + } + printf("\n\r name: %s", &pptSlidesBmp[i][0]); + #endif + } + + for(int j = 0; j < MAXSLIDESPERBIN; ++j) { + sprintf(&pptSlidesResizedBmp[j][0], "%s\\\\slide%d_resized.bmp", name, j+1); + } + + sprintf(pBinContent, "%scontent.tmp", name); + sprintf(pAtmlDemoBin, "%s.bin", name); + +} + +//Process ppt information txt file +bool Step2_ProcessPPTInfoFile(BMPConvOpt *pOption) +{ + //open script file to process + FILE *pScriptfile = fopen(pptScriptLink, "rb"); + if(!pScriptfile) + { + fclose(pScriptfile); + fprintf(stderr, "\n\r Open ppt info txt file %s for creating demo bin fails!", pptScriptLink); + return false; + } + + //compile all regex pattern, if fail return + if(!CompileAllPtn()) { + fclose(pScriptfile); + FreeAllRegex(); + fprintf(stderr, "\n\r Compilation pattern fails!"); + return false; + } + + //clear all fields with 0xFF + ClearDemoBINHeader(&binhead); + for(int i=0;i MAXSLIDESPERBIN){ + //reach max slide per bin + binhead.slidecount = MAXSLIDESPERBIN; + break; + } + + parsedslides[loop]= slidecnt - 1;//record file index in the file name array + + //store temp, as index to file name array, slides index in bin file not depends on this + //parsedslides[binhead.slidecount - 1] = slidecnt;//store temp, as index to file name array + + //if rotate angle is times of 180 degree, then no need to switch width and height + #if defined(SLIDESHOW_MERGE_on) + if(pOption->ssPageNumber > 0 && loop < pOption->ssPageNumber){ + #endif + if(pOption->rotateangle % 180 == 0){ + slideinfo[binhead.slidecount - 1].slidewidth = pOption->width;//fixed for demo + slideinfo[binhead.slidecount - 1].slideheight = pOption->height;//fixed for demo + } else if(pOption->rotateangle % 90 == 0) { + //if rotate angle is times of 90 degree, but not times of 2*90 degree, + //then switch width and height + slideinfo[binhead.slidecount - 1].slidewidth = pOption->height;//fixed for demo + slideinfo[binhead.slidecount - 1].slideheight = pOption->width;//fixed for demo + } else { + fprintf(stderr, "\n Sorry, rotate angle %u not supported for coordinate conversion!", pOption->rotateangle); + fclose(pScriptfile); + FreeAllRegex(); + return false; + } + #if defined(SLIDESHOW_MERGE_on) + } + else { + if(pOption->ssRotateangle % 180 == 0){ + slideinfo[binhead.slidecount - 1].slidewidth = pOption->ssWidth;//fixed for demo + slideinfo[binhead.slidecount - 1].slideheight = pOption->ssHeight;//fixed for demo + } else if(pOption->ssRotateangle % 90 == 0) { + //if rotate angle is times of 90 degree, but not times of 2*90 degree, + //then switch width and height + slideinfo[binhead.slidecount - 1].slidewidth = pOption->ssHeight;//fixed for demo + slideinfo[binhead.slidecount - 1].slideheight = pOption->ssWidth;//fixed for demo + } else { + fprintf(stderr, "\n Sorry, rotate angle %u not supported for coordinate conversion!", pOption->ssRotateangle); + fclose(pScriptfile); + FreeAllRegex(); + return false; + } + } + #endif + + //parse each slide info field,i.e. display box, hyperlink, property config section for now + for(;;) { + //read available line in ppt information txt file + if(!GetLineNoEmpty(pScriptfile, line, MAXSCRIPTSTRINGLINE)) { + if(feof(pScriptfile)) { + //end of file + printf("\n\r OK, reach script file end!"); + fclose(pScriptfile); + FreeAllRegex(); + return true; + } + fclose(pScriptfile); + FreeAllRegex(); + fprintf(stderr, "\n\r Script file format is not right for slide info organization!"); + return false; + } + + // + //Is it slide section? + // + if(IsSlideSectionStart(line)) + break;//yes, break parsing slide info loop and goto next loop of parsing slide section + + // + //Is it slide properties section? + // + if(IsPropertiesSectionStart(line)) { + // + //Note: Ony 1 properties field in bin file, + // So only the lastest properties section content will be recorded!!! + // + + //properties section, read remained section string lines + for(int i = 1; i < 4; ++i) { + if(!GetLineNoEmpty(pScriptfile, line+i*MAXSCRIPTSTRINGLINE, MAXSCRIPTSTRINGLINE)) { + fclose(pScriptfile); + FreeAllRegex(); + fprintf(stderr, "\n\r Script file format is not right for 'Properties' section!"); + return false; + } + } + + if(!ParsePropertiesSection(line, \ + oninitcmds, \ + onrefreshcmds, \ + onclosecmds)) { + fclose(pScriptfile); + FreeAllRegex(); + fprintf(stderr, "\n\r Script file format is not righ for slide 'Properties' section!"); + return false; + } + + //setting flag to indicate having property settings for this slide + slideinfo[binhead.slidecount - 1].propyes = 1; + slideinfo[binhead.slidecount - 1].propinfo.propcnt = 3; + strcpy(slideinfo[binhead.slidecount - 1].propinfo.onInitCmds, oninitcmds); + strcpy(slideinfo[binhead.slidecount - 1].propinfo.onRefreshCmds, onrefreshcmds); + strcpy(slideinfo[binhead.slidecount - 1].propinfo.onCloseCmds, onclosecmds); + + continue; + } + + // + //Is it Display box section? + // + if(IsDispBoxSectionStart(line)) { + //display box section, read remained section string lines + for(int i = 1; i < 5; ++i) { + if(!GetLineNoEmpty(pScriptfile, line+i*MAXSCRIPTSTRINGLINE, MAXSCRIPTSTRINGLINE)) { + fclose(pScriptfile); + FreeAllRegex(); + fprintf(stderr, "\n\r Script file format is not right for 'DisplayBox' section!"); + return false; + } + } + + //parse display box section + if(!ParseDispBoxSection(line, \ + &dispboxtop, &dispboxleft, &dispboxwidth, &dispboxheight)) { + fclose(pScriptfile); + FreeAllRegex(); + fprintf(stderr, "\n\r Script file format is not right for 'DisplayBox' section!"); + return false; + } + + //have display box in slide + ++slideinfo[binhead.slidecount - 1].dispboxcount; + if(slideinfo[binhead.slidecount - 1].dispboxcount > MAX_DISPBOX_PER_SLIDE) { + //reach max display box for a slide + slideinfo[binhead.slidecount - 1].dispboxcount = MAX_DISPBOX_PER_SLIDE; + continue; + } + + //resized ratio + double width_ratio; + double height_ratio; + unsigned int conv_bottom, conv_left, conv_width, conv_height; + #if defined(SLIDESHOW_MERGE_on) + if(pOption->ssPageNumber > 0 && loop < pOption->ssPageNumber){ + #endif + width_ratio = pOption->width / (double)slidewidth; + height_ratio = pOption->height / (double)slideheight; + + #if defined(SLIDESHOW_MERGE_on) + } + else{ + width_ratio = pOption->ssWidth / (double)slidewidth; + height_ratio = pOption->ssHeight / (double)slideheight; + } + #endif + + unsigned int tmpRet; + #if defined(SLIDESHOW_MERGE_on) + if(pOption->ssPageNumber > 0 && loop < pOption->ssPageNumber){ + #endif + tmpRet = HotZoneCoordinateConversion( + dispboxtop, + dispboxleft, + dispboxwidth, + dispboxheight, + pOption->width, + pOption->height, + width_ratio, + height_ratio, + pOption->rotateangle, + &conv_bottom, + &conv_left, + &conv_width, + &conv_height); + #if defined(SLIDESHOW_MERGE_on) + } + else{ + tmpRet = HotZoneCoordinateConversion( + dispboxtop, + dispboxleft, + dispboxwidth, + dispboxheight, + pOption->ssWidth, + pOption->ssHeight, + width_ratio, + height_ratio, + pOption->ssRotateangle, + &conv_bottom, + &conv_left, + &conv_width, + &conv_height); + } + #endif + if(!tmpRet) + { + fclose(pScriptfile); + FreeAllRegex(); + fprintf(stderr, "\n Script file format is not right!"); + return false; + } + unsigned int slideindex = binhead.slidecount - 1; + unsigned int dispboxindex = slideinfo[binhead.slidecount-1].dispboxcount - 1; + slideinfo[slideindex].dispboxinfo[dispboxindex].dispboxbottom = conv_bottom; + slideinfo[slideindex].dispboxinfo[dispboxindex].dispboxleft = conv_left; + slideinfo[slideindex].dispboxinfo[dispboxindex].dispboxwidth = conv_width; + slideinfo[slideindex].dispboxinfo[dispboxindex].dispboxheight = conv_height; + + continue; + } + + // + //Is it hyperlink section? + // + if(IsLinkSectionStart(line)) { + + //hyperlink section, read remained section string lines + for(int i = 1; i < 6; ++i) { + if(!GetLineNoEmpty(pScriptfile, line+i*MAXSCRIPTSTRINGLINE, MAXSCRIPTSTRINGLINE)) { + fclose(pScriptfile); + FreeAllRegex(); + fprintf(stderr, "\n\r Script file format is not right!"); + return false; + } + } + + //parse hyperlink section + if(!ParseLinkSection(line, &linkcnt, linkaddr, \ + &linktop, &linkleft, &linkwidth, &linkheight)) { + fclose(pScriptfile); + FreeAllRegex(); + fprintf(stderr, "\n\r Script file format is not right!"); + return false; + } + + //parsed linkcnt is not used, considering if some links were removed by manual + ++(slideinfo[binhead.slidecount - 1].linkcount); + if(slideinfo[binhead.slidecount - 1].linkcount > MAX_LINK_PER_SLIDE) { + //reach max link limit for a slide + slideinfo[binhead.slidecount - 1].linkcount = MAX_LINK_PER_SLIDE; + continue; + } + + //resize ratio + double width_ratio; + double height_ratio; + unsigned int conv_bottom, conv_left, conv_width, conv_height; + #if defined(SLIDESHOW_MERGE_on) + if(pOption->ssPageNumber > 0 && loop < pOption->ssPageNumber){ + #endif + width_ratio = pOption->width / (double)slidewidth; + height_ratio = pOption->height / (double)slideheight; + #if defined(SLIDESHOW_MERGE_on) + } + else{ + width_ratio = pOption->ssWidth / (double)slidewidth; + height_ratio = pOption->ssHeight / (double)slideheight; + } + #endif + //printf("\n linktop %u, linkleft %u, linkwidth %u, linkheight %u",\ + // linktop, linkleft, linkwidth, linkheight); + unsigned int tmpRet; + #if defined(SLIDESHOW_MERGE_on) + if(pOption->ssPageNumber > 0 && loop < pOption->ssPageNumber){ + #endif + tmpRet = HotZoneCoordinateConversion( + //original link zone params, gotten from slide info txt file + linktop, + linkleft, + linkwidth, + linkheight, + //resized slide width and height + pOption->width, + pOption->height, + //resize ratio of width and height + width_ratio, + height_ratio, + //clockwise rotate angle + pOption->rotateangle, + //pointer of output link zone param + &conv_bottom, + &conv_left, + &conv_width, + &conv_height); + #if defined(SLIDESHOW_MERGE_on) + } + else{ + tmpRet = HotZoneCoordinateConversion( + //original link zone params, gotten from slide info txt file + linktop, + linkleft, + linkwidth, + linkheight, + //resized slide width and height + pOption->ssWidth, + pOption->ssHeight, + //resize ratio of width and height + width_ratio, + height_ratio, + //clockwise rotate angle + pOption->ssRotateangle, + //pointer of output link zone param + &conv_bottom, + &conv_left, + &conv_width, + &conv_height); + } + #endif + if(!tmpRet) + { + //link hot zone coordinate conversion fail, then return false + fclose(pScriptfile); + FreeAllRegex(); + fprintf(stderr, "\n Link zone coordinate conversion fail!"); + return false; + } + + //set the slideinfo link value, noted bmp was rotated and resized. + unsigned int linkindex = slideinfo[binhead.slidecount-1].linkcount - 1; + unsigned int slideindex = binhead.slidecount - 1; + slideinfo[slideindex].linkinfo[linkindex].linkboxbottom = conv_bottom; + slideinfo[slideindex].linkinfo[linkindex].linkboxleft = conv_left; + slideinfo[slideindex].linkinfo[linkindex].linkboxwidth = conv_width; + slideinfo[slideindex].linkinfo[linkindex].linkboxheight = conv_height; + +#ifdef DEBUG_LINKSECTION + printf("\n\r [slide %d, link box %d is %u, %u, %u, %u,addr %s]", slideindex, linkindex,\ + slideinfo[slideindex].linkinfo[linkindex].linkboxbottom,\ + slideinfo[slideindex].linkinfo[linkindex].linkboxleft,\ + slideinfo[slideindex].linkinfo[linkindex].linkboxwidth,\ + slideinfo[slideindex].linkinfo[linkindex].linkboxheight, \ + linkaddr); +#endif + + strcpy(slideinfo[slideindex].linkinfo[linkindex].linkstring, linkaddr); + + continue; + } + + //not slide section, not hyperlink section, not display box section, then err + fclose(pScriptfile); + FreeAllRegex(); + fprintf(stderr, "\n\r Script file format is not right!"); + return false; + + } + } + + return true; +} + + +//Resize and Rotate slides +bool Step3_ResizeAndRotateSlideBMP(BMPConvOpt *pOption) +{ + bool bRet=true; + BMP pptBMP; + + SetEasyBMPwarningsOff();//set warning message on + + //set pic width and height + ScaleParam scale; + + //picture number + #if defined(MOVIE_MERGE_on) + binhead.slidecount = pOption->mvSlideNumber; + #endif + int picNum = binhead.slidecount; //sizeof(pptSlidesBmp)/sizeof(char*); + //printf("\n\r has %d slides", picNum); + + //resize all picture + int i; + for(i=0; issPageNumber > 0 && i < pOption->ssPageNumber){ + #endif + scale.dimension.width = pOption->width; + scale.dimension.height = pOption->height; + #if defined(SLIDESHOW_MERGE_on) + } + else{ + scale.dimension.width = pOption->ssWidth; + scale.dimension.height = pOption->ssHeight; + } + #endif + //printf("\n\r process %s before create object",pptSlidesBmp[i]); + if(!pptBMP.ReadFromFile(pptSlidesBmp[i])) { + fprintf(stderr, "Fail to open slide bit map file for operation!"); + return false; + } + //printf("\n\r process %s before rescale",pptSlidesBmp[i]); + bRet &= Rescale(pptBMP, 'd', scale); + //printf("\n\r process %s before setbitdepth",pptSlidesBmp[i]); + #if defined(SLIDESHOW_MERGE_on) + if(pOption->ssPageNumber > 0 && i < pOption->ssPageNumber){ + #endif + bRet &= pptBMP.SetBitDepth(pOption->bitdepth); + #if defined(SLIDESHOW_MERGE_on) + } + else{ + bRet &= pptBMP.SetBitDepth(pOption->ssBitdepth); + } + #endif + + //printf("\n\r process %s before writefile",pptSlidesBmp[i]); + if(!pptBMP.WriteToFile(pptSlidesResizedBmp[i])) { + fprintf(stderr, "Fail to open file to write converted bitmap file!"); + return false; + } + + //Rotate BMP + + + + #if defined(SLIDESHOW_MERGE_on) + if(pOption->ssPageNumber > 0 && i < pOption->ssPageNumber){ + #endif + bRet &= Rotate(pptSlidesResizedBmp[i], pptSlidesResizedBmp[i], pOption->rotateangle); + #if defined(SLIDESHOW_MERGE_on) + } + else{ + bRet &= Rotate(pptSlidesResizedBmp[i], pptSlidesResizedBmp[i], pOption->ssRotateangle); + } + #endif +#ifdef DEBUG_CONVBMPINFO + FILE *pBmpFile; + pBmpFile = fopen(pptSlidesResizedBmp[i], "rb"); + if(!pBmpFile) { + fprintf(stderr, "\n\r fail to open"); + exit(3); + } + BMPHeader bmpHead; + fread((char*)&bmpHead, 1, sizeof(BMPHeader), pBmpFile); + fclose(pBmpFile); + + printf("\n\r============bmp header=============="); + printf("\n\r bmp.type is %x", bmpHead.type); + printf("\n\r bmp.filesize is %d", bmpHead.fileSize); + printf("\n\r bmp.width is %d", bmpHead.width); + printf("\n\r bmp.height is %d", bmpHead.height); + printf("\n\r bmp.compressed is %d", bmpHead.compression); + printf("\n\r bmp.bitdepth is %d", bmpHead.bits); + +#endif + + } + + return bRet; +} + +//create demo bin from above variables +bool Step4_GenerateDemoBin(BMPConvOpt *pOption) +{ + FILE *pBMPfile, *pBinContentfile, *pDemoBin; + unsigned int offset; + unsigned int slideoffset[MAXSLIDESPERBIN];//store each slide offset in temp file + char buf[1024];//as read/write file buffer + + //bin file tag 'ATML' + binhead.tag = (unsigned int)'L'<<24 | (unsigned int)'M'<<16 | + (unsigned int)'T'<<8 | (unsigned int) 'A'; + + //first open bincontentfile to store all parsed slide bmp file + pBinContentfile = fopen(pBinContent, "wb"); + if(!pBinContentfile) { + fclose(pBinContentfile); + fprintf(stderr, "\n Open file fail during creating bin!"); + return false; + } + + slideoffset[0] = 0; offset = 0; + //write all parsed slide bmp files into a bincontentfile + for(unsigned int i = 0; i sizeof(pptSlidesResizedBmp)/ sizeof(char *)) { + fclose(pBinContentfile); + fprintf(stderr, "\n slide %u,i %u",parsedslides[i], i); + fprintf(stderr, "\n Script file and bmp file count is not consistent!"); + return false; + } + + #if !defined(MOVIE_MERGE_on) + pBMPfile = fopen(pptSlidesResizedBmp[parsedslides[i]], "rb"); + #else + pBMPfile = fopen(pptSlidesResizedBmp[i], "rb"); + #endif + if(!pBMPfile) { + fclose(pBinContentfile); + fclose(pBMPfile); + fprintf(stderr, "\n Open bmp file fail!"); + return false; + } + + //convert bmp file bitmap data format to meet sam3 lcd coordinate + if(pOption->reversebitmaporder){ + + struct stat filestat; + ////////////////////////// + unsigned int width = 0; + unsigned int height = 0; + + #if defined(SLIDESHOW_MERGE_on) + if(pOption->ssPageNumber > 0 && i < pOption->ssPageNumber){ + #endif + width = pOption->width; + height = pOption->height; + #if defined(SLIDESHOW_MERGE_on) + } + else{ + width = pOption->ssWidth; + height = pOption->ssHeight; + } + #endif + //default 270 rotate make the bmp look like column-aligned store + if(pOption->rotateangle % 180 == 0) + { + width = pOption->height; + height = pOption->width; + } + #if defined(SLIDESHOW_MERGE_on) + if(pOption->ssPageNumber > 0 && i < pOption->ssPageNumber){ + #endif + if(pOption->rotateangle % 180 == 0) + { + width = pOption->height; + height = pOption->width; + } + #if defined(SLIDESHOW_MERGE_on) + } + else{ + if(pOption->ssRotateangle % 180 == 0) + { + width = pOption->ssHeight; + height = pOption->ssWidth; + } + } + #endif + ////////////////////////// + fstat(fileno(pBMPfile), &filestat); + + //printf("\n\r filesize is %u", filestat.st_size); + char *bmpfilebuf = (char *)malloc(filestat.st_size+1024); + char *convbmpbuf = (char *)malloc(filestat.st_size+1024); + + if(!bmpfilebuf || !convbmpbuf) { + fclose(pBMPfile); + fclose(pBinContentfile); + fprintf(stderr, "\n malloc space for bmp file fail!"); + return false; + } + + size_t numread = fread(bmpfilebuf, 1, filestat.st_size, pBMPfile); + if(numread != filestat.st_size) { + fclose(pBMPfile); + fclose(pBinContentfile); + fprintf(stderr, "\n Read bmp file length is not right!"); + return false; + } + unsigned int bitmapoffset = ((BMPHeader *)bmpfilebuf)->offset; + + unsigned int byteperpixel = ((BMPHeader *)bmpfilebuf)->bits; + if(byteperpixel != 8 && byteperpixel != 16 && byteperpixel !=24 ) { + fclose(pBMPfile); + fclose(pBinContentfile); + fprintf(stderr, "\n Conversion of bitmap order of bit depth %u is not supported yet!", byteperpixel); + return false; + } + byteperpixel /= 8; + + memcpy(convbmpbuf, bmpfilebuf, bitmapoffset); + + //printf("\n\r Begin to convert %ubit bitmap data to meet sam3 lcd format!",byteperpixel*8); + //convert orignal bitmap data to sam3-ek LCD api coordinate format + unsigned int j,k,s; + for (j = 0, s=0; j < width; ++j) { + + for (k = 0; k < height && j*k*byteperpixel < filestat.st_size; k++) { + + *(convbmpbuf+bitmapoffset+s) = bmpfilebuf[ bitmapoffset + \ + ((width -j - 1)*height + k)*byteperpixel]; + if(byteperpixel == 2) { + *(convbmpbuf+bitmapoffset+s+1) = bmpfilebuf[ bitmapoffset + \ + ((width -j - 1)*height + k)*byteperpixel+1]; + } + if(byteperpixel == 3) { + *(convbmpbuf+bitmapoffset+s+2) = bmpfilebuf[ bitmapoffset + \ + ((width -j - 1)*height + k)*byteperpixel+2]; + } + s += byteperpixel; + } + //printf("\n\r j is %d",j); + } + + //printf("\n\r End to convert %ubit bitmap data!",byteperpixel*8); + + //check if right long data conversion + if(j != width || k != height) { + fclose(pBMPfile); + fclose(pBinContentfile); + fprintf(stderr, "\n\r not all expected bitmap data converted!"); + return false; + } + + fwrite(convbmpbuf, 1, filestat.st_size, pBinContentfile); + offset += filestat.st_size; + + free(convbmpbuf); + free(bmpfilebuf); + } else { + //directly write all bmp file into the tmp bincontent file + while(!feof(pBMPfile)) { + size_t numread = fread(buf, 1, 1024, pBMPfile); + fwrite(buf, 1, numread, pBinContentfile); + offset += numread; + } + } + + //store this slide bmp file size + slideinfo[i].slidedatalength = offset - startoffset; + //printf("\n\r slide size is %u", slideinfo[i].slidedatalength); + + //store offset for next slides + slideoffset[i+1]= offset; + //printf("\n\r offset is %d", offset); + fclose(pBMPfile); + +#ifdef DEBUG_DISPSECTION + printf("\n --Slide %u has %u display box", i+1, slideinfo[i].dispboxcount); + unsigned s; + for(s = 0; s < slideinfo[i].dispboxcount; ++s) { + printf("\n slide count is %d, botm %d, left %d, width %d, height %d",\ + i+1, slideinfo[i].dispboxinfo[s].dispboxbottom, \ + slideinfo[i].dispboxinfo[s].dispboxleft, \ + slideinfo[i].dispboxinfo[s].dispboxwidth, \ + slideinfo[i].dispboxinfo[s].dispboxheight); + } +#endif + + } + fclose(pBinContentfile); + + //get header size + unsigned int headersize = sizeof(DemoBINHeader) + sizeof(SlideINFOHeader)* binhead.slidecount; + + //set headersize field of DemoBINHeader + binhead.headersize = headersize; + //printf("\n\r headersize is %d", headersize); + + //set file size field of DemoBINHeader + binhead.filesize = headersize + offset;//offset should be bincontent filesize now + + //correct slide offset and then set them info information struct + for(unsigned int i = 0; i < binhead.slidecount; ++i) { + slideinfo[i].slideoffset = slideoffset[i] + headersize; +} + + pDemoBin = fopen(pAtmlDemoBin, "wb"); + if(!pDemoBin) { + fclose(pDemoBin); + fprintf(stderr, "\n\r Open file fail during creating bin!"); + return false; + } + + #if !defined(MOVIE_MERGE_on) + fwrite(&binhead, 1, sizeof(DemoBINHeader), pDemoBin); + for(unsigned int i = 0; i < binhead.slidecount; ++i) { + fwrite(&slideinfo[i], 1, sizeof(SlideINFOHeader), pDemoBin); + } + #else + unsigned int tmpSlideCount = binhead.slidecount; + fwrite(&tmpSlideCount, 1, sizeof(unsigned int), pDemoBin); + #endif + + //open pBinContentfile in read mode for writing final demo bin + pBinContentfile = fopen(pBinContent, "rb"); + if(!pBinContentfile) { + fclose(pBinContentfile); + fprintf(stderr, "\n\r Open file fail during creating bin!"); + return false; + } + + //write the slide bin file to final demo bin + while(!feof(pBinContentfile)) { + size_t numread = fread(buf, 1, 1024, pBinContentfile); + fwrite(buf, 1, numread, pDemoBin); + } + + fclose(pBinContentfile); + fclose(pDemoBin); + + //remove temporary bincontentfile + if(remove(pBinContent)) + fprintf(stderr, "\n\r Can't remove temporary file!"); + + return true; +} + +//show generated bin contained bmp information +void ShowEachBmpHeader() +{ + FILE *pBinfile; + DemoBINHeader binheader; + SlideINFOHeader slideinfo; + BMPHeader bmphead; + + pBinfile = fopen(pAtmlDemoBin, "rb"); + if(!pBinfile) { + fprintf(stderr, "\n\r Fail to open demo bin file!!"); + return; + } + + fread(&binheader, 1, sizeof(DemoBINHeader),pBinfile); + unsigned int slidecount = binheader.slidecount; + printf("\n\r Demo bin has %u slides", slidecount); + + for(unsigned int j=0; j < slidecount;++j) { + fseek(pBinfile, sizeof(DemoBINHeader) + j *sizeof(SlideINFOHeader), SEEK_SET); + fread(&slideinfo, 1, sizeof(SlideINFOHeader), pBinfile); + printf("\n\r slide %d bitdata in %u,length %u",j, slideinfo.slideoffset, slideinfo.slidedatalength); + fseek(pBinfile, slideinfo.slideoffset, SEEK_SET); + fread(&bmphead, 1, sizeof(BMPHeader), pBinfile); + printf("\n\r============bmp header=============="); + printf("\n\r bmp.type is %x", bmphead.type); + printf("\n\r bmp.filesize is %d", bmphead.fileSize); + printf("\n\r bmp.width is %d", bmphead.width); + printf("\n\r bmp.height is %d", bmphead.height); + printf("\n\r bmp.compressed is %d", bmphead.compression); + printf("\n\r bmp.bitdepth is %d", bmphead.bits); + + } + + fclose(pBinfile); +} + diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/src/ScriptParse.cpp b/utility/demo-fw/pc-tools/CreateDemoBin/src/ScriptParse.cpp new file mode 100644 index 0000000..ad0c73b --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/src/ScriptParse.cpp @@ -0,0 +1,851 @@ +/* + * ScriptParse.cpp + * + * Created on: 2009-3-15 + * Author: Tony.Liu + */ +#include +#include +#include +#include +#include "regex.h" +#include "ScriptParse.h" +#include "DemoBinHeader.h" + +#define SUBSLEN 10 +#define EBUFLEN 128 /* error buffer length */ +#define BUFLEN 1024 /* matched buffer length */ + +using namespace std; + +static size_t len; +static regex_t reSpace; +static regex_t reSlideCnt; +static regex_t reSlideSize; +static regex_t reSlideWidth; +static regex_t reSlideHeight; + +static regex_t reSlideDispString; +static regex_t reSlideDispTop; +static regex_t reSlideDispLeft; +static regex_t reSlideDispWidth; +static regex_t reSlideDispHeight; + +static regex_t reSlideLink; +static regex_t reSlideLinkAddr; +static regex_t reSlideLinkTop; +static regex_t reSlideLinkLeft; +static regex_t reSlideLinkWidth; +static regex_t reSlideLinkHeight; + +static regex_t reSlideProps; +static regex_t reSlideOnInitCmds; +static regex_t reSlideOnRefreshCmds; +static regex_t reSlideOnCloseCmds; + +static regmatch_t subs[SUBSLEN]; +static char matched[BUFLEN]; +static char errbuf[EBUFLEN]; + +static char *pSpacePtn = "^[[:space:]]+$"; +static char *pSlideCntPtn = "^Slide[[:blank:]]+([[:digit:]]+):[[:space:]]+$"; +static char *pSlideSizePtn = "^Slide Size:[[:space:]]+$"; +static char *pSlideWidthPtn = "^Width:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$"; +static char *pSlideHeightPtn = "^Height:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$"; + +static char *pSlideDispBoxStringPtn = "^Display Box:[[:space:]]+$"; +static char *pSlideDispBoxTopPtn = "^Top:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$"; +static char *pSlideDispBoxLeftPtn = "^Left:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$"; +static char *pSlideDispBoxWidthPtn = "^Width:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$"; +static char *pSlideDispBoxHeightPtn = "^Height:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$"; + +static char *pSlideLinkPtn = "^HyperLink[[:blank:]]+([[:digit:]]+)::[[:space:]]+$"; +static char *pSlideLinkAddrPtn = "^\"Link Address\":[[:blank:]]+[[:cntrl:]]*(.*)[[:space:]]+[[:cntrl:]]+$"; +static char *pSlideLinkTopPtn = "^Top:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$"; +static char *pSlideLinkLeftPtn = "^Left:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$"; +static char *pSlideLinkWidthPtn = "^Width:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$"; +static char *pSlideLinkHeightPtn = "^Height:[[:blank:]]+([[:digit:]]+([.][[:digit:]]+)?)[[:space:]]+$"; + +static char *pSlidePropsPtn = "^Properties::[[:space:]]+$"; +static char *pSlideOnInitCmdsPtn = "^OnInitCmds:[[:blank:]]*[[:cntrl:]]*(.*)[[:space:]]+[[:cntrl:]]+$"; +static char *pSlideOnRefreshCmdsPtn = "^OnRefreshCmds:[[:blank:]]*[[:cntrl:]]*(.*)[[:space:]]+[[:cntrl:]]+$"; +static char *pSlideOnCloseCmdsPtn = "^OnCloseCmds:[[:blank:]]*[[:cntrl:]]*(.*)[[:space:]]+[[:cntrl:]]+$"; + +//compile pattern +static bool CompileRegexPtn(regex_t *compiled, const char *pattern, int cflags) +{ + int err = regcomp (compiled, pattern, cflags); + if (err) + { + len = regerror (err, compiled, errbuf, sizeof (errbuf)); + //printf("\n\r error compilation!"); + fprintf (stderr, "error: regcomp: %s\n", errbuf); + return false; + } + + return true; +} + +//compile all pattern +bool CompileAllPtn() +{ + bool bRet=true; + + //compile slide section head pattern + bRet &= CompileRegexPtn(&reSpace, pSpacePtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideCnt, pSlideCntPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideSize, pSlideSizePtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideWidth, pSlideWidthPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideHeight, pSlideHeightPtn, REG_EXTENDED | REG_NEWLINE); + + //compile display box section pattern + bRet &= CompileRegexPtn(&reSlideDispString, pSlideDispBoxStringPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideDispTop, pSlideDispBoxTopPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideDispLeft, pSlideDispBoxLeftPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideDispWidth, pSlideDispBoxWidthPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideDispHeight, pSlideDispBoxHeightPtn, REG_EXTENDED | REG_NEWLINE); + + //compile hyperlink section pattern + bRet &= CompileRegexPtn(&reSlideLink, pSlideLinkPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideLinkAddr, pSlideLinkAddrPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideLinkTop, pSlideLinkTopPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideLinkLeft, pSlideLinkLeftPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideLinkWidth, pSlideLinkWidthPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideLinkHeight, pSlideLinkHeightPtn, REG_EXTENDED | REG_NEWLINE); + + //compile slide config section pattern + bRet &= CompileRegexPtn(&reSlideProps, pSlidePropsPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideOnInitCmds, pSlideOnInitCmdsPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideOnRefreshCmds, pSlideOnRefreshCmdsPtn, REG_EXTENDED | REG_NEWLINE); + bRet &= CompileRegexPtn(&reSlideOnCloseCmds, pSlideOnCloseCmdsPtn, REG_EXTENDED | REG_NEWLINE); + + return bRet; +} + +//free compiled regex pattern +void FreeAllRegex() +{ + //free slide section head patterns + regfree(&reSlideCnt); + regfree(&reSlideSize); + regfree(&reSlideWidth); + regfree(&reSlideHeight); + + //free slide display box section patterns + regfree(&reSlideDispString); + regfree(&reSlideDispTop); + regfree(&reSlideDispLeft); + regfree(&reSlideDispWidth); + regfree(&reSlideDispHeight); + + //free slide hyperlink section patterns + regfree(&reSlideLink); + regfree(&reSlideLinkAddr); + regfree(&reSlideLinkTop); + regfree(&reSlideLinkLeft); + regfree(&reSlideWidth); + regfree(&reSlideHeight); + + //free slide config section pattern + regfree(&reSlideProps); + regfree(&reSlideOnInitCmds); + regfree(&reSlideOnRefreshCmds); + regfree(&reSlideOnCloseCmds);; +} + +//match the pattern? +bool RegexMatch(const regex_t *compiled, const char *string, size_t nmatch, regmatch_t *matchptr, int eflags) +{ + bool bRet = true; + + int err = regexec (compiled, string, (size_t)nmatch, matchptr,eflags); + + if (err == REG_NOMATCH) + { + //fprintf (stderr, "Sorry, no match ...\n"); + bRet = false; + } + else if (err) + { + len = regerror (err, compiled, errbuf, sizeof (errbuf)); + fprintf (stderr, "error: regexec: %s\n", errbuf); + bRet = false; + } + + return bRet; +} + +//is a space line? +bool IsSpaceLine(const char *string) +{ + bool bRet = RegexMatch(&reSpace, string, 0,0,0); + + return bRet; +} + +//match slide count line and return the count +bool GetSlideCount( const char *string, unsigned int *slidenum) +{ + bool bRet = false; + +#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_SLIDESECTION) + printf("\n\r [Parsing slide count string is %s", string); +#endif + + bRet = RegexMatch(&reSlideCnt,string, (size_t)SUBSLEN, subs, 0); + //not match pattern + if(!bRet) { + fprintf(stderr, "\n\rNot slide count line...!"); + return bRet; + } + +// printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so); + int len = subs[1].rm_eo - subs[1].rm_so; + memcpy (matched, string + subs[1].rm_so, len); + matched[len] = '\0'; + +#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_SLIDESECTION) + printf("\n\r Parsed slide count is %s]",matched); +#endif + + *slidenum = (unsigned int)floor(atof(matched)); + + return bRet; +} + +//check slide size line is correct +bool IsSlideSizeString(const char *string) +{ + bool bRet = false; + + bRet = RegexMatch(&reSlideSize,string, (size_t)SUBSLEN, subs, 0); + //not match pattern + if(!bRet) { + fprintf(stderr, "\n\rNot slide size string line...!"); + return bRet; + } + + return bRet; +} + +//match slide width line and return the width +bool GetSlideWidth( const char *string, unsigned int *slidewidth) +{ + bool bRet = false; + +#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_SLIDESECTION) + printf("\n\r [Parsing slide width string is %s", string); +#endif + + bRet = RegexMatch(&reSlideWidth,string, (size_t)SUBSLEN, subs, 0); + //not match pattern + if(!bRet) { + fprintf(stderr, "\n\rNot slide width line...!"); + return bRet; + } + +// printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so); + int len = subs[1].rm_eo - subs[1].rm_so; + memcpy (matched, string + subs[1].rm_so, len); + matched[len] = '\0'; + +#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_SLIDESECTION) + printf("\n\r Parsed slide width is %s]",matched); +#endif + + *slidewidth = (unsigned int)floor(atof(matched)); + + return bRet; +} + +//match slide height line and return the height +bool GetSlideHeight( const char *string, unsigned int *slideheight) +{ + bool bRet = false; + +#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_SLIDESECTION) + printf("\n\r [Parsing slide height string is %s", string); +#endif + + bRet = RegexMatch(&reSlideHeight,string, (size_t)SUBSLEN, subs, 0); + //not match pattern + if(!bRet) { + fprintf(stderr, "\n\rNot slide height line...!"); + return bRet; + } + +// printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so); + int len = subs[1].rm_eo - subs[1].rm_so; + memcpy (matched, string + subs[1].rm_so, len); + matched[len] = '\0'; + +#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_SLIDESECTION) + printf("\n\r Parsed slide height is %s]",matched); +#endif + + *slideheight = (unsigned int)floor(atof(matched)); + + return bRet; +} + +//match link top line and return link top position +bool GetDispBoxTop(const char *string, unsigned int *top) +{ + bool bRet = false; + +#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_DISPBOXSECTION) + printf("\n\r [Parsing display box top string is %s", string); +#endif + + bRet = RegexMatch(&reSlideDispTop, string, (size_t)SUBSLEN, subs, 0); + //not match pattern + if(!bRet) { + fprintf(stderr, "\n\rNot link top line...!"); + return bRet; + } + +// printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so); + int len = subs[1].rm_eo - subs[1].rm_so; + memcpy (matched, string + subs[1].rm_so, len); + matched[len] = '\0'; + +#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_DISPBOXSECTION) + printf("\n\r Parsed display box top is %s]",matched); +#endif + + *top = (unsigned int)floor(atof(matched)); + + return bRet; +} + +//match link left line and return link left position +bool GetDispBoxLeft(const char *string, unsigned int *left) +{ + bool bRet = false; + +#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_DISPBOXSECTION) + printf("\n\r [Parsing display box left string is %s", string); +#endif + + bRet = RegexMatch(&reSlideDispLeft, string, (size_t)SUBSLEN, subs, 0); + //not match pattern + if(!bRet) { + fprintf(stderr, "\n\rNot link left line...!"); + return bRet; + } + +// printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so); + int len = subs[1].rm_eo - subs[1].rm_so; + memcpy (matched, string + subs[1].rm_so, len); + matched[len] = '\0'; + +#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_DISPBOXSECTION) + printf("\n\r Parsed display box left is %s]",matched); +#endif + + *left = (unsigned int)floor(atof(matched)); + + return bRet; +} + +//match link width line and return width value +bool GetDispBoxWidth(const char *string, unsigned int *width) +{ + bool bRet = false; + +#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_DISPBOXSECTION) + printf("\n\r [Parsing display box width string is %s", string); +#endif + + bRet = RegexMatch(&reSlideDispWidth, string, (size_t)SUBSLEN, subs, 0); + //not match pattern + if(!bRet) { + fprintf(stderr, "\n\rNot link width line...!"); + return bRet; + } + +// printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so); + int len = subs[1].rm_eo - subs[1].rm_so; + memcpy (matched, string + subs[1].rm_so, len); + matched[len] = '\0'; + +#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_DISPBOXSECTION) + printf("\n\r Parsed display box width is %s]",matched); +#endif + + *width = (unsigned int)floor(atof(matched)); + + return bRet; +} + +//match link width line and return width value +bool GetDispBoxHeight(const char *string, unsigned int *height) +{ + bool bRet = false; + +#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_DISPBOXSECTION) + printf("\n\r [Parsing display box height string is %s", string); +#endif + + bRet = RegexMatch(&reSlideDispHeight, string, (size_t)SUBSLEN, subs, 0); + //not match pattern + if(!bRet) { + fprintf(stderr, "\n\rNot link height line...!"); + return bRet; + } + +// printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so); + int len = subs[1].rm_eo - subs[1].rm_so; + memcpy (matched, string + subs[1].rm_so, len); + matched[len] = '\0'; + +#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_DISPBOXSECTION) + printf("\n\r Parsed display box height is %s]",matched); +#endif + + *height = (unsigned int)floor(atof(matched)); + + return bRet; +} + +//match hyperlink line and return link count +bool GetLinkCount(const char *string, unsigned int *linkcnt) +{ + bool bRet = false; + +#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_LINKSECTION) + printf("\n\r [Parsing link count string is %s", string); +#endif + + bRet = RegexMatch(&reSlideLink, string, (size_t)SUBSLEN, subs, 0); + //not match pattern + if(!bRet) { + fprintf(stderr, "\n\rNot hyperlink line...!"); + return bRet; + } + +// printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so); + int len = subs[1].rm_eo - subs[1].rm_so; + memcpy (matched, string + subs[1].rm_so, len); + matched[len] = '\0'; + +#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_LINKSECTION) + printf("\n\r Parsed link count is %s]",matched); +#endif + + *linkcnt = (unsigned int)floor(atof(matched)); + + return bRet; +} + +//match link address line and return the address +bool GetLinkAddr(const char *string, char *link) +{ + bool bRet = false; + +#if defined(DEBUG_BEFOREPARSE) && defined(DEBUG_LINKSECTION) + printf("\n\r [Parsing link address string is %s", string); +#endif + + bRet = RegexMatch(&reSlideLinkAddr, string, (size_t)SUBSLEN, subs, 0); + //not match pattern + if(!bRet) { + fprintf(stderr, "\n\rNot link address line...!"); + return bRet; + } + + //printf("\n\r %d, %d",subs[1].rm_eo, subs[1].rm_so); + int len = subs[1].rm_eo - subs[1].rm_so; + + if(len > MAXLINKLEN - 1) { + fprintf(stderr, "\n\r link address is too long!"); + return false; + } + + memcpy (link, string + subs[1].rm_so, len); + link[len] = '\0'; + +#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_LINKSECTION) + printf("\n\r"); + for(int j=0;j MAXLINKLEN - 1) { + fprintf(stderr, "\n\r OnInitCmds line is too long!"); + return false; + } + + memcpy (pOnInitCmds, string + subs[1].rm_so, len); + pOnInitCmds[len] = '\0'; + +#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_PROPSECTION) + printf("\n\r Hex code of parsed: "); + for(int j=0;j MAXLINKLEN - 1) { + fprintf(stderr, "\n\r OnRefreshCmds is too long!"); + return false; + } + + memcpy (pOnRefreshCmds, string + subs[1].rm_so, len); + pOnRefreshCmds[len] = '\0'; + +#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_PROPSECTION) + printf("\n\r Hex code of parsed: "); + for(int j=0;j MAXLINKLEN - 1) { + fprintf(stderr, "\n\r OnCloseCmds is too long!"); + return false; + } + + memcpy (pOnCloseCmds, string + subs[1].rm_so, len); + pOnCloseCmds[len] = '\0'; + +#if defined(DEBUG_AFTERPARSE) && defined(DEBUG_PROPSECTION) + printf("\n\r Hex code of parsed: "); + for(int j=0;j +#include +#include +#include "profile.h" +#include "CreateDemoBin.h" +#include "DemoBinHeader.h" + + +//show usage help +void ShowHelp(const char * exeName) +{ + printf("\n"); + printf("Usage: %s [options] ", exeName); + printf("\n For example, sam3demo.ppt, after running VBS macro in PowerPoint, "); + printf("\n copy this file under the same directory, then Run:\n"); + printf("\n %s sam3demo", exeName); + printf("\n Options:"); + printf("\n --help, show this information"); + printf("\n -profile , build-in option sets, default board name is at91sam3u-ek"); + printf("\n -profile help, display all build-in profile details"); + printf("\n -width , default is 320 pixel"); + printf("\n -height , default is 240 pixel"); + printf("\n -bitdepth , default is 16 bit"); + printf("\n -rotate , times of 90 degree within 360, default is 270 degree"); + printf("\n -noreversebitmaporder, keep bitmap data original order, default reverse the order for at91sam3u-ek"); + printf("\n"); +} + +//show profile details +void ShowProfiles() +{ + printf("\n\r profiles details:"); + printf("\n\r -profile at91sam3u-ek <-> -bitdepth 16 -width 320 -height 240 -rotate 0"); + +} + +//seek matched profile +static int ProfileOption(char *pProfile, BMPConvOpt *const pOption ) +{ + unsigned int j; + unsigned int i = sizeof(profile)/sizeof(Profile); + + for(j = 0; j < i; j++) { + if(strcmp(pProfile, profile[j].pProfileName) == 0) { + pOption->bitdepth = profile[j].options.bitdepth; + pOption->width = profile[j].options.width; + pOption->height = profile[j].options.height; + pOption->rotateangle = profile[j].options.rotateangle; + pOption->reversebitmaporder = profile[j].options.reversebitmaporder; + return 0; + } + } + + return 1; +} + +//get conversion setting option from execution arguments +static void GetOptsFromargv(int argc, char **argv, BMPConvOpt *pOption) +{ + int i; + + //set default option value, it is used for at91SAM3u-ek demo on SDCARD or NANDFLASH + pOption->bitdepth = 16; + pOption->width = 320; + pOption->height = 240; + pOption->rotateangle = 270; + pOption->reversebitmaporder = 1; + #if defined(MOVIE_MERGE_on) + pOption->mvSlideNumber = 5; + #endif + #if defined(SLIDESHOW_MERGE_on) + pOption->ssPageNumber = MAXSLIDESPERBIN; + pOption->ssBitdepth = 16; + pOption->ssWidth = 320; + pOption->ssHeight = 240; + pOption->ssRotateangle = 270; + pOption->ssReverseBmpOrder = 1; + #endif + + //parse argument + for(i=1;iwidth = (unsigned int)floor(atof(argv[++i])); + continue; + } + + if(strcmp(argv[i], "-height")==0) { + pOption->height = (unsigned int)floor(atof(argv[++i])); + continue; + } + + if(strcmp(argv[i], "-bitdepth")==0) { + pOption->bitdepth = (unsigned int)floor(atof(argv[++i])); + continue; + } + + if(strcmp(argv[i], "-rotate")==0) { + pOption->rotateangle = (unsigned int)floor(atof(argv[++i])); + continue; + } + + if(strcmp(argv[i], "-noreversebitmaporder")==0) { + pOption->reversebitmaporder = 0; + continue; + } + + #if defined(MOVIE_MERGE_on) + if(strcmp(argv[i], "-movieSlideNumber")==0) { + pOption->mvSlideNumber = (unsigned int)floor(atof(argv[++i])); + continue; + } + #endif + + #if defined(SLIDESHOW_MERGE_on) + if(strcmp(argv[i], "-ssPageNumber")== 0) { + pOption->ssPageNumber = (unsigned int)floor(atof(argv[++i])); + continue; + } + + if(strcmp(argv[i], "-ssWidth")== 0) { + pOption->ssWidth = (unsigned int)floor(atof(argv[++i])); + continue; + } + + if(strcmp(argv[i], "-ssHeight")==0) { + pOption->ssHeight = (unsigned int)floor(atof(argv[++i])); + continue; + } + + if(strcmp(argv[i], "-ssBitdepth")==0) { + pOption->ssBitdepth = (unsigned int)floor(atof(argv[++i])); + continue; + } + + if(strcmp(argv[i], "-ssRotate")==0) { + pOption->ssRotateangle = (unsigned int)floor(atof(argv[++i])); + continue; + } + + if(strcmp(argv[i], "-ssNoreversebitmaporder")==0) { + pOption->ssReverseBmpOrder = 0; + continue; + } + #endif + } + + printf("\n *****Prepare: Converstion will use following options:"); + #if defined(SLIDESHOW_MERGE_on) + printf("\n Bitdepth: %u; Width: %u; Height: %u; rotate angel: %u; reversebitorder: %s; SS Slide number: %u; SSBitdepth: %u; SSWidth: %u; SSHeight: %u; SS rotate angel: %u;",\ + pOption->bitdepth,\ + pOption->width,\ + pOption->height,\ + pOption->rotateangle,\ + pOption->reversebitmaporder ? "yes":"no",\ + pOption->ssPageNumber,\ + pOption->ssBitdepth,\ + pOption->ssWidth,\ + pOption->ssHeight,\ + pOption->ssRotateangle); + #else + printf("\n Bitdepth: %u; Width: %u; Height: %u; rotate angel: %u; reversebitorder: %s;",\ + pOption->bitdepth,\ + pOption->width,\ + pOption->height,\ + pOption->rotateangle,\ + pOption->reversebitmaporder ? "yes":"no"); + #endif + +} + +//////////////////////////////////////////////////////////////////// +//Main portal +/////////////////////////////////////////////////////////////////// + +int main(int argc, char**argv) +{ + bool bRet=true; + BMPConvOpt option; + + //Show usage help + if(argc == 1 || \ + strcmp(argv[1], "--help")==0 || \ + strcmp(argv[1], "/?")==0 \ + ) + { + ShowHelp(argv[0]); + return 1; + } + + if(argc == 3 && strcmp(argv[1], "-profile") == 0 && strcmp(argv[2], "help") == 0) { + ShowProfiles(); + return 0; + } + + //parse execution options ready for following conversion + GetOptsFromargv(argc, argv, &option); + + //Init filename variables based on command argument + printf("\n\n *****Step1: Create Neccesary file names!"); + Step1_CreateFileNameVars(argv[argc-1]); + +#if 0 + //check if created file names are correct + printf("\n\r %s ", pptScriptLink); + printf("\n\r %s", pAtmlDemoBin); + printf("\n\r %s", pBinContent); + for(int i = 0; i< MAXSLIDESPERBIN; ++i) { + printf("\n\r %s", pptSlidesBmp[i]); + } + for(int j=0; j < MAXSLIDESPERBIN; ++j) { + printf("\n\r %s", pptSlides320x240Bmp[j]); + } + exit(0); +#endif + + //Parsed generated Script file + #if !defined(MOVIE_MERGE_on) + printf("\n\n *****Step2: Parse PPT slide information txt file"); + bRet &= Step2_ProcessPPTInfoFile(&option); + printf("\n ****Step2 Result: %s ****", bRet?"Success":"Failure"); + #endif + + //Resize and rotate saved slide bmp files + printf("\n\n *****Step3: Resize,rotate and reset bit depth of slide bmp file"); + printf("\nbitdepth %u, width %u, height %u, rotateangle %u",option.bitdepth, option.width, option.height, option.rotateangle); + bRet &= Step3_ResizeAndRotateSlideBMP(&option); + printf("\n ****Step3 Result: %s ****", bRet?"Success":"Failure"); + + //Create Atmel Demo bin file + printf("\n\n *****Step4: Create demo bin from above step generated information"); + bRet &= Step4_GenerateDemoBin(&option); + printf("\n ****Step4 Result: %s ****", bRet?"Success":"Failure"); + +#if !defined(MOVIE_MERGE_on) + //Show each bmp bitmap file header in demo bin file + printf("\n\n *****Done: Check bitmap file information in generated demo bin"); + ShowEachBmpHeader(); +#endif + + if(bRet) { + printf("\n\n -----------Result: Creating demo bin file succeeds!-----------"); + return 0; + } + else { + printf("\n\n ------------Result: Fail to Create right demo bin!-----------"); + return 1; + } + +} + + -- cgit v1.2.3