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 --- utility/demo-fw/pc-tools/CreateDemoBin/Makefile | 69 + utility/demo-fw/pc-tools/CreateDemoBin/Module1.bas | 350 ++++ .../pc-tools/CreateDemoBin/PPT/CreateDemoBinH.bat | 2 + .../CreateDemoBin/PPT/CreateDemoBinIFlash.bat | 2 + .../pc-tools/CreateDemoBin/PPT/CreatelDemoBinV.bat | 2 + .../pc-tools/CreateDemoBin/PPT/DEMOBINFLASH1.bin | Bin 0 -> 78822 bytes .../pc-tools/CreateDemoBin/PPT/DEMOBINFLASH1.ppt | Bin 0 -> 125952 bytes .../demo-fw/pc-tools/CreateDemoBin/PPT/Module1.bas | 350 ++++ .../pc-tools/CreateDemoBin/PPT/SAM3U_MarCom.ppt | Bin 0 -> 2458112 bytes .../pc-tools/CreateDemoBin/PPT/Sam3DEMO.bin | Bin 0 -> 5101618 bytes .../pc-tools/CreateDemoBin/PPT/Sam3DEMO.ppt | Bin 0 -> 1574400 bytes .../pc-tools/CreateDemoBin/PPT/SamDEMOV.bin | Bin 0 -> 5101618 bytes .../pc-tools/CreateDemoBin/PPT/SamDEMOV.ppt | Bin 0 -> 2018304 bytes .../pc-tools/CreateDemoBin/bin/CreateDemoBin.exe | Bin 0 -> 942615 bytes .../pc-tools/CreateDemoBin/bin/CreateMovieBin.exe | Bin 0 -> 940567 bytes .../pc-tools/CreateDemoBin/include/CreateDemoBin.h | 96 + .../pc-tools/CreateDemoBin/include/DemoBinHeader.h | 82 + .../pc-tools/CreateDemoBin/include/ScriptParse.h | 103 ++ .../pc-tools/CreateDemoBin/include/profile.h | 22 + .../demo-fw/pc-tools/CreateDemoBin/include/regex.h | 556 ++++++ .../lib/EasyBMP/BSD_(revised)_license.txt | 10 + .../pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP.cpp | 1917 ++++++++++++++++++++ .../pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP.h | 86 + .../CreateDemoBin/lib/EasyBMP/EasyBMP_BMP.h | 86 + .../lib/EasyBMP/EasyBMP_ChangeLog.txt | 821 +++++++++ .../lib/EasyBMP/EasyBMP_DataStructures.h | 104 ++ .../lib/EasyBMP/EasyBMP_VariousBMPutilities.h | 53 + .../lib/EasyBMP/sample/EasyBMPbackground.bmp | Bin 0 -> 308278 bytes .../lib/EasyBMP/sample/EasyBMPsample.cpp | 82 + .../lib/EasyBMP/sample/EasyBMPtext.bmp | Bin 0 -> 113266 bytes .../CreateDemoBin/lib/EasyBMP/sample/makefile | 53 + .../demo-fw/pc-tools/CreateDemoBin/lib/libregex.a | Bin 0 -> 182428 bytes utility/demo-fw/pc-tools/CreateDemoBin/readme.txt | 109 ++ .../pc-tools/CreateDemoBin/src/CreateDemoBin.cpp | 1102 +++++++++++ .../pc-tools/CreateDemoBin/src/ScriptParse.cpp | 851 +++++++++ .../demo-fw/pc-tools/CreateDemoBin/src/main.cpp | 268 +++ 36 files changed, 7176 insertions(+) create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/Makefile create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/Module1.bas create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/PPT/CreateDemoBinH.bat create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/PPT/CreateDemoBinIFlash.bat create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/PPT/CreatelDemoBinV.bat create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/PPT/DEMOBINFLASH1.bin create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/PPT/DEMOBINFLASH1.ppt create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/PPT/Module1.bas create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/PPT/SAM3U_MarCom.ppt create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/PPT/Sam3DEMO.bin create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/PPT/Sam3DEMO.ppt create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/PPT/SamDEMOV.bin create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/PPT/SamDEMOV.ppt create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/bin/CreateDemoBin.exe create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/bin/CreateMovieBin.exe create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/include/CreateDemoBin.h create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/include/DemoBinHeader.h create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/include/ScriptParse.h create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/include/profile.h create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/include/regex.h create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/BSD_(revised)_license.txt create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP.cpp create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP.h create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_BMP.h create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_ChangeLog.txt create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_DataStructures.h create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_VariousBMPutilities.h create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/EasyBMPbackground.bmp create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/EasyBMPsample.cpp create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/EasyBMPtext.bmp create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/makefile create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/lib/libregex.a create mode 100644 utility/demo-fw/pc-tools/CreateDemoBin/readme.txt 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') diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/Makefile b/utility/demo-fw/pc-tools/CreateDemoBin/Makefile new file mode 100644 index 0000000..786da50 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/Makefile @@ -0,0 +1,69 @@ +# Output directories +BIN = bin +OBJ = obj + +# Compiler +CC = g++ + +# Optimization level +OPT = + +# Flags +INCLUDES = -I include +INCLUDES += -I lib/EasyBMP +INCLUDES += -I lib/regex + +CXXFLAGS = $(OPT) -g -Wall +CXXFLAGS += -D DEBUG_PROPSECTION +CXXFLAGS += -D DEBUG_DISPSECTION +CXXFLAGS += -D DEBUG_SLIDESECTION +CXXFLAGS += -D DEBUG_LINKSECTION +CXXFLAGS += -D DEBUG_CONVBMPINFO +CXXFLAGS += -D DEBUG_BEFOREPARSE +CXXFLAGS += -D DEBUG_AFTERPARSE + +# Movie flas +ifeq ($(MOVIE_MERGE), on) +CXXFLAGS += -D MOVIE_MERGE_on +endif + +LDFLAGS = $(OPT) + +# VPATH to search source +VPATH += ./src +VPATH += ./lib/EasyBMP + +# Objects +OBJS += main.o +OBJS += ScriptParse.o +OBJS += EasyBMP.o +OBJS += CreateDemoBin.o + +C_OBJECTS = $(addprefix $(OBJ)/, $(OBJS)) + +LIBS = lib/libregex.a + +# Source code + +# Output target +ifeq ($(MOVIE_MERGE), on) +TARGET = CreateMovieBin.exe +else +TARGET = CreateDemoBin.exe +endif + +# Make target +.PHONY: all +all: $(BIN) $(OBJ) $(TARGET) + +$(BIN) $(OBJ): + mkdir $@ + +$(OBJS): %.o: %.cpp + $(CC) -c $(CXXFLAGS) $(INCLUDES) $< -o $(OBJ)/$@ + +$(TARGET): $(OBJS) + $(CC) $(LDFLAGS) -o $(BIN)/$(TARGET) $(C_OBJECTS) $(LIBS) + +clean: + -rm -f $(OBJ)/*.o $(BIN)/$(TARGET) diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/Module1.bas b/utility/demo-fw/pc-tools/CreateDemoBin/Module1.bas new file mode 100644 index 0000000..4d0fece --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/Module1.bas @@ -0,0 +1,350 @@ +Attribute VB_Name = "Module1" +Sub ExportPPTInfo() + +Dim DataTextStr As String +Dim SrcPpt As Application +Dim BaseObj As Object +Dim OutputText As String +Dim pShape As Shape +Dim pTextRange As TextRange +Dim pActionSetting As ActionSetting +Dim pSlide As Slide +Dim pTextFrame As TextFrame +Dim flag As Integer +Dim CurType As Integer +Dim SlideNo As Integer +Dim HyperlinkNo As Integer +Dim intOutFile As Integer +Dim Addr As String +Dim Filename As String +Dim Index As Integer +Dim stringLen As Integer +Dim Pos As Integer +Dim Notes As String +Dim defaulttxt, Options, WSH, inputtext, NameNoExt + + flag = 0 + CurType = 0 + SlideNo = 1 + HyperlinkNo = 1 + + + Set SrcPpt = Application + For Each SlideItem In SrcPpt.ActivePresentation.Slides + OutputText = OutputText + "Slide" + Str(SlideNo) + ":" + Chr$(13) & Chr$(10) + OutputText = OutputText + "Slide Size:" + Chr$(13) & Chr$(10) + OutputText = OutputText + "Width: " + Str(SlideItem.Master.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(SlideItem.Master.Height) + Chr$(13) & Chr$(10) + Chr$(13) & Chr$(10) + +' MsgBox SlideItem.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange.Text + Notes = SlideItem.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange.Text + If Notes <> "" Then + OutputText = OutputText + "Properties::" + Chr$(13) & Chr$(10) + OutputText = OutputText + Notes + Chr$(13) & Chr$(10) + Chr$(13) & Chr$(10) + End If + + SlideNo = SlideNo + 1 + HyperlinkNo = 0 + For Each linkitem In SlideItem.Hyperlinks + flag = 0 + Addr = linkitem.Address + If Addr = "BoxOnly" Then + OutputText = OutputText + "Display Box:" + Chr$(13) & Chr$(10) + Else + HyperlinkNo = HyperlinkNo + 1 + OutputText = OutputText + "HyperLink" + Str(HyperlinkNo) + "::" + Chr$(13) & Chr$(10) + OutputText = OutputText + Chr$(34) + "Link Address" + Chr$(34) + ": " + Addr + Chr$(13) & Chr$(10) + End If + + If (TypeName(linkitem.Parent) = "Shape" Or TypeName(linkitem.Parent) = "TextRange") Then + flag = 1 + If TypeName(linkitem.Parent) = "Shape" Then + Set pShape = linkitem.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) +' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = linkitem.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) +' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(linkitem.Parent) + + Case "ActionSetting" + Set pActionSetting = linkitem.Parent + CurType = 3 + Case "Slide" + Set pSlide = linkitem.Parent + CurType = 4 + + Case "TextFrame" + Set pTextFrame = linkitem.Parent + CurType = 5 + + End Select + + End If + While Not (flag = 1) + Select Case CurType + Case 3 + If (TypeName(pActionSetting.Parent) = "Shape" Or TypeName(pActionSetting.Parent) = "TextRange") Then + flag = 1 + If TypeName(pActionSetting.Parent) = "Shape" Then + Set pShape = pActionSetting.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) + ' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = pActionSetting.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) + ' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(pActionSetting.Parent) + Case "ActionSetting" + Set pActionSetting = pActionSetting.Parent + CurType = 3 + Case "Slide" + Set pSlide = pActionSetting.Parent + CurType = 4 + Case "TextFrame" + Set pTextFrame = pActionSetting.Parent + CurType = 5 + End Select + + End If + Case 4 + If (TypeName(pSlide.Parent) = "Shape" Or TypeName(pSlide.Parent) = "TextRange") Then + flag = 1 + If TypeName(pSlide.Parent) = "Shape" Then + Set pShape = pSlide.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) + ' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = pSlide.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) + ' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(pSlide.Parent) + Case "ActionSetting" + Set pActionSetting = pSlide.Parent + CurType = 3 + Case "Slide" + Set pSlide = pSlide.Parent + CurType = 4 + Case "TextFrame" + Set pTextFrame = pSlide.Parent + CurType = 5 + End Select + + End If + Case 5 + If (TypeName(pTextFrame.Parent) = "Shape" Or TypeName(pTextFrame.Parent) = "TextRange") Then + flag = 1 + If TypeName(pTextFrame.Parent) = "Shape" Then + Set pShape = pTextFrame.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) + ' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = pTextFrame.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) + ' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(pTextFrame.Parent) + Case "ActionSetting" + Set pActionSetting = pTextFrame.Parent + CurType = 3 + Case "Slide" + Set pSlide = pTextFrame.Parent + CurType = 4 + Case "TextFrame" + Set pTextFrame = pTextFrame.Parent + CurType = 5 + End Select + + End If + End Select + Wend + + + OutputText = OutputText + Chr$(13) & Chr$(10) + Next + + For Each linkitem In SlideItem.Master.Hyperlinks + flag = 0 + Addr = linkitem.Address + If Addr = "BoxOnly" Then + OutputText = OutputText + "Display Box:" + Chr$(13) & Chr$(10) + Else + HyperlinkNo = HyperlinkNo + 1 + OutputText = OutputText + "HyperLink" + Str(HyperlinkNo) + "::" + Chr$(13) & Chr$(10) + OutputText = OutputText + Chr$(34) + "Link Address" + Chr$(34) + ": " + Addr + Chr$(13) & Chr$(10) + End If + + If (TypeName(linkitem.Parent) = "Shape" Or TypeName(linkitem.Parent) = "TextRange") Then + flag = 1 + If TypeName(linkitem.Parent) = "Shape" Then + Set pShape = linkitem.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) +' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = linkitem.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) +' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(linkitem.Parent) + + Case "ActionSetting" + Set pActionSetting = linkitem.Parent + CurType = 3 + Case "Slide" + Set pSlide = linkitem.Parent + CurType = 4 + + Case "TextFrame" + Set pTextFrame = linkitem.Parent + CurType = 5 + + End Select + + End If + While Not (flag = 1) + Select Case CurType + Case 3 + If (TypeName(pActionSetting.Parent) = "Shape" Or TypeName(pActionSetting.Parent) = "TextRange") Then + flag = 1 + If TypeName(pActionSetting.Parent) = "Shape" Then + Set pShape = pActionSetting.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) + ' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = pActionSetting.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) + ' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(pActionSetting.Parent) + Case "ActionSetting" + Set pActionSetting = pActionSetting.Parent + CurType = 3 + Case "Slide" + Set pSlide = pActionSetting.Parent + CurType = 4 + Case "TextFrame" + Set pTextFrame = pActionSetting.Parent + CurType = 5 + End Select + + End If + Case 4 + If (TypeName(pSlide.Parent) = "Shape" Or TypeName(pSlide.Parent) = "TextRange") Then + flag = 1 + If TypeName(pSlide.Parent) = "Shape" Then + Set pShape = pSlide.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) + ' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = pSlide.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) + ' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(pSlide.Parent) + Case "ActionSetting" + Set pActionSetting = pSlide.Parent + CurType = 3 + Case "Slide" + Set pSlide = pSlide.Parent + CurType = 4 + Case "TextFrame" + Set pTextFrame = pSlide.Parent + CurType = 5 + End Select + + End If + Case 5 + If (TypeName(pTextFrame.Parent) = "Shape" Or TypeName(pTextFrame.Parent) = "TextRange") Then + flag = 1 + If TypeName(pTextFrame.Parent) = "Shape" Then + Set pShape = pTextFrame.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) + ' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = pTextFrame.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) + ' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(pTextFrame.Parent) + Case "ActionSetting" + Set pActionSetting = pTextFrame.Parent + CurType = 3 + Case "Slide" + Set pSlide = pTextFrame.Parent + CurType = 4 + Case "TextFrame" + Set pTextFrame = pTextFrame.Parent + CurType = 5 + End Select + + End If + End Select + Wend + + + OutputText = OutputText + Chr$(13) & Chr$(10) + Next + OutputText = OutputText + Chr$(13) & Chr$(10) + Chr$(13) & Chr$(10) + Next + + stringLen = Len(SrcPpt.ActivePresentation.Name) + For Index = 1 To stringLen + If Mid(SrcPpt.ActivePresentation.Name, Index, 1) = "." Then + Pos = Index + End If + Next + + Filename = Left(SrcPpt.ActivePresentation.Name, Pos - 1) + ".txt" + NameNoExt = Left(SrcPpt.ActivePresentation.Name, Pos - 1) + + Open Filename For Output As #1 + Print #1, OutputText + Close #1 + +' Save as PNG files +With Application.ActivePresentation + '.SaveAs SrcPpt.ActivePresentation.Name, ppSaveAsBMP + .Export SrcPpt.ActivePresentation.Name, "BMP", 320, 240 +End With + +Set WSH = CreateObject("WSCRIPT.SHELL") + +defaulttxt = "-profile at91sam3u-ek" + +inputtext = "Use following format:" + Chr$(13) & Chr$(10) + " -profile , default profiles" + Chr$(13) & Chr$(10) + "Or" + Chr$(13) & Chr$(10) + " -bitdepth xx -width xxx -height xxx -rotate xxx [-noreversebitorder]" + +Do + +Options = InputBox(inputtext, "Input convert param:", defaulttxt) + +If Len(Options) = 0 Then +Exit Do + +Else + +inputtext = "../bin/CreateDemoBin.exe " + Options + " " + NameNoExt + +WSH.POPUP (inputtext) + +WSH.Run (inputtext) + + +Exit Do + +End If + +Loop + +End Sub + diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/PPT/CreateDemoBinH.bat b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/CreateDemoBinH.bat new file mode 100644 index 0000000..7c6f358 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/CreateDemoBinH.bat @@ -0,0 +1,2 @@ +..\bin\CreateDemoBin -width 320 -height 240 -bitdepth 16 -rotate 270 Sam3DEMO +pause \ No newline at end of file diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/PPT/CreateDemoBinIFlash.bat b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/CreateDemoBinIFlash.bat new file mode 100644 index 0000000..265c8ed --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/CreateDemoBinIFlash.bat @@ -0,0 +1,2 @@ +..\bin\CreateDemoBin -width 320 -height 240 -bitdepth 8 -rotate 270 -noreversebitmaporder DEMOBINFLASH1 +pause \ No newline at end of file diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/PPT/CreatelDemoBinV.bat b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/CreatelDemoBinV.bat new file mode 100644 index 0000000..7171642 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/CreatelDemoBinV.bat @@ -0,0 +1,2 @@ +..\bin\CreateDemoBin -width 240 -height 320 -bitdepth 16 -rotate 0 -ssPageNumber 17 --ssWidth 320 -ssHeight 240 -ssBitdepth 16 -ssRotate 270 SamDEMOV +pause \ No newline at end of file diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/PPT/DEMOBINFLASH1.bin b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/DEMOBINFLASH1.bin new file mode 100644 index 0000000..c9edee5 Binary files /dev/null and b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/DEMOBINFLASH1.bin differ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/PPT/DEMOBINFLASH1.ppt b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/DEMOBINFLASH1.ppt new file mode 100644 index 0000000..22c843a Binary files /dev/null and b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/DEMOBINFLASH1.ppt differ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/PPT/Module1.bas b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/Module1.bas new file mode 100644 index 0000000..4d0fece --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/Module1.bas @@ -0,0 +1,350 @@ +Attribute VB_Name = "Module1" +Sub ExportPPTInfo() + +Dim DataTextStr As String +Dim SrcPpt As Application +Dim BaseObj As Object +Dim OutputText As String +Dim pShape As Shape +Dim pTextRange As TextRange +Dim pActionSetting As ActionSetting +Dim pSlide As Slide +Dim pTextFrame As TextFrame +Dim flag As Integer +Dim CurType As Integer +Dim SlideNo As Integer +Dim HyperlinkNo As Integer +Dim intOutFile As Integer +Dim Addr As String +Dim Filename As String +Dim Index As Integer +Dim stringLen As Integer +Dim Pos As Integer +Dim Notes As String +Dim defaulttxt, Options, WSH, inputtext, NameNoExt + + flag = 0 + CurType = 0 + SlideNo = 1 + HyperlinkNo = 1 + + + Set SrcPpt = Application + For Each SlideItem In SrcPpt.ActivePresentation.Slides + OutputText = OutputText + "Slide" + Str(SlideNo) + ":" + Chr$(13) & Chr$(10) + OutputText = OutputText + "Slide Size:" + Chr$(13) & Chr$(10) + OutputText = OutputText + "Width: " + Str(SlideItem.Master.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(SlideItem.Master.Height) + Chr$(13) & Chr$(10) + Chr$(13) & Chr$(10) + +' MsgBox SlideItem.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange.Text + Notes = SlideItem.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange.Text + If Notes <> "" Then + OutputText = OutputText + "Properties::" + Chr$(13) & Chr$(10) + OutputText = OutputText + Notes + Chr$(13) & Chr$(10) + Chr$(13) & Chr$(10) + End If + + SlideNo = SlideNo + 1 + HyperlinkNo = 0 + For Each linkitem In SlideItem.Hyperlinks + flag = 0 + Addr = linkitem.Address + If Addr = "BoxOnly" Then + OutputText = OutputText + "Display Box:" + Chr$(13) & Chr$(10) + Else + HyperlinkNo = HyperlinkNo + 1 + OutputText = OutputText + "HyperLink" + Str(HyperlinkNo) + "::" + Chr$(13) & Chr$(10) + OutputText = OutputText + Chr$(34) + "Link Address" + Chr$(34) + ": " + Addr + Chr$(13) & Chr$(10) + End If + + If (TypeName(linkitem.Parent) = "Shape" Or TypeName(linkitem.Parent) = "TextRange") Then + flag = 1 + If TypeName(linkitem.Parent) = "Shape" Then + Set pShape = linkitem.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) +' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = linkitem.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) +' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(linkitem.Parent) + + Case "ActionSetting" + Set pActionSetting = linkitem.Parent + CurType = 3 + Case "Slide" + Set pSlide = linkitem.Parent + CurType = 4 + + Case "TextFrame" + Set pTextFrame = linkitem.Parent + CurType = 5 + + End Select + + End If + While Not (flag = 1) + Select Case CurType + Case 3 + If (TypeName(pActionSetting.Parent) = "Shape" Or TypeName(pActionSetting.Parent) = "TextRange") Then + flag = 1 + If TypeName(pActionSetting.Parent) = "Shape" Then + Set pShape = pActionSetting.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) + ' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = pActionSetting.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) + ' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(pActionSetting.Parent) + Case "ActionSetting" + Set pActionSetting = pActionSetting.Parent + CurType = 3 + Case "Slide" + Set pSlide = pActionSetting.Parent + CurType = 4 + Case "TextFrame" + Set pTextFrame = pActionSetting.Parent + CurType = 5 + End Select + + End If + Case 4 + If (TypeName(pSlide.Parent) = "Shape" Or TypeName(pSlide.Parent) = "TextRange") Then + flag = 1 + If TypeName(pSlide.Parent) = "Shape" Then + Set pShape = pSlide.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) + ' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = pSlide.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) + ' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(pSlide.Parent) + Case "ActionSetting" + Set pActionSetting = pSlide.Parent + CurType = 3 + Case "Slide" + Set pSlide = pSlide.Parent + CurType = 4 + Case "TextFrame" + Set pTextFrame = pSlide.Parent + CurType = 5 + End Select + + End If + Case 5 + If (TypeName(pTextFrame.Parent) = "Shape" Or TypeName(pTextFrame.Parent) = "TextRange") Then + flag = 1 + If TypeName(pTextFrame.Parent) = "Shape" Then + Set pShape = pTextFrame.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) + ' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = pTextFrame.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) + ' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(pTextFrame.Parent) + Case "ActionSetting" + Set pActionSetting = pTextFrame.Parent + CurType = 3 + Case "Slide" + Set pSlide = pTextFrame.Parent + CurType = 4 + Case "TextFrame" + Set pTextFrame = pTextFrame.Parent + CurType = 5 + End Select + + End If + End Select + Wend + + + OutputText = OutputText + Chr$(13) & Chr$(10) + Next + + For Each linkitem In SlideItem.Master.Hyperlinks + flag = 0 + Addr = linkitem.Address + If Addr = "BoxOnly" Then + OutputText = OutputText + "Display Box:" + Chr$(13) & Chr$(10) + Else + HyperlinkNo = HyperlinkNo + 1 + OutputText = OutputText + "HyperLink" + Str(HyperlinkNo) + "::" + Chr$(13) & Chr$(10) + OutputText = OutputText + Chr$(34) + "Link Address" + Chr$(34) + ": " + Addr + Chr$(13) & Chr$(10) + End If + + If (TypeName(linkitem.Parent) = "Shape" Or TypeName(linkitem.Parent) = "TextRange") Then + flag = 1 + If TypeName(linkitem.Parent) = "Shape" Then + Set pShape = linkitem.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) +' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = linkitem.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) +' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(linkitem.Parent) + + Case "ActionSetting" + Set pActionSetting = linkitem.Parent + CurType = 3 + Case "Slide" + Set pSlide = linkitem.Parent + CurType = 4 + + Case "TextFrame" + Set pTextFrame = linkitem.Parent + CurType = 5 + + End Select + + End If + While Not (flag = 1) + Select Case CurType + Case 3 + If (TypeName(pActionSetting.Parent) = "Shape" Or TypeName(pActionSetting.Parent) = "TextRange") Then + flag = 1 + If TypeName(pActionSetting.Parent) = "Shape" Then + Set pShape = pActionSetting.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) + ' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = pActionSetting.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) + ' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(pActionSetting.Parent) + Case "ActionSetting" + Set pActionSetting = pActionSetting.Parent + CurType = 3 + Case "Slide" + Set pSlide = pActionSetting.Parent + CurType = 4 + Case "TextFrame" + Set pTextFrame = pActionSetting.Parent + CurType = 5 + End Select + + End If + Case 4 + If (TypeName(pSlide.Parent) = "Shape" Or TypeName(pSlide.Parent) = "TextRange") Then + flag = 1 + If TypeName(pSlide.Parent) = "Shape" Then + Set pShape = pSlide.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) + ' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = pSlide.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) + ' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(pSlide.Parent) + Case "ActionSetting" + Set pActionSetting = pSlide.Parent + CurType = 3 + Case "Slide" + Set pSlide = pSlide.Parent + CurType = 4 + Case "TextFrame" + Set pTextFrame = pSlide.Parent + CurType = 5 + End Select + + End If + Case 5 + If (TypeName(pTextFrame.Parent) = "Shape" Or TypeName(pTextFrame.Parent) = "TextRange") Then + flag = 1 + If TypeName(pTextFrame.Parent) = "Shape" Then + Set pShape = pTextFrame.Parent + OutputText = OutputText + "Top: " + Str(pShape.Top) + Chr$(13) & Chr$(10) + "Left: " + Str(pShape.Left) + Chr$(13) & Chr$(10) + "Width: " + Str(pShape.Width) + Chr$(13) & Chr$(10) + "Height: " + Str(pShape.Height) + Chr$(13) & Chr$(10) + ' MsgBox Str(pShape.Left) + " " + Str(pShape.Top) + Else + Set pTextRange = pTextFrame.Parent + OutputText = OutputText + "Top: " + Str(pTextRange.BoundTop) + Chr$(13) & Chr$(10) + "Left: " + Str(pTextRange.BoundLeft) + Chr$(13) & Chr$(10) + "Width: " + Str(pTextRange.BoundWidth) + Chr$(13) & Chr$(10) + "Height: " + Str(pTextRange.BoundHeight) + Chr$(13) & Chr$(10) + ' MsgBox Str(pTextRange.BoundLeft) + " " + Str(pTextRange.BoundTop) + End If + Else + Select Case TypeName(pTextFrame.Parent) + Case "ActionSetting" + Set pActionSetting = pTextFrame.Parent + CurType = 3 + Case "Slide" + Set pSlide = pTextFrame.Parent + CurType = 4 + Case "TextFrame" + Set pTextFrame = pTextFrame.Parent + CurType = 5 + End Select + + End If + End Select + Wend + + + OutputText = OutputText + Chr$(13) & Chr$(10) + Next + OutputText = OutputText + Chr$(13) & Chr$(10) + Chr$(13) & Chr$(10) + Next + + stringLen = Len(SrcPpt.ActivePresentation.Name) + For Index = 1 To stringLen + If Mid(SrcPpt.ActivePresentation.Name, Index, 1) = "." Then + Pos = Index + End If + Next + + Filename = Left(SrcPpt.ActivePresentation.Name, Pos - 1) + ".txt" + NameNoExt = Left(SrcPpt.ActivePresentation.Name, Pos - 1) + + Open Filename For Output As #1 + Print #1, OutputText + Close #1 + +' Save as PNG files +With Application.ActivePresentation + '.SaveAs SrcPpt.ActivePresentation.Name, ppSaveAsBMP + .Export SrcPpt.ActivePresentation.Name, "BMP", 320, 240 +End With + +Set WSH = CreateObject("WSCRIPT.SHELL") + +defaulttxt = "-profile at91sam3u-ek" + +inputtext = "Use following format:" + Chr$(13) & Chr$(10) + " -profile , default profiles" + Chr$(13) & Chr$(10) + "Or" + Chr$(13) & Chr$(10) + " -bitdepth xx -width xxx -height xxx -rotate xxx [-noreversebitorder]" + +Do + +Options = InputBox(inputtext, "Input convert param:", defaulttxt) + +If Len(Options) = 0 Then +Exit Do + +Else + +inputtext = "../bin/CreateDemoBin.exe " + Options + " " + NameNoExt + +WSH.POPUP (inputtext) + +WSH.Run (inputtext) + + +Exit Do + +End If + +Loop + +End Sub + diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/PPT/SAM3U_MarCom.ppt b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/SAM3U_MarCom.ppt new file mode 100644 index 0000000..8e9863c Binary files /dev/null and b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/SAM3U_MarCom.ppt differ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/PPT/Sam3DEMO.bin b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/Sam3DEMO.bin new file mode 100644 index 0000000..9866a3e Binary files /dev/null and b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/Sam3DEMO.bin differ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/PPT/Sam3DEMO.ppt b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/Sam3DEMO.ppt new file mode 100644 index 0000000..6034f98 Binary files /dev/null and b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/Sam3DEMO.ppt differ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/PPT/SamDEMOV.bin b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/SamDEMOV.bin new file mode 100644 index 0000000..fec7e4c Binary files /dev/null and b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/SamDEMOV.bin differ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/PPT/SamDEMOV.ppt b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/SamDEMOV.ppt new file mode 100644 index 0000000..612e51f Binary files /dev/null and b/utility/demo-fw/pc-tools/CreateDemoBin/PPT/SamDEMOV.ppt differ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/bin/CreateDemoBin.exe b/utility/demo-fw/pc-tools/CreateDemoBin/bin/CreateDemoBin.exe new file mode 100644 index 0000000..cb1e084 Binary files /dev/null and b/utility/demo-fw/pc-tools/CreateDemoBin/bin/CreateDemoBin.exe differ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/bin/CreateMovieBin.exe b/utility/demo-fw/pc-tools/CreateDemoBin/bin/CreateMovieBin.exe new file mode 100644 index 0000000..d65906f Binary files /dev/null and b/utility/demo-fw/pc-tools/CreateDemoBin/bin/CreateMovieBin.exe differ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/include/CreateDemoBin.h b/utility/demo-fw/pc-tools/CreateDemoBin/include/CreateDemoBin.h new file mode 100644 index 0000000..d6d2883 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/include/CreateDemoBin.h @@ -0,0 +1,96 @@ +#ifndef __CREATEDEMOBIN_H +#define __CREATEDEMOBIN_H + +//////////////////////////////////////////////////////////// +//type definition +/////////////////////////////////////////////////////////// +// BMP (Windows) Header Format +typedef struct __attribute__ ((packed)) { + /// signature, must be 4D42 hex + unsigned short type; + /// size of BMP file in bytes (unreliable) + unsigned int fileSize; + /// reserved, must be zero + unsigned short reserved1; + /// reserved, must be zero + unsigned short reserved2; + /// offset to start of image data in bytes + unsigned int offset; + /// size of BITMAPINFOHEADER structure + unsigned int headerSize; + /// image width in pixels + unsigned int width; + /// image height in pixels + unsigned int height; + /// number of planes in the image, must be 1 + unsigned short planes; + /// number of bits per pixel (1, 4, 8, 16, 24, 32) + unsigned short bits; + /// compression type (0=none, 1=RLE-8, 2=RLE-4) + unsigned int compression; + /// size of image data in bytes (including padding) + unsigned int imageSize; + /// horizontal resolution in pixels per meter (unreliable) + unsigned int xresolution; + /// vertical resolution in pixels per meter (unreliable) + unsigned int yresolution; + /// number of colors in image, or zero + unsigned int ncolours; + /// number of important colors, or zero + unsigned int importantcolours; +} BMPHeader; + +//option structure for image conversion +typedef struct _BMPConvOptions { + //bitdepth of bmp file stored in demo bin file + unsigned int bitdepth; + //IMPORTANT NOTES: following width and height means + // resized image without any rotation + //resized bmp width + unsigned int width; + //resized bmp height + unsigned int height; + //anti-clockwise rotate angle + unsigned int rotateangle; + //reverse bmp bitmap data order + //some lcd controller needs to get BMP bitmap data from bottom to top + //this is used to indicate conversion + unsigned int reversebitmaporder; + #if defined(MOVIE_MERGE_on) + //slide number for movie binary + unsigned int mvSlideNumber; + #endif + #if defined(SLIDESHOW_MERGE_on) + unsigned int ssPageNumber; + unsigned int ssBitdepth; + unsigned int ssWidth; + unsigned int ssHeight; + unsigned int ssRotateangle; + unsigned int ssReverseBmpOrder; + #endif +} BMPConvOpt; + +#define BMP24MAPLEN 320*240*3 +#define BMP16MAPLEN 320*240*2 + +/////////////////////////////////////////////////////////////////////// +//export functions, steps of creation of atmel demo bin file +////////////////////////////////////////////////////////////////////// + +//Initialize filename variables +void Step1_CreateFileNameVars(char * name); + +//Process ppt information txt file +bool Step2_ProcessPPTInfoFile(BMPConvOpt *pOption); + +//Resize and Rotate slides +bool Step3_ResizeAndRotateSlideBMP(BMPConvOpt *pOption); + +//create demo bin from above variables +bool Step4_GenerateDemoBin(BMPConvOpt *pOption); + +//show generated bin contained bmp information +void ShowEachBmpHeader(); + + +#endif diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/include/DemoBinHeader.h b/utility/demo-fw/pc-tools/CreateDemoBin/include/DemoBinHeader.h new file mode 100644 index 0000000..7ad30fa --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/include/DemoBinHeader.h @@ -0,0 +1,82 @@ +/* + * AtmlDemobinHeader.h + * + * Created on: 2009-3-15 + * Author: Tony.Liu + */ + +#ifndef DEMOBINHEADER_H_ +#define DEMOBINHEADER_H_ + +#include + +#define MAXSCRIPTSTRINGLINE 128 + +#define MAXSLIDESPERBIN 300 + +#define MAXLINKLEN 50 + +#define MAX_LINK_PER_SLIDE 10 + +#define MAX_DISPBOX_PER_SLIDE 4 + +#define DEMOSLIDEWIDTH 240 + +#define DEMOSLIDEHEIGHT 320 + +#define ClearDemoBINHeader(pHead) memset((pHead), 0xFF, sizeof(DemoBINHeader)) + +#define ClearSlideINFOHeader(pHead) memset((pHead), 0xFF, sizeof(SlideINFOHeader)) + +/// ATMEL DEMO BIN tag value +#define ATMLBINTAG 0x4C4D5441 + +//demo bin file header +typedef struct { + unsigned int tag;//demo bin head,'A','T','M','L' + unsigned int filesize;//bin file size + unsigned int headersize;//headsize including all SlideINFOHeader fields + unsigned int slidecount;//slide numbers +// PPTINFO pptinfo[MAXSLIDESPERBIN]; +} DemoBINHeader; + +typedef struct { + //value are converted from slides script. noted BMP anticlockwise rotated 90 degree + unsigned int linkboxbottom; + unsigned int linkboxleft; + unsigned int linkboxwidth; + unsigned int linkboxheight; + //link string + char linkstring[MAXLINKLEN]; +}SlideLinkINFO; + +typedef struct { + //value are converted from slides script. noted BMP anticlockwise rotated 90 degree + unsigned int dispboxbottom; + unsigned int dispboxleft; + unsigned int dispboxwidth; + unsigned int dispboxheight; +} SlideDispINFO; + +typedef struct { + //properties for each slide, command string line supported only now. + unsigned int propcnt; //numbers of properties + char onInitCmds[MAXLINKLEN]; + char onRefreshCmds[MAXLINKLEN]; + char onCloseCmds[MAXLINKLEN]; +} SlidePropINFO; + +typedef struct { + unsigned int slideoffset; + unsigned int slidedatalength; + unsigned int slidewidth; + unsigned int slideheight; + unsigned int dispboxcount;//0 means no display box, others mean yes + SlideDispINFO dispboxinfo[MAX_DISPBOX_PER_SLIDE]; + unsigned int linkcount; + SlideLinkINFO linkinfo[MAX_LINK_PER_SLIDE]; + unsigned int propyes;// 0 means no property settings, 1 or others mean yes + SlidePropINFO propinfo; +} SlideINFOHeader; + +#endif /* DEMOBINHEADER_H_ */ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/include/ScriptParse.h b/utility/demo-fw/pc-tools/CreateDemoBin/include/ScriptParse.h new file mode 100644 index 0000000..05621de --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/include/ScriptParse.h @@ -0,0 +1,103 @@ +/* + * ScriptParse.h + * + * Created on: 2009-3-15 + * Author: Tony.Liu + */ + +#ifndef SCRIPTPARSE_H_ +#define SCRIPTPARSE_H_ + +//compile all pattern +bool CompileAllPtn(); + +//free all regex objects +void FreeAllRegex(); + +//is a space line? +bool IsSpaceLine(const char *string); + +//match slide count line and return the count +bool GetSlideCount( const char *string, unsigned int *slidenum); + +//check slide size line is correct +bool IsSlideSizeString(const char *string); + +//match slide width line and return the width +bool GetSlideWidth( const char *string, unsigned int *slidewidth); + +//match slide height line and return the height +bool GetSlideHeight( const char *string, unsigned int *slideheight); + +//Is Display Box section starting? +bool IsDispBoxSectionStart(const char *string); + +//match link top line and return link top position +bool GetDispBoxTop(const char *string, unsigned int *top); + +//match link left line and return link left position +bool GetDispBoxLeft(const char *string, unsigned int *left); + +//match link width line and return width value +bool GetDispBoxWidth(const char *string, unsigned int *width); + +//match link width line and return width value +bool GetDispBoxHeight(const char *string, unsigned int *height); + +//match hyperlink line and return link count +bool GetLinkCount(const char *string, unsigned int *linkcnt); + +//match link address line and return the address +bool GetLinkAddr(const char *string, char *link); + +//match link top line and return link top position +bool GetLinkTop(const char *string, unsigned int *top); + +//match link left line and return link left position +bool GetLinkLeft(const char *string, unsigned int *left); + +//match link width line and return width value +bool GetLinkWidth(const char *string, unsigned int *width); + +//match link width line and return width value +bool GetLinkHeight(const char *string, unsigned int *height); + +//Parse slide section of script +//Parse slide section of script +bool ParseSlideSection(const char *string, \ + unsigned int *slideindex, \ + unsigned int *slidewidth, \ + unsigned int *slideheight); + +//Parse hyperlink section of script +bool ParseLinkSection(const char *string, \ + unsigned int *linkindex, \ + char *linkstr, \ + unsigned int *linktop, \ + unsigned int *linkleft, \ + unsigned int *linkwidth, \ + unsigned int *linkheight); + +//Parse display box section of script +bool ParseDispBoxSection(const char *string, \ + unsigned int *disptop, \ + unsigned int *displeft, \ + unsigned int *dispwidth, \ + unsigned int *dispheight); + +//Parse slide properties section of script +bool ParsePropertiesSection(const char *string, \ + char *pOnInitCmds, \ + char *pOnRefreshCmds, \ + char *pOnCloseCmds); + +//Is slide section starting? +bool IsSlideSectionStart(const char *string); + +//Is hyperlink section starting? +bool IsLinkSectionStart(const char *string); + +//Is slide properties section starting? +bool IsPropertiesSectionStart(const char *string); + +#endif /* SCRIPTPARSE_H_ */ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/include/profile.h b/utility/demo-fw/pc-tools/CreateDemoBin/include/profile.h new file mode 100644 index 0000000..65294c9 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/include/profile.h @@ -0,0 +1,22 @@ +/* + * profile.h + * + * Created on: Oct 26, 2009 + * Author: Tony.Liu + */ + +#ifndef PROFILE_H_ +#define PROFILE_H_ + +#include "CreateDemoBin.h" + +typedef struct { + char *pProfileName; + BMPConvOpt options; +} Profile; + +static Profile profile[] = { + {"at91sam3u-ek", {16, 320, 240, 270, 1}} +}; + +#endif /* PROFILE_H_ */ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/include/regex.h b/utility/demo-fw/pc-tools/CreateDemoBin/include/regex.h new file mode 100644 index 0000000..2396f78 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/include/regex.h @@ -0,0 +1,556 @@ +/* Definitions for data structures and routines for the regular + expression library. + Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005,2006 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _REGEX_H +#define _REGEX_H 1 + +#include + +/* Allow the use in C++ code. */ +#ifdef __cplusplus +extern "C" { +#endif + +/* The following two types have to be signed and unsigned integer type + wide enough to hold a value of a pointer. For most ANSI compilers + ptrdiff_t and size_t should be likely OK. Still size of these two + types is 2 for Microsoft C. Ugh... */ +typedef long int s_reg_t; +typedef unsigned long int active_reg_t; + +/* The following bits are used to determine the regexp syntax we + recognize. The set/not-set meanings are chosen so that Emacs syntax + remains the value 0. The bits are given in alphabetical order, and + the definitions shifted by one from the previous bit; thus, when we + add or remove a bit, only one other definition need change. */ +typedef unsigned long int reg_syntax_t; + +/* If this bit is not set, then \ inside a bracket expression is literal. + If set, then such a \ quotes the following character. */ +#define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1) + +/* If this bit is not set, then + and ? are operators, and \+ and \? are + literals. + If set, then \+ and \? are operators and + and ? are literals. */ +#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) + +/* If this bit is set, then character classes are supported. They are: + [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], + [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. + If not set, then character classes are not supported. */ +#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) + +/* If this bit is set, then ^ and $ are always anchors (outside bracket + expressions, of course). + If this bit is not set, then it depends: + ^ is an anchor if it is at the beginning of a regular + expression or after an open-group or an alternation operator; + $ is an anchor if it is at the end of a regular expression, or + before a close-group or an alternation operator. + + This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because + POSIX draft 11.2 says that * etc. in leading positions is undefined. + We already implemented a previous draft which made those constructs + invalid, though, so we haven't changed the code back. */ +#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) + +/* If this bit is set, then special characters are always special + regardless of where they are in the pattern. + If this bit is not set, then special characters are special only in + some contexts; otherwise they are ordinary. Specifically, + * + ? and intervals are only special when not after the beginning, + open-group, or alternation operator. */ +#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) + +/* If this bit is set, then *, +, ?, and { cannot be first in an re or + immediately after an alternation or begin-group operator. */ +#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) + +/* If this bit is set, then . matches newline. + If not set, then it doesn't. */ +#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) + +/* If this bit is set, then . doesn't match NUL. + If not set, then it does. */ +#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) + +/* If this bit is set, nonmatching lists [^...] do not match newline. + If not set, they do. */ +#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) + +/* If this bit is set, either \{...\} or {...} defines an + interval, depending on RE_NO_BK_BRACES. + If not set, \{, \}, {, and } are literals. */ +#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) + +/* If this bit is set, +, ? and | aren't recognized as operators. + If not set, they are. */ +#define RE_LIMITED_OPS (RE_INTERVALS << 1) + +/* If this bit is set, newline is an alternation operator. + If not set, newline is literal. */ +#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) + +/* If this bit is set, then `{...}' defines an interval, and \{ and \} + are literals. + If not set, then `\{...\}' defines an interval. */ +#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) + +/* If this bit is set, (...) defines a group, and \( and \) are literals. + If not set, \(...\) defines a group, and ( and ) are literals. */ +#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) + +/* If this bit is set, then \ matches . + If not set, then \ is a back-reference. */ +#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) + +/* If this bit is set, then | is an alternation operator, and \| is literal. + If not set, then \| is an alternation operator, and | is literal. */ +#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) + +/* If this bit is set, then an ending range point collating higher + than the starting range point, as in [z-a], is invalid. + If not set, then when ending range point collates higher than the + starting range point, the range is ignored. */ +#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) + +/* If this bit is set, then an unmatched ) is ordinary. + If not set, then an unmatched ) is invalid. */ +#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) + +/* If this bit is set, succeed as soon as we match the whole pattern, + without further backtracking. */ +#define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) + +/* If this bit is set, do not process the GNU regex operators. + If not set, then the GNU regex operators are recognized. */ +#define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1) + +/* If this bit is set, turn on internal regex debugging. + If not set, and debugging was on, turn it off. + This only works if regex.c is compiled -DDEBUG. + We define this bit always, so that all that's needed to turn on + debugging is to recompile regex.c; the calling code can always have + this bit set, and it won't affect anything in the normal case. */ +#define RE_DEBUG (RE_NO_GNU_OPS << 1) + +/* If this bit is set, a syntactically invalid interval is treated as + a string of ordinary characters. For example, the ERE 'a{1' is + treated as 'a\{1'. */ +#define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1) + +/* If this bit is set, then ignore case when matching. + If not set, then case is significant. */ +#define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1) + +/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only + for ^, because it is difficult to scan the regex backwards to find + whether ^ should be special. */ +#define RE_CARET_ANCHORS_HERE (RE_ICASE << 1) + +/* If this bit is set, then \{ cannot be first in an bre or + immediately after an alternation or begin-group operator. */ +#define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1) + +/* If this bit is set, then no_sub will be set to 1 during + re_compile_pattern. */ +#define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1) + +/* This global variable defines the particular regexp syntax to use (for + some interfaces). When a regexp is compiled, the syntax used is + stored in the pattern buffer, so changing this does not affect + already-compiled regexps. */ +extern reg_syntax_t re_syntax_options; + +/* Define combinations of the above bits for the standard possibilities. + (The [[[ comments delimit what gets put into the Texinfo file, so + don't delete them!) */ +/* [[[begin syntaxes]]] */ +#define RE_SYNTAX_EMACS 0 + +#define RE_SYNTAX_AWK \ + (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ + | RE_NO_BK_PARENS | RE_NO_BK_REFS \ + | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ + | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \ + | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) + +#define RE_SYNTAX_GNU_AWK \ + ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \ + & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \ + | RE_CONTEXT_INVALID_OPS )) + +#define RE_SYNTAX_POSIX_AWK \ + (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ + | RE_INTERVALS | RE_NO_GNU_OPS) + +#define RE_SYNTAX_GREP \ + (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ + | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ + | RE_NEWLINE_ALT) + +#define RE_SYNTAX_EGREP \ + (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ + | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ + | RE_NO_BK_VBAR) + +#define RE_SYNTAX_POSIX_EGREP \ + (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \ + | RE_INVALID_INTERVAL_ORD) + +/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ +#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC + +#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC + +/* Syntax bits common to both basic and extended POSIX regex syntax. */ +#define _RE_SYNTAX_POSIX_COMMON \ + (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ + | RE_INTERVALS | RE_NO_EMPTY_RANGES) + +#define RE_SYNTAX_POSIX_BASIC \ + (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP) + +/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes + RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this + isn't minimal, since other operators, such as \`, aren't disabled. */ +#define RE_SYNTAX_POSIX_MINIMAL_BASIC \ + (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) + +#define RE_SYNTAX_POSIX_EXTENDED \ + (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ + | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ + | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD) + +/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is + removed and RE_NO_BK_REFS is added. */ +#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ + (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ + | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ + | RE_NO_BK_PARENS | RE_NO_BK_REFS \ + | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) +/* [[[end syntaxes]]] */ + +/* Maximum number of duplicates an interval can allow. Some systems + (erroneously) define this in other header files, but we want our + value, so remove any previous define. */ +#ifdef RE_DUP_MAX +# undef RE_DUP_MAX +#endif +/* If sizeof(int) == 2, then ((1 << 15) - 1) overflows. */ +#define RE_DUP_MAX (0x7fff) + + +/* POSIX `cflags' bits (i.e., information for `regcomp'). */ + +/* If this bit is set, then use extended regular expression syntax. + If not set, then use basic regular expression syntax. */ +#define REG_EXTENDED 1 + +/* If this bit is set, then ignore case when matching. + If not set, then case is significant. */ +#define REG_ICASE (REG_EXTENDED << 1) + +/* If this bit is set, then anchors do not match at newline + characters in the string. + If not set, then anchors do match at newlines. */ +#define REG_NEWLINE (REG_ICASE << 1) + +/* If this bit is set, then report only success or fail in regexec. + If not set, then returns differ between not matching and errors. */ +#define REG_NOSUB (REG_NEWLINE << 1) + + +/* POSIX `eflags' bits (i.e., information for regexec). */ + +/* If this bit is set, then the beginning-of-line operator doesn't match + the beginning of the string (presumably because it's not the + beginning of a line). + If not set, then the beginning-of-line operator does match the + beginning of the string. */ +#define REG_NOTBOL 1 + +/* Like REG_NOTBOL, except for the end-of-line. */ +#define REG_NOTEOL (1 << 1) + +/* Use PMATCH[0] to delimit the start and end of the search in the + buffer. */ +#define REG_STARTEND (1 << 2) + + +/* If any error codes are removed, changed, or added, update the + `re_error_msg' table in regex.c. */ +typedef enum +{ +#ifdef _XOPEN_SOURCE + REG_ENOSYS = -1, /* This will never happen for this implementation. */ +#endif + + REG_NOERROR = 0, /* Success. */ + REG_NOMATCH, /* Didn't find a match (for regexec). */ + + /* POSIX regcomp return error codes. (In the order listed in the + standard.) */ + REG_BADPAT, /* Invalid pattern. */ + REG_ECOLLATE, /* Inalid collating element. */ + REG_ECTYPE, /* Invalid character class name. */ + REG_EESCAPE, /* Trailing backslash. */ + REG_ESUBREG, /* Invalid back reference. */ + REG_EBRACK, /* Unmatched left bracket. */ + REG_EPAREN, /* Parenthesis imbalance. */ + REG_EBRACE, /* Unmatched \{. */ + REG_BADBR, /* Invalid contents of \{\}. */ + REG_ERANGE, /* Invalid range end. */ + REG_ESPACE, /* Ran out of memory. */ + REG_BADRPT, /* No preceding re for repetition op. */ + + /* Error codes we've added. */ + REG_EEND, /* Premature end. */ + REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ + REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ +} reg_errcode_t; + +/* This data structure represents a compiled pattern. Before calling + the pattern compiler, the fields `buffer', `allocated', `fastmap', + `translate', and `no_sub' can be set. After the pattern has been + compiled, the `re_nsub' field is available. All other fields are + private to the regex routines. */ + +#ifndef RE_TRANSLATE_TYPE +# define RE_TRANSLATE_TYPE unsigned char * +#endif + +struct re_pattern_buffer +{ + /* Space that holds the compiled pattern. It is declared as + `unsigned char *' because its elements are sometimes used as + array indexes. */ + unsigned char *buffer; + + /* Number of bytes to which `buffer' points. */ + unsigned long int allocated; + + /* Number of bytes actually used in `buffer'. */ + unsigned long int used; + + /* Syntax setting with which the pattern was compiled. */ + reg_syntax_t syntax; + + /* Pointer to a fastmap, if any, otherwise zero. re_search uses the + fastmap, if there is one, to skip over impossible starting points + for matches. */ + char *fastmap; + + /* Either a translate table to apply to all characters before + comparing them, or zero for no translation. The translation is + applied to a pattern when it is compiled and to a string when it + is matched. */ + RE_TRANSLATE_TYPE translate; + + /* Number of subexpressions found by the compiler. */ + size_t re_nsub; + + /* Zero if this pattern cannot match the empty string, one else. + Well, in truth it's used only in `re_search_2', to see whether or + not we should use the fastmap, so we don't set this absolutely + perfectly; see `re_compile_fastmap' (the `duplicate' case). */ + unsigned can_be_null : 1; + + /* If REGS_UNALLOCATED, allocate space in the `regs' structure + for `max (RE_NREGS, re_nsub + 1)' groups. + If REGS_REALLOCATE, reallocate space if necessary. + If REGS_FIXED, use what's there. */ +#define REGS_UNALLOCATED 0 +#define REGS_REALLOCATE 1 +#define REGS_FIXED 2 + unsigned regs_allocated : 2; + + /* Set to zero when `regex_compile' compiles a pattern; set to one + by `re_compile_fastmap' if it updates the fastmap. */ + unsigned fastmap_accurate : 1; + + /* If set, `re_match_2' does not return information about + subexpressions. */ + unsigned no_sub : 1; + + /* If set, a beginning-of-line anchor doesn't match at the beginning + of the string. */ + unsigned not_bol : 1; + + /* Similarly for an end-of-line anchor. */ + unsigned not_eol : 1; + + /* If true, an anchor at a newline matches. */ + unsigned newline_anchor : 1; +}; + +typedef struct re_pattern_buffer regex_t; + +/* Type for byte offsets within the string. POSIX mandates this. */ +typedef int regoff_t; + + +/* This is the structure we store register match data in. See + regex.texinfo for a full description of what registers match. */ +struct re_registers +{ + unsigned num_regs; + regoff_t *start; + regoff_t *end; +}; + + +/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, + `re_match_2' returns information about at least this many registers + the first time a `regs' structure is passed. */ +#ifndef RE_NREGS +# define RE_NREGS 30 +#endif + + +/* POSIX specification for registers. Aside from the different names than + `re_registers', POSIX uses an array of structures, instead of a + structure of arrays. */ +typedef struct +{ + regoff_t rm_so; /* Byte offset from string's start to substring's start. */ + regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ +} regmatch_t; + +/* Declarations for routines. */ + +/* Sets the current default syntax to SYNTAX, and return the old syntax. + You can also simply assign to the `re_syntax_options' variable. */ +extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); + +/* Compile the regular expression PATTERN, with length LENGTH + and syntax given by the global `re_syntax_options', into the buffer + BUFFER. Return NULL if successful, and an error string if not. */ +extern const char *re_compile_pattern (const char *__pattern, size_t __length, + struct re_pattern_buffer *__buffer); + + +/* Compile a fastmap for the compiled pattern in BUFFER; used to + accelerate searches. Return 0 if successful and -2 if was an + internal error. */ +extern int re_compile_fastmap (struct re_pattern_buffer *__buffer); + + +/* Search in the string STRING (with length LENGTH) for the pattern + compiled into BUFFER. Start searching at position START, for RANGE + characters. Return the starting position of the match, -1 for no + match, or -2 for an internal error. Also return register + information in REGS (if REGS and BUFFER->no_sub are nonzero). */ +extern int re_search (struct re_pattern_buffer *__buffer, const char *__string, + int __length, int __start, int __range, + struct re_registers *__regs); + + +/* Like `re_search', but search in the concatenation of STRING1 and + STRING2. Also, stop searching at index START + STOP. */ +extern int re_search_2 (struct re_pattern_buffer *__buffer, + const char *__string1, int __length1, + const char *__string2, int __length2, int __start, + int __range, struct re_registers *__regs, int __stop); + + +/* Like `re_search', but return how many characters in STRING the regexp + in BUFFER matched, starting at position START. */ +extern int re_match (struct re_pattern_buffer *__buffer, const char *__string, + int __length, int __start, struct re_registers *__regs); + + +/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ +extern int re_match_2 (struct re_pattern_buffer *__buffer, + const char *__string1, int __length1, + const char *__string2, int __length2, int __start, + struct re_registers *__regs, int __stop); + + +/* Set REGS to hold NUM_REGS registers, storing them in STARTS and + ENDS. Subsequent matches using BUFFER and REGS will use this memory + for recording register information. STARTS and ENDS must be + allocated with malloc, and must each be at least `NUM_REGS * sizeof + (regoff_t)' bytes long. + + If NUM_REGS == 0, then subsequent matches should allocate their own + register data. + + Unless this function is called, the first search or match using + PATTERN_BUFFER will allocate its own register data, without + freeing the old data. */ +extern void re_set_registers (struct re_pattern_buffer *__buffer, + struct re_registers *__regs, + unsigned int __num_regs, + regoff_t *__starts, regoff_t *__ends); + +#if defined _REGEX_RE_COMP || defined _LIBC +# ifndef _CRAY +/* 4.2 bsd compatibility. */ +extern char *re_comp (const char *); +extern int re_exec (const char *); +# endif +#endif + +/* GCC 2.95 and later have "__restrict"; C99 compilers have + "restrict", and "configure" may have defined "restrict". */ +#ifndef __restrict +# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) +# if defined restrict || 199901L <= __STDC_VERSION__ +# define __restrict restrict +# else +# define __restrict +# endif +# endif +#endif +/* gcc 3.1 and up support the [restrict] syntax. */ +#ifndef __restrict_arr +# if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) \ + && !defined __GNUG__ +# define __restrict_arr __restrict +# else +# define __restrict_arr +# endif +#endif + +/* POSIX compatibility. */ +extern int regcomp (regex_t *__restrict __preg, + const char *__restrict __pattern, + int __cflags); + +extern int regexec (const regex_t *__restrict __preg, + const char *__restrict __string, size_t __nmatch, + regmatch_t __pmatch[__restrict_arr], + int __eflags); + +extern size_t regerror (int __errcode, const regex_t *__restrict __preg, + char *__restrict __errbuf, size_t __errbuf_size); + +extern void regfree (regex_t *__preg); + + +#ifdef __cplusplus +} +#endif /* C++ */ + +#endif /* regex.h */ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/BSD_(revised)_license.txt b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/BSD_(revised)_license.txt new file mode 100644 index 0000000..6785262 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/BSD_(revised)_license.txt @@ -0,0 +1,10 @@ +Copyright (c) 2005, The EasyBMP Project (http://easybmp.sourceforge.net) +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP.cpp b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP.cpp new file mode 100644 index 0000000..07d33ef --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP.cpp @@ -0,0 +1,1917 @@ +/************************************************* +* * +* EasyBMP Cross-Platform Windows Bitmap Library * +* * +* Author: Paul Macklin * +* email: macklin01@users.sourceforge.net * +* support: http://easybmp.sourceforge.net * +* * +* file: EasyBMP.cpp * +* date added: 03-31-2006 * +* date modified: 12-01-2006 * +* version: 1.06 * +* * +* License: BSD (revised/modified) * +* Copyright: 2005-6 by the EasyBMP Project * +* * +* description: Actual source file * +* * +*************************************************/ + +#include "EasyBMP.h" + +/* These functions are defined in EasyBMP.h */ + +bool EasyBMPwarnings = true; + +void SetEasyBMPwarningsOff( void ) +{ EasyBMPwarnings = false; } +void SetEasyBMPwarningsOn( void ) +{ EasyBMPwarnings = true; } +bool GetEasyBMPwarningState( void ) +{ return EasyBMPwarnings; } + +/* These functions are defined in EasyBMP_DataStructures.h */ + +int IntPow( int base, int exponent ) +{ + int i; + int output = 1; + for( i=0 ; i < exponent ; i++ ) + { output *= base; } + return output; +} + +BMFH::BMFH() +{ + bfType = 19778; + bfReserved1 = 0; + bfReserved2 = 0; +} + +void BMFH::SwitchEndianess( void ) +{ + bfType = FlipWORD( bfType ); + bfSize = FlipDWORD( bfSize ); + bfReserved1 = FlipWORD( bfReserved1 ); + bfReserved2 = FlipWORD( bfReserved2 ); + bfOffBits = FlipDWORD( bfOffBits ); + return; +} + +BMIH::BMIH() +{ + biPlanes = 1; + biCompression = 0; + biXPelsPerMeter = DefaultXPelsPerMeter; + biYPelsPerMeter = DefaultYPelsPerMeter; + biClrUsed = 0; + biClrImportant = 0; +} + +void BMIH::SwitchEndianess( void ) +{ + biSize = FlipDWORD( biSize ); + biWidth = FlipDWORD( biWidth ); + biHeight = FlipDWORD( biHeight ); + biPlanes = FlipWORD( biPlanes ); + biBitCount = FlipWORD( biBitCount ); + biCompression = FlipDWORD( biCompression ); + biSizeImage = FlipDWORD( biSizeImage ); + biXPelsPerMeter = FlipDWORD( biXPelsPerMeter ); + biYPelsPerMeter = FlipDWORD( biYPelsPerMeter ); + biClrUsed = FlipDWORD( biClrUsed ); + biClrImportant = FlipDWORD( biClrImportant ); + return; +} + +void BMIH::display( void ) +{ + using namespace std; + cout << "biSize: " << (int) biSize << endl + << "biWidth: " << (int) biWidth << endl + << "biHeight: " << (int) biHeight << endl + << "biPlanes: " << (int) biPlanes << endl + << "biBitCount: " << (int) biBitCount << endl + << "biCompression: " << (int) biCompression << endl + << "biSizeImage: " << (int) biSizeImage << endl + << "biXPelsPerMeter: " << (int) biXPelsPerMeter << endl + << "biYPelsPerMeter: " << (int) biYPelsPerMeter << endl + << "biClrUsed: " << (int) biClrUsed << endl + << "biClrImportant: " << (int) biClrImportant << endl << endl; +} + +void BMFH::display( void ) +{ + using namespace std; + cout << "bfType: " << (int) bfType << endl + << "bfSize: " << (int) bfSize << endl + << "bfReserved1: " << (int) bfReserved1 << endl + << "bfReserved2: " << (int) bfReserved2 << endl + << "bfOffBits: " << (int) bfOffBits << endl << endl; +} + +/* These functions are defined in EasyBMP_BMP.h */ + +RGBApixel BMP::GetPixel( int i, int j ) const +{ + using namespace std; + bool Warn = false; + if( i >= Width ) + { i = Width-1; Warn = true; } + if( i < 0 ) + { i = 0; Warn = true; } + if( j >= Height ) + { j = Height-1; Warn = true; } + if( j < 0 ) + { j = 0; Warn = true; } + if( Warn && EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to access non-existent pixel;" << endl + << " Truncating request to fit in the range [0," + << Width-1 << "] x [0," << Height-1 << "]." << endl; + } + return Pixels[i][j]; +} + +bool BMP::SetPixel( int i, int j, RGBApixel NewPixel ) +{ + Pixels[i][j] = NewPixel; + return true; +} + + +bool BMP::SetColor( int ColorNumber , RGBApixel NewColor ) +{ + using namespace std; + if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to change color table for a BMP object" << endl + << " that lacks a color table. Ignoring request." << endl; + } + return false; + } + if( !Colors ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to set a color, but the color table" << endl + << " is not defined. Ignoring request." << endl; + } + return false; + } + if( ColorNumber >= TellNumberOfColors() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Requested color number " + << ColorNumber << " is outside the allowed" << endl + << " range [0," << TellNumberOfColors()-1 + << "]. Ignoring request to set this color." << endl; + } + return false; + } + Colors[ColorNumber] = NewColor; + return true; +} + +// RGBApixel BMP::GetColor( int ColorNumber ) const +RGBApixel BMP::GetColor( int ColorNumber ) +{ + RGBApixel Output; + Output.Red = 255; + Output.Green = 255; + Output.Blue = 255; + Output.Alpha = 0; + + using namespace std; + if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to access color table for a BMP object" << endl + << " that lacks a color table. Ignoring request." << endl; + } + return Output; + } + if( !Colors ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Requested a color, but the color table" << endl + << " is not defined. Ignoring request." << endl; + } + return Output; + } + if( ColorNumber >= TellNumberOfColors() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Requested color number " + << ColorNumber << " is outside the allowed" << endl + << " range [0," << TellNumberOfColors()-1 + << "]. Ignoring request to get this color." << endl; + } + return Output; + } + Output = Colors[ColorNumber]; + return Output; +} + +BMP::BMP() +{ + Width = 1; + Height = 1; + BitDepth = 24; + Pixels = new RGBApixel* [Width]; + Pixels[0] = new RGBApixel [Height]; + Colors = NULL; + + XPelsPerMeter = 0; + YPelsPerMeter = 0; + + MetaData1 = NULL; + SizeOfMetaData1 = 0; + MetaData2 = NULL; + SizeOfMetaData2 = 0; +} + +// BMP::BMP( const BMP& Input ) +BMP::BMP( BMP& Input ) +{ + // first, make the image empty. + + Width = 1; + Height = 1; + BitDepth = 24; + Pixels = new RGBApixel* [Width]; + Pixels[0] = new RGBApixel [Height]; + Colors = NULL; + XPelsPerMeter = 0; + YPelsPerMeter = 0; + + MetaData1 = NULL; + SizeOfMetaData1 = 0; + MetaData2 = NULL; + SizeOfMetaData2 = 0; + + // now, set the correct bit depth + + SetBitDepth( Input.TellBitDepth() ); + + // set the correct pixel size + + SetSize( Input.TellWidth() , Input.TellHeight() ); + + // set the DPI information from Input + + SetDPI( Input.TellHorizontalDPI() , Input.TellVerticalDPI() ); + + // if there is a color table, get all the colors + + if( BitDepth == 1 || BitDepth == 4 || + BitDepth == 8 ) + { + for( int k=0 ; k < TellNumberOfColors() ; k++ ) + { + SetColor( k, Input.GetColor( k )); + } + } + + // get all the pixels + + for( int j=0; j < Height ; j++ ) + { + for( int i=0; i < Width ; i++ ) + { + Pixels[i][j] = *Input(i,j); +// Pixels[i][j] = Input.GetPixel(i,j); // *Input(i,j); + } + } +} + +BMP::~BMP() +{ + int i; + for(i=0;i= Width ) + { i = Width-1; Warn = true; } + if( i < 0 ) + { i = 0; Warn = true; } + if( j >= Height ) + { j = Height-1; Warn = true; } + if( j < 0 ) + { j = 0; Warn = true; } + if( Warn && EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to access non-existent pixel;" << endl + << " Truncating request to fit in the range [0," + << Width-1 << "] x [0," << Height-1 << "]." << endl; + } + return &(Pixels[i][j]); +} + +// int BMP::TellBitDepth( void ) const +int BMP::TellBitDepth( void ) +{ return BitDepth; } + +// int BMP::TellHeight( void ) const +int BMP::TellHeight( void ) +{ return Height; } + +// int BMP::TellWidth( void ) const +int BMP::TellWidth( void ) +{ return Width; } + +// int BMP::TellNumberOfColors( void ) const +int BMP::TellNumberOfColors( void ) +{ + int output = IntPow( 2, BitDepth ); + if( BitDepth == 32 ) + { output = IntPow( 2, 24 ); } + return output; +} + +bool BMP::SetBitDepth( int NewDepth ) +{ + using namespace std; + if( NewDepth != 1 && NewDepth != 4 && + NewDepth != 8 && NewDepth != 16 && + NewDepth != 24 && NewDepth != 32 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: User attempted to set unsupported bit depth " + << NewDepth << "." << endl + << " Bit depth remains unchanged at " + << BitDepth << "." << endl; + } + return false; + } + + BitDepth = NewDepth; + if( Colors ) + { delete [] Colors; } + int NumberOfColors = IntPow( 2, BitDepth ); + if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) + { Colors = new RGBApixel [NumberOfColors]; } + else + { Colors = NULL; } + if( BitDepth == 1 || BitDepth == 4 || BitDepth == 8 ) + { CreateStandardColorTable(); } + + return true; +} + +bool BMP::SetSize(int NewWidth , int NewHeight ) +{ + using namespace std; + if( NewWidth <= 0 || NewHeight <= 0 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: User attempted to set a non-positive width or height." << endl + << " Size remains unchanged at " + << Width << " x " << Height << "." << endl; + } + return false; + } + + int i,j; + + for(i=0;i -1 ) + { + bool Success = false; + if( BitDepth == 32 ) + { Success = Write32bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 24 ) + { Success = Write24bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 8 ) + { Success = Write8bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 4 ) + { Success = Write4bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 1 ) + { Success = Write1bitRow( Buffer, BufferSize, j ); } + if( Success ) + { + int BytesWritten = (int) fwrite( (char*) Buffer, 1, BufferSize, fp ); + if( BytesWritten != BufferSize ) + { Success = false; } + } + if( !Success ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Could not write proper amount of data." << endl; + } + j = -1; + } + j--; + } + + delete [] Buffer; + } + + if( BitDepth == 16 ) + { + // write the bit masks + + ebmpWORD BlueMask = 31; // bits 12-16 + ebmpWORD GreenMask = 2016; // bits 6-11 + ebmpWORD RedMask = 63488; // bits 1-5 + ebmpWORD ZeroWORD; + + if( IsBigEndian() ) + { RedMask = FlipWORD( RedMask ); } + fwrite( (char*) &RedMask , 2 , 1 , fp ); + fwrite( (char*) &ZeroWORD , 2 , 1 , fp ); + + if( IsBigEndian() ) + { GreenMask = FlipWORD( GreenMask ); } + fwrite( (char*) &GreenMask , 2 , 1 , fp ); + fwrite( (char*) &ZeroWORD , 2 , 1 , fp ); + + if( IsBigEndian() ) + { BlueMask = FlipWORD( BlueMask ); } + fwrite( (char*) &BlueMask , 2 , 1 , fp ); + fwrite( (char*) &ZeroWORD , 2 , 1 , fp ); + + int DataBytes = Width*2; + int PaddingBytes = ( 4 - DataBytes % 4 ) % 4; + + // write the actual pixels + + for( j=Height-1 ; j >= 0 ; j-- ) + //int WriteNumber; + //for(j=0, WriteNumber=0; j < Height; ++j) + { + // write all row pixel data + i=0; + int WriteNumber = 0; + while( WriteNumber < DataBytes ) + //for(i = 0; i 3, then something strange is going on + // it's probably an OS2 bitmap file. + + if( bmih.biCompression > 3 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName << " is in an unsupported format." + << endl + << " (bmih.biCompression = " + << bmih.biCompression << ")" << endl + << " The file is probably an old OS2 bitmap or corrupted." + << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + + if( bmih.biCompression == 3 && bmih.biBitCount != 16 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName + << " uses bit fields and is not a" << endl + << " 16-bit file. This is not supported." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + + // set the bit depth + + int TempBitDepth = (int) bmih.biBitCount; + if( TempBitDepth != 1 && TempBitDepth != 4 + && TempBitDepth != 8 && TempBitDepth != 16 + && TempBitDepth != 24 && TempBitDepth != 32 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName << " has unrecognized bit depth." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + SetBitDepth( (int) bmih.biBitCount ); + + // set the size + + if( (int) bmih.biWidth <= 0 || (int) bmih.biHeight <= 0 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: " << FileName + << " has a non-positive width or height." << endl; + } + SetSize(1,1); + SetBitDepth(1); + fclose(fp); + return false; + } + SetSize( (int) bmih.biWidth , (int) bmih.biHeight ); + + // some preliminaries + + double dBytesPerPixel = ( (double) BitDepth ) / 8.0; + double dBytesPerRow = dBytesPerPixel * (Width+0.0); + dBytesPerRow = ceil(dBytesPerRow); + + int BytePaddingPerRow = 4 - ( (int) (dBytesPerRow) )% 4; + if( BytePaddingPerRow == 4 ) + { BytePaddingPerRow = 0; } + + // if < 16 bits, read the palette + + if( BitDepth < 16 ) + { + // determine the number of colors specified in the + // color table + + int NumberOfColorsToRead = ((int) bmfh.bfOffBits - 54 )/4; + if( NumberOfColorsToRead > IntPow(2,BitDepth) ) + { NumberOfColorsToRead = IntPow(2,BitDepth); } + + if( NumberOfColorsToRead < TellNumberOfColors() ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: file " << FileName << " has an underspecified" << endl + << " color table. The table will be padded with extra" << endl + << " white (255,255,255,0) entries." << endl; + } + } + + int n; + for( n=0; n < NumberOfColorsToRead ; n++ ) + { + SafeFread( (char*) &(Colors[n]) , 4 , 1 , fp); + } + for( n=NumberOfColorsToRead ; n < TellNumberOfColors() ; n++ ) + { + RGBApixel WHITE; + WHITE.Red = 255; + WHITE.Green = 255; + WHITE.Blue = 255; + WHITE.Alpha = 0; + SetColor( n , WHITE ); + } + + + } + + // skip blank data if bfOffBits so indicates + + int BytesToSkip = bmfh.bfOffBits - 54;; + if( BitDepth < 16 ) + { BytesToSkip -= 4*IntPow(2,BitDepth); } + if( BitDepth == 16 && bmih.biCompression == 3 ) + { BytesToSkip -= 3*4; } + if( BytesToSkip < 0 ) + { BytesToSkip = 0; } + if( BytesToSkip > 0 && BitDepth != 16 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Extra meta data detected in file " << FileName << endl + << " Data will be skipped." << endl; + } + ebmpBYTE* TempSkipBYTE; + TempSkipBYTE = new ebmpBYTE [BytesToSkip]; + SafeFread( (char*) TempSkipBYTE , BytesToSkip , 1 , fp); + delete [] TempSkipBYTE; + } + + // This code reads 1, 4, 8, 24, and 32-bpp files + // with a more-efficient buffered technique. + + int i,j; + if( BitDepth != 16 ) + { + int BufferSize = (int) ( (Width*BitDepth) / 8.0 ); + while( 8*BufferSize < Width*BitDepth ) + { BufferSize++; } + while( BufferSize % 4 ) + { BufferSize++; } + ebmpBYTE* Buffer; + Buffer = new ebmpBYTE [BufferSize]; + j= Height-1; + while( j > -1 ) + { + int BytesRead = (int) fread( (char*) Buffer, 1, BufferSize, fp ); + if( BytesRead < BufferSize ) + { + j = -1; + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Could not read proper amount of data." << endl; + } + } + else + { + bool Success = false; + if( BitDepth == 1 ) + { Success = Read1bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 4 ) + { Success = Read4bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 8 ) + { Success = Read8bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 24 ) + { Success = Read24bitRow( Buffer, BufferSize, j ); } + if( BitDepth == 32 ) + { Success = Read32bitRow( Buffer, BufferSize, j ); } + if( !Success ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Could not read enough pixel data!" << endl; + } + j = -1; + } + } + j--; + } + delete [] Buffer; + } + + if( BitDepth == 16 ) + { + int DataBytes = Width*2; + int PaddingBytes = ( 4 - DataBytes % 4 ) % 4; + + // set the default mask + + ebmpWORD BlueMask = 31; // bits 12-16 + ebmpWORD GreenMask = 992; // bits 7-11 + ebmpWORD RedMask = 31744; // bits 2-6 + + // read the bit fields, if necessary, to + // override the default 5-5-5 mask + + if( bmih.biCompression != 0 ) + { + // read the three bit masks + + ebmpWORD TempMaskWORD; + ebmpWORD ZeroWORD=0; + + SafeFread( (char*) &RedMask , 2 , 1 , fp ); + if( IsBigEndian() ) + { RedMask = FlipWORD(RedMask); } + SafeFread( (char*) &TempMaskWORD , 2, 1, fp ); + + SafeFread( (char*) &GreenMask , 2 , 1 , fp ); + if( IsBigEndian() ) + { GreenMask = FlipWORD(GreenMask); } + SafeFread( (char*) &TempMaskWORD , 2, 1, fp ); + + SafeFread( (char*) &BlueMask , 2 , 1 , fp ); + if( IsBigEndian() ) + { BlueMask = FlipWORD(BlueMask); } + SafeFread( (char*) &TempMaskWORD , 2, 1, fp ); + } + + // read and skip any meta data + + if( BytesToSkip > 0 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Extra meta data detected in file " + << FileName << endl + << " Data will be skipped." << endl; + } + ebmpBYTE* TempSkipBYTE; + TempSkipBYTE = new ebmpBYTE [BytesToSkip]; + SafeFread( (char*) TempSkipBYTE , BytesToSkip , 1 , fp); + delete [] TempSkipBYTE; + } + + // determine the red, green and blue shifts + + int GreenShift = 0; + ebmpWORD TempShiftWORD = GreenMask; + while( TempShiftWORD > 31 ) + { TempShiftWORD = TempShiftWORD>>1; GreenShift++; } + int BlueShift = 0; + TempShiftWORD = BlueMask; + while( TempShiftWORD > 31 ) + { TempShiftWORD = TempShiftWORD>>1; BlueShift++; } + int RedShift = 0; + TempShiftWORD = RedMask; + while( TempShiftWORD > 31 ) + { TempShiftWORD = TempShiftWORD>>1; RedShift++; } + + // read the actual pixels + + for( j=Height-1 ; j >= 0 ; j-- ) + { + i=0; + int ReadNumber = 0; + while( ReadNumber < DataBytes ) + { + ebmpWORD TempWORD; + SafeFread( (char*) &TempWORD , 2 , 1 , fp ); + if( IsBigEndian() ) + { TempWORD = FlipWORD(TempWORD); } + ReadNumber += 2; + + ebmpWORD Red = RedMask & TempWORD; + ebmpWORD Green = GreenMask & TempWORD; + ebmpWORD Blue = BlueMask & TempWORD; + + ebmpBYTE BlueBYTE = (ebmpBYTE) 8*(Blue>>BlueShift); + ebmpBYTE GreenBYTE = (ebmpBYTE) 8*(Green>>GreenShift); + ebmpBYTE RedBYTE = (ebmpBYTE) 8*(Red>>RedShift); + + (Pixels[i][j]).Red = RedBYTE; + (Pixels[i][j]).Green = GreenBYTE; + (Pixels[i][j]).Blue = BlueBYTE; + + i++; + } + ReadNumber = 0; + while( ReadNumber < PaddingBytes ) + { + ebmpBYTE TempBYTE; + SafeFread( (char*) &TempBYTE , 1, 1, fp); + ReadNumber++; + } + } + + } + + fclose(fp); + return true; +} + +bool BMP::CreateStandardColorTable( void ) +{ + using namespace std; + if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to create color table at a bit" << endl + << " depth that does not require a color table." << endl + << " Ignoring request." << endl; + } + return false; + } + + if( BitDepth == 1 ) + { + int i; + for( i=0 ; i < 2 ; i++ ) + { + Colors[i].Red = i*255; + Colors[i].Green = i*255; + Colors[i].Blue = i*255; + Colors[i].Alpha = 0; + } + return true; + } + + if( BitDepth == 4 ) + { + int i = 0; + int j,k,ell; + + // simplify the code for the first 8 colors + for( ell=0 ; ell < 2 ; ell++ ) + { + for( k=0 ; k < 2 ; k++ ) + { + for( j=0 ; j < 2 ; j++ ) + { + Colors[i].Red = j*128; + Colors[i].Green = k*128; + Colors[i].Blue = ell*128; + i++; + } + } + } + + // simplify the code for the last 8 colors + for( ell=0 ; ell < 2 ; ell++ ) + { + for( k=0 ; k < 2 ; k++ ) + { + for( j=0 ; j < 2 ; j++ ) + { + Colors[i].Red = j*255; + Colors[i].Green = k*255; + Colors[i].Blue = ell*255; + i++; + } + } + } + + // overwrite the duplicate color + i=8; + Colors[i].Red = 192; + Colors[i].Green = 192; + Colors[i].Blue = 192; + + for( i=0 ; i < 16 ; i++ ) + { Colors[i].Alpha = 0; } + return true; + } + + if( BitDepth == 8 ) + { + int i=0; + int j,k,ell; + + // do an easy loop, which works for all but colors + // 0 to 9 and 246 to 255 + for( ell=0 ; ell < 4 ; ell++ ) + { + for( k=0 ; k < 8 ; k++ ) + { + for( j=0; j < 8 ; j++ ) + { + Colors[i].Red = j*32; + Colors[i].Green = k*32; + Colors[i].Blue = ell*64; + Colors[i].Alpha = 0; + i++; + } + } + } + + // now redo the first 8 colors + i=0; + for( ell=0 ; ell < 2 ; ell++ ) + { + for( k=0 ; k < 2 ; k++ ) + { + for( j=0; j < 2 ; j++ ) + { + Colors[i].Red = j*128; + Colors[i].Green = k*128; + Colors[i].Blue = ell*128; + i++; + } + } + } + + // overwrite colors 7, 8, 9 + i=7; + Colors[i].Red = 192; + Colors[i].Green = 192; + Colors[i].Blue = 192; + i++; // 8 + Colors[i].Red = 192; + Colors[i].Green = 220; + Colors[i].Blue = 192; + i++; // 9 + Colors[i].Red = 166; + Colors[i].Green = 202; + Colors[i].Blue = 240; + + // overwrite colors 246 to 255 + i=246; + Colors[i].Red = 255; + Colors[i].Green = 251; + Colors[i].Blue = 240; + i++; // 247 + Colors[i].Red = 160; + Colors[i].Green = 160; + Colors[i].Blue = 164; + i++; // 248 + Colors[i].Red = 128; + Colors[i].Green = 128; + Colors[i].Blue = 128; + i++; // 249 + Colors[i].Red = 255; + Colors[i].Green = 0; + Colors[i].Blue = 0; + i++; // 250 + Colors[i].Red = 0; + Colors[i].Green = 255; + Colors[i].Blue = 0; + i++; // 251 + Colors[i].Red = 255; + Colors[i].Green = 255; + Colors[i].Blue = 0; + i++; // 252 + Colors[i].Red = 0; + Colors[i].Green = 0; + Colors[i].Blue = 255; + i++; // 253 + Colors[i].Red = 255; + Colors[i].Green = 0; + Colors[i].Blue = 255; + i++; // 254 + Colors[i].Red = 0; + Colors[i].Green = 255; + Colors[i].Blue = 255; + i++; // 255 + Colors[i].Red = 255; + Colors[i].Green = 255; + Colors[i].Blue = 255; + + return true; + } + return true; +} + +bool SafeFread( char* buffer, int size, int number, FILE* fp ) +{ + using namespace std; + int ItemsRead; + if( feof(fp) ) + { return false; } + ItemsRead = (int) fread( buffer , size , number , fp ); + if( ItemsRead < number ) + { return false; } + return true; +} + +void BMP::SetDPI( int HorizontalDPI, int VerticalDPI ) +{ + XPelsPerMeter = (int) ( HorizontalDPI * 39.37007874015748 ); + YPelsPerMeter = (int) ( VerticalDPI * 39.37007874015748 ); +} + +// int BMP::TellVerticalDPI( void ) const +int BMP::TellVerticalDPI( void ) +{ + if( !YPelsPerMeter ) + { YPelsPerMeter = DefaultYPelsPerMeter; } + return (int) ( YPelsPerMeter / (double) 39.37007874015748 ); +} + +// int BMP::TellHorizontalDPI( void ) const +int BMP::TellHorizontalDPI( void ) +{ + if( !XPelsPerMeter ) + { XPelsPerMeter = DefaultXPelsPerMeter; } + return (int) ( XPelsPerMeter / (double) 39.37007874015748 ); +} + +/* These functions are defined in EasyBMP_VariousBMPutilities.h */ + +BMFH GetBMFH( const char* szFileNameIn ) +{ + using namespace std; + BMFH bmfh; + + FILE* fp; + fp = fopen( szFileNameIn,"rb"); + + if( !fp ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Cannot initialize from file " + << szFileNameIn << "." << endl + << " File cannot be opened or does not exist." + << endl; + } + bmfh.bfType = 0; + return bmfh; + } + + SafeFread( (char*) &(bmfh.bfType) , sizeof(ebmpWORD) , 1 , fp ); + SafeFread( (char*) &(bmfh.bfSize) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmfh.bfReserved1) , sizeof(ebmpWORD) , 1 , fp ); + SafeFread( (char*) &(bmfh.bfReserved2) , sizeof(ebmpWORD) , 1 , fp ); + SafeFread( (char*) &(bmfh.bfOffBits) , sizeof(ebmpDWORD) , 1 , fp ); + + fclose( fp ); + + if( IsBigEndian() ) + { bmfh.SwitchEndianess(); } + + return bmfh; +} + +BMIH GetBMIH( const char* szFileNameIn ) +{ + using namespace std; + BMFH bmfh; + BMIH bmih; + + FILE* fp; + fp = fopen( szFileNameIn,"rb"); + + if( !fp ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Cannot initialize from file " + << szFileNameIn << "." << endl + << " File cannot be opened or does not exist." + << endl; + } + return bmih; + } + + // read the bmfh, i.e., first 14 bytes (just to get it out of the way); + + ebmpBYTE TempBYTE; + int i; + for( i = 14 ; i > 0 ; i-- ) + { SafeFread( (char*) &TempBYTE , sizeof(ebmpBYTE) , 1, fp ); } + + // read the bmih + + SafeFread( (char*) &(bmih.biSize) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biWidth) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biHeight) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biPlanes) , sizeof(ebmpWORD) , 1 , fp ); + + SafeFread( (char*) &(bmih.biBitCount) , sizeof(ebmpWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biCompression) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biSizeImage) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biXPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp ); + + SafeFread( (char*) &(bmih.biYPelsPerMeter) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biClrUsed) , sizeof(ebmpDWORD) , 1 , fp ); + SafeFread( (char*) &(bmih.biClrImportant) , sizeof(ebmpDWORD) , 1 , fp ); + + fclose( fp ); + + if( IsBigEndian() ) + { bmih.SwitchEndianess(); } + + return bmih; +} + +void DisplayBitmapInfo( const char* szFileNameIn ) +{ + using namespace std; + FILE* fp; + fp = fopen( szFileNameIn,"rb"); + + if( !fp ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: Cannot initialize from file " + << szFileNameIn << "." << endl + << " File cannot be opened or does not exist." + << endl; + } + return; + } + fclose( fp ); + + // don't duplicate work! Just use the functions from above! + + BMFH bmfh = GetBMFH(szFileNameIn); + BMIH bmih = GetBMIH(szFileNameIn); + + cout << "File information for file " << szFileNameIn + << ":" << endl << endl; + + cout << "BITMAPFILEHEADER:" << endl + << "bfType: " << bmfh.bfType << endl + << "bfSize: " << bmfh.bfSize << endl + << "bfReserved1: " << bmfh.bfReserved1 << endl + << "bfReserved2: " << bmfh.bfReserved2 << endl + << "bfOffBits: " << bmfh.bfOffBits << endl << endl; + + cout << "BITMAPINFOHEADER:" << endl + << "biSize: " << bmih.biSize << endl + << "biWidth: " << bmih.biWidth << endl + << "biHeight: " << bmih.biHeight << endl + << "biPlanes: " << bmih.biPlanes << endl + << "biBitCount: " << bmih.biBitCount << endl + << "biCompression: " << bmih.biCompression << endl + << "biSizeImage: " << bmih.biSizeImage << endl + << "biXPelsPerMeter: " << bmih.biXPelsPerMeter << endl + << "biYPelsPerMeter: " << bmih.biYPelsPerMeter << endl + << "biClrUsed: " << bmih.biClrUsed << endl + << "biClrImportant: " << bmih.biClrImportant << endl << endl; + return; +} + +int GetBitmapColorDepth( const char* szFileNameIn ) +{ + BMIH bmih = GetBMIH( szFileNameIn ); + return (int) bmih.biBitCount; +} + +void PixelToPixelCopy( BMP& From, int FromX, int FromY, + BMP& To, int ToX, int ToY) +{ + *To(ToX,ToY) = *From(FromX,FromY); + return; +} + +void PixelToPixelCopyTransparent( BMP& From, int FromX, int FromY, + BMP& To, int ToX, int ToY, + RGBApixel& Transparent ) +{ + if( From(FromX,FromY)->Red != Transparent.Red || + From(FromX,FromY)->Green != Transparent.Green || + From(FromX,FromY)->Blue != Transparent.Blue ) + { *To(ToX,ToY) = *From(FromX,FromY); } + return; +} + +void RangedPixelToPixelCopy( BMP& From, int FromL , int FromR, int FromB, int FromT, + BMP& To, int ToX, int ToY ) +{ + // make sure the conventions are followed + if( FromB < FromT ) + { int Temp = FromT; FromT = FromB; FromB = Temp; } + + // make sure that the copied regions exist in both bitmaps + if( FromR >= From.TellWidth() ) + { FromR = From.TellWidth()-1; } + if( FromL < 0 ){ FromL = 0; } + + if( FromB >= From.TellHeight() ) + { FromB = From.TellHeight()-1; } + if( FromT < 0 ){ FromT = 0; } + + if( ToX+(FromR-FromL) >= To.TellWidth() ) + { FromR = To.TellWidth()-1+FromL-ToX; } + if( ToY+(FromB-FromT) >= To.TellHeight() ) + { FromB = To.TellHeight()-1+FromT-ToY; } + + int i,j; + for( j=FromT ; j <= FromB ; j++ ) + { + for( i=FromL ; i <= FromR ; i++ ) + { + PixelToPixelCopy( From, i,j, + To, ToX+(i-FromL), ToY+(j-FromT) ); + } + } + + return; +} + +void RangedPixelToPixelCopyTransparent( + BMP& From, int FromL , int FromR, int FromB, int FromT, + BMP& To, int ToX, int ToY , + RGBApixel& Transparent ) +{ + // make sure the conventions are followed + if( FromB < FromT ) + { int Temp = FromT; FromT = FromB; FromB = Temp; } + + // make sure that the copied regions exist in both bitmaps + if( FromR >= From.TellWidth() ) + { FromR = From.TellWidth()-1; } + if( FromL < 0 ){ FromL = 0; } + + if( FromB >= From.TellHeight() ) + { FromB = From.TellHeight()-1; } + if( FromT < 0 ){ FromT = 0; } + + if( ToX+(FromR-FromL) >= To.TellWidth() ) + { FromR = To.TellWidth()-1+FromL-ToX; } + if( ToY+(FromB-FromT) >= To.TellHeight() ) + { FromB = To.TellHeight()-1+FromT-ToY; } + + int i,j; + for( j=FromT ; j <= FromB ; j++ ) + { + for( i=FromL ; i <= FromR ; i++ ) + { + PixelToPixelCopyTransparent( From, i,j, + To, ToX+(i-FromL), ToY+(j-FromT) , + Transparent); + } + } + + return; +} + +bool CreateGrayscaleColorTable( BMP& InputImage ) +{ + using namespace std; + int BitDepth = InputImage.TellBitDepth(); + if( BitDepth != 1 && BitDepth != 4 && BitDepth != 8 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Warning: Attempted to create color table at a bit" << endl + << " depth that does not require a color table." << endl + << " Ignoring request." << endl; + } + return false; + } + int i; + int NumberOfColors = InputImage.TellNumberOfColors(); + + ebmpBYTE StepSize; + if( BitDepth != 1 ) + { StepSize = 255/(NumberOfColors-1); } + else + { StepSize = 255; } + + for( i=0 ; i < NumberOfColors ; i++ ) + { + ebmpBYTE TempBYTE = i*StepSize; + RGBApixel TempColor; + TempColor.Red = TempBYTE; + TempColor.Green = TempBYTE; + TempColor.Blue = TempBYTE; + TempColor.Alpha = 0; + InputImage.SetColor( i , TempColor ); + } + return true; +} + +bool BMP::Read32bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int i; + if( Width*4 > BufferSize ) + { return false; } + for( i=0 ; i < Width ; i++ ) + { memcpy( (char*) &(Pixels[i][Row]), (char*) Buffer+4*i, 4 ); } + return true; +} + +bool BMP::Read24bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int i; + if( Width*3 > BufferSize ) + { return false; } + for( i=0 ; i < Width ; i++ ) + { memcpy( (char*) &(Pixels[i][Row]), Buffer+3*i, 3 ); } + return true; +} + +bool BMP::Read8bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int i; + if( Width > BufferSize ) + { return false; } + for( i=0 ; i < Width ; i++ ) + { + int Index = Buffer[i]; + *( this->operator()(i,Row) )= GetColor(Index); + } + return true; +} + +bool BMP::Read4bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int Shifts[2] = {4 ,0 }; + int Masks[2] = {240,15}; + + int i=0; + int j; + int k=0; + if( Width > 2*BufferSize ) + { return false; } + while( i < Width ) + { + j=0; + while( j < 2 && i < Width ) + { + int Index = (int) ( (Buffer[k]&Masks[j]) >> Shifts[j]); + *( this->operator()(i,Row) )= GetColor(Index); + i++; j++; + } + k++; + } + return true; +} +bool BMP::Read1bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int Shifts[8] = {7 ,6 ,5 ,4 ,3,2,1,0}; + int Masks[8] = {128,64,32,16,8,4,2,1}; + + int i=0; + int j; + int k=0; + + if( Width > 8*BufferSize ) + { return false; } + while( i < Width ) + { + j=0; + while( j < 8 && i < Width ) + { + int Index = (int) ( (Buffer[k]&Masks[j]) >> Shifts[j]); + *( this->operator()(i,Row) )= GetColor(Index); + i++; j++; + } + k++; + } + return true; +} + +bool BMP::Write32bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int i; + if( Width*4 > BufferSize ) + { return false; } + for( i=0 ; i < Width ; i++ ) + { memcpy( (char*) Buffer+4*i, (char*) &(Pixels[i][Row]), 4 ); } + return true; +} + +bool BMP::Write24bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int i; + if( Width*3 > BufferSize ) + { return false; } + for( i=0 ; i < Width ; i++ ) + { memcpy( (char*) Buffer+3*i, (char*) &(Pixels[i][Row]), 3 ); } + return true; +} + +bool BMP::Write8bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int i; + if( Width > BufferSize ) + { return false; } + for( i=0 ; i < Width ; i++ ) + { Buffer[i] = FindClosestColor( Pixels[i][Row] ); } + return true; +} + +bool BMP::Write4bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int PositionWeights[2] = {16,1}; + + int i=0; + int j; + int k=0; + if( Width > 2*BufferSize ) + { return false; } + while( i < Width ) + { + j=0; + int Index = 0; + while( j < 2 && i < Width ) + { + Index += ( PositionWeights[j]* (int) FindClosestColor( Pixels[i][Row] ) ); + i++; j++; + } + Buffer[k] = (ebmpBYTE) Index; + k++; + } + return true; +} + +bool BMP::Write1bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ) +{ + int PositionWeights[8] = {128,64,32,16,8,4,2,1}; + + int i=0; + int j; + int k=0; + if( Width > 8*BufferSize ) + { return false; } + while( i < Width ) + { + j=0; + int Index = 0; + while( j < 8 && i < Width ) + { + Index += ( PositionWeights[j]* (int) FindClosestColor( Pixels[i][Row] ) ); + i++; j++; + } + Buffer[k] = (ebmpBYTE) Index; + k++; + } + return true; +} + +ebmpBYTE BMP::FindClosestColor( RGBApixel& input ) +{ + using namespace std; + + int i=0; + int NumberOfColors = TellNumberOfColors(); + ebmpBYTE BestI = 0; + int BestMatch = 999999; + + while( i < NumberOfColors ) + { + RGBApixel Attempt = GetColor( i ); + int TempMatch = IntSquare( (int) Attempt.Red - (int) input.Red ) + + IntSquare( (int) Attempt.Green - (int) input.Green ) + + IntSquare( (int) Attempt.Blue - (int) input.Blue ); + if( TempMatch < BestMatch ) + { BestI = (ebmpBYTE) i; BestMatch = TempMatch; } + if( BestMatch < 1 ) + { i = NumberOfColors; } + i++; + } + return BestI; +} + +bool EasyBMPcheckDataSize( void ) +{ + using namespace std; + bool ReturnValue = true; + if( sizeof( ebmpBYTE ) != 1 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: ebmpBYTE has the wrong size (" + << sizeof( ebmpBYTE ) << " bytes)," << endl + << " Compared to the expected 1 byte value" << endl; + } + ReturnValue = false; + } + if( sizeof( ebmpWORD ) != 2 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: ebmpWORD has the wrong size (" + << sizeof( ebmpWORD ) << " bytes)," << endl + << " Compared to the expected 2 byte value" << endl; + } + ReturnValue = false; + } + if( sizeof( ebmpDWORD ) != 4 ) + { + if( EasyBMPwarnings ) + { + cout << "EasyBMP Error: ebmpDWORD has the wrong size (" + << sizeof( ebmpDWORD ) << " bytes)," << endl + << " Compared to the expected 4 byte value" << endl; + } + ReturnValue = false; + } + return ReturnValue; +} + +bool Rescale( BMP& InputImage , char mode, ScaleParam scale ) +{ + using namespace std; + int CapMode = toupper( mode ); + + BMP OldImage( InputImage ); + + if( CapMode != 'P' && + CapMode != 'W' && + CapMode != 'H' && + CapMode != 'F' && + CapMode != 'D' ) + { + if( EasyBMPwarnings ) + { + char ErrorMessage [1024]; + sprintf( ErrorMessage, "EasyBMP Error: Unknown rescale mode %c requested\n" , mode ); + cout << ErrorMessage; + } + return false; + } + + int NewWidth =0; + int NewHeight =0; + + int OldWidth = OldImage.TellWidth(); + int OldHeight= OldImage.TellHeight(); + + if( CapMode == 'P' ) + { + NewWidth = (int) floor( OldWidth * scale.ratio / 100.0 ); + NewHeight = (int) floor( OldHeight * scale.ratio / 100.0 ); + } + if( CapMode == 'F' ) + { + if( OldWidth > OldHeight ) + { CapMode = 'W'; } + else + { CapMode = 'H'; } + } + + if( CapMode == 'W' ) + { + double percent = (double) scale.keepsize / (double) OldWidth; + NewWidth = scale.keepsize; + NewHeight = (int) floor( OldHeight * percent ); + } + if( CapMode == 'H' ) + { + double percent = (double) scale.keepsize / (double) OldHeight; + NewHeight = scale.keepsize; + NewWidth = (int) floor( OldWidth * percent ); + } + + if( CapMode == 'D') + { + NewWidth = scale.dimension.width; + NewHeight = scale.dimension.height; + } + + if( NewWidth < 1 ) + { NewWidth = 1; } + if( NewHeight < 1 ) + { NewHeight = 1; } + + InputImage.SetSize( NewWidth, NewHeight ); + InputImage.SetBitDepth( 24 ); + + int I,J; + double ThetaI,ThetaJ; + + for( int j=0; j < NewHeight-1 ; j++ ) + { + ThetaJ = (double)(j*(OldHeight-1.0)) + /(double)(NewHeight-1.0); + J = (int) floor( ThetaJ ); + ThetaJ -= J; + + for( int i=0; i < NewWidth-1 ; i++ ) + { + ThetaI = (double)(i*(OldWidth-1.0)) + /(double)(NewWidth-1.0); + I = (int) floor( ThetaI ); + ThetaI -= I; + + InputImage(i,j)->Red = (ebmpBYTE) + ( (1.0-ThetaI-ThetaJ+ThetaI*ThetaJ)*(OldImage(I,J)->Red) + +(ThetaI-ThetaI*ThetaJ)*(OldImage(I+1,J)->Red) + +(ThetaJ-ThetaI*ThetaJ)*(OldImage(I,J+1)->Red) + +(ThetaI*ThetaJ)*(OldImage(I+1,J+1)->Red) ); + InputImage(i,j)->Green = (ebmpBYTE) + ( (1.0-ThetaI-ThetaJ+ThetaI*ThetaJ)*OldImage(I,J)->Green + +(ThetaI-ThetaI*ThetaJ)*OldImage(I+1,J)->Green + +(ThetaJ-ThetaI*ThetaJ)*OldImage(I,J+1)->Green + +(ThetaI*ThetaJ)*OldImage(I+1,J+1)->Green ); + InputImage(i,j)->Blue = (ebmpBYTE) + ( (1.0-ThetaI-ThetaJ+ThetaI*ThetaJ)*OldImage(I,J)->Blue + +(ThetaI-ThetaI*ThetaJ)*OldImage(I+1,J)->Blue + +(ThetaJ-ThetaI*ThetaJ)*OldImage(I,J+1)->Blue + +(ThetaI*ThetaJ)*OldImage(I+1,J+1)->Blue ); + } + InputImage(NewWidth-1,j)->Red = (ebmpBYTE) + ( (1.0-ThetaJ)*(OldImage(OldWidth-1,J)->Red) + + ThetaJ*(OldImage(OldWidth-1,J+1)->Red) ); + InputImage(NewWidth-1,j)->Green = (ebmpBYTE) + ( (1.0-ThetaJ)*(OldImage(OldWidth-1,J)->Green) + + ThetaJ*(OldImage(OldWidth-1,J+1)->Green) ); + InputImage(NewWidth-1,j)->Blue = (ebmpBYTE) + ( (1.0-ThetaJ)*(OldImage(OldWidth-1,J)->Blue) + + ThetaJ*(OldImage(OldWidth-1,J+1)->Blue) ); + } + + for( int i=0 ; i < NewWidth-1 ; i++ ) + { + ThetaI = (double)(i*(OldWidth-1.0)) + /(double)(NewWidth-1.0); + I = (int) floor( ThetaI ); + ThetaI -= I; + InputImage(i,NewHeight-1)->Red = (ebmpBYTE) + ( (1.0-ThetaI)*(OldImage(I,OldHeight-1)->Red) + + ThetaI*(OldImage(I,OldHeight-1)->Red) ); + InputImage(i,NewHeight-1)->Green = (ebmpBYTE) + ( (1.0-ThetaI)*(OldImage(I,OldHeight-1)->Green) + + ThetaI*(OldImage(I,OldHeight-1)->Green) ); + InputImage(i,NewHeight-1)->Blue = (ebmpBYTE) + ( (1.0-ThetaI)*(OldImage(I,OldHeight-1)->Blue) + + ThetaI*(OldImage(I,OldHeight-1)->Blue) ); + } + + *InputImage(NewWidth-1,NewHeight-1) = *OldImage(OldWidth-1,OldHeight-1); + return true; +} diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP.h b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP.h new file mode 100644 index 0000000..52012db --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP.h @@ -0,0 +1,86 @@ +/************************************************* +* * +* EasyBMP Cross-Platform Windows Bitmap Library * +* * +* Author: Paul Macklin * +* email: macklin01@users.sourceforge.net * +* support: http://easybmp.sourceforge.net * +* * +* file: EasyBMP.h * +* date added: 01-31-2005 * +* date modified: 12-01-2006 * +* version: 1.06 * +* * +* License: BSD (revised/modified) * +* Copyright: 2005-6 by the EasyBMP Project * +* * +* description: Main include file * +* * +*************************************************/ + +#ifdef _MSC_VER +// MS Visual Studio gives warnings when using +// fopen. But fopen_s is not going to work well +// with most compilers, and fopen_s uses different +// syntax than fopen. (i.e., a macro won't work) +// So, we'lll use this: +#define _CRT_SECURE_NO_DEPRECATE +#endif + +#include +#include +#include +#include + +#ifndef EasyBMP +#define EasyBMP + +#ifdef __BCPLUSPLUS__ +// The Borland compiler must use this because something +// is wrong with their cstdio file. +#include +#else +#include +#endif + +#ifdef __GNUC__ +// If g++ specific code is ever required, this is +// where it goes. +#endif + +#ifdef __INTEL_COMPILER +// If Intel specific code is ever required, this is +// where it goes. +#endif + +#ifndef _DefaultXPelsPerMeter_ +#define _DefaultXPelsPerMeter_ +#define DefaultXPelsPerMeter 3780 +// set to a default of 96 dpi +#endif + +#ifndef _DefaultYPelsPerMeter_ +#define _DefaultYPelsPerMeter_ +#define DefaultYPelsPerMeter 3780 +// set to a default of 96 dpi +#endif + +#include "EasyBMP_DataStructures.h" +#include "EasyBMP_BMP.h" +#include "EasyBMP_VariousBMPutilities.h" + +#ifndef _EasyBMP_Version_ +#define _EasyBMP_Version_ 1.06 +#define _EasyBMP_Version_Integer_ 106 +#define _EasyBMP_Version_String_ "1.06" +#endif + +#ifndef _EasyBMPwarnings_ +#define _EasyBMPwarnings_ +#endif + +void SetEasyBMPwarningsOff( void ); +void SetEasyBMPwarningsOn( void ); +bool GetEasyBMPwarningState( void ); + +#endif diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_BMP.h b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_BMP.h new file mode 100644 index 0000000..7161435 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_BMP.h @@ -0,0 +1,86 @@ +/************************************************* +* * +* EasyBMP Cross-Platform Windows Bitmap Library * +* * +* Author: Paul Macklin * +* email: macklin01@users.sourceforge.net * +* support: http://easybmp.sourceforge.net * +* * +* file: EasyBMP_VariousBMPutilities.h * +* date added: 05-02-2005 * +* date modified: 12-01-2006 * +* version: 1.06 * +* * +* License: BSD (revised/modified) * +* Copyright: 2005-6 by the EasyBMP Project * +* * +* description: Defines BMP class * +* * +*************************************************/ + +#ifndef _EasyBMP_BMP_h_ +#define _EasyBMP_BMP_h_ + +bool SafeFread( char* buffer, int size, int number, FILE* fp ); +bool EasyBMPcheckDataSize( void ); + +class BMP +{private: + + int BitDepth; + int Width; + int Height; + RGBApixel** Pixels; + RGBApixel* Colors; + int XPelsPerMeter; + int YPelsPerMeter; + + ebmpBYTE* MetaData1; + int SizeOfMetaData1; + ebmpBYTE* MetaData2; + int SizeOfMetaData2; + + bool Read32bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Read24bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Read8bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Read4bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Read1bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + + bool Write32bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Write24bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Write8bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Write4bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + bool Write1bitRow( ebmpBYTE* Buffer, int BufferSize, int Row ); + + ebmpBYTE FindClosestColor( RGBApixel& input ); + + public: + + int TellBitDepth( void ); + int TellWidth( void ); + int TellHeight( void ); + int TellNumberOfColors( void ); + void SetDPI( int HorizontalDPI, int VerticalDPI ); + int TellVerticalDPI( void ); + int TellHorizontalDPI( void ); + + BMP(); + BMP( BMP& Input ); + ~BMP(); + RGBApixel* operator()(int i,int j); + + RGBApixel GetPixel( int i, int j ) const; + bool SetPixel( int i, int j, RGBApixel NewPixel ); + + bool CreateStandardColorTable( void ); + + bool SetSize( int NewWidth, int NewHeight ); + bool SetBitDepth( int NewDepth ); + bool WriteToFile( const char* FileName ); + bool ReadFromFile( const char* FileName ); + + RGBApixel GetColor( int ColorNumber ); + bool SetColor( int ColorNumber, RGBApixel NewColor ); +}; + +#endif diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_ChangeLog.txt b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_ChangeLog.txt new file mode 100644 index 0000000..b0a2c14 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_ChangeLog.txt @@ -0,0 +1,821 @@ +EasyBMP Cross-Platform Windows Bitmap Library: Change Log + +Library Author(s): Paul Macklin + Library License: BSD (revised). See the BSD_(revised)_license.txt + file for further information. + Copyright: 2005-6 by the EasyBMP Project + Email: macklin01@users.sourceforge.net + Support: http://easybmp.sourceforge.net + +All changes by Paul Macklin unless otherwise noted. + +*--------------------------------------------------------------------* + +Version: 0.50 + Date: 1-31-2005 + + None! (first release) + +*--------------------------------------------------------------------* + +Version: 0.51 + Date: 2-14-2005 + + Added full 32-bit BMP file support + + Took out annoying "colors: " message from BMP8 initialization + from scratch + + Added more license and copyright info to each file + + Added change log to library + + To do next: + Should update the error messages for the initializations + Should simplify the reading and writing code + +*--------------------------------------------------------------------* + +Version: 0.52 + Date: 2-19-2005 + + Fixed a minor bug in the MakeGreyscalePalette function where the + 0 color turned out to be (255,255,255), rather than (0,0,0) + + Updated standard colors for 4-bit, 8-bit, and 24-bit + +*--------------------------------------------------------------------* + +Version: 0.53 + Date: 2-27-2005 + + Fixed unsigned / signed problem that VS.net shows + + + Tried fix of line 186 in EasyBMP_BMP4.h file. If it works, + I'll apply it consistently. I think that VS.net wants us + to clear char* blah, then char = new blah [size], just + like the old days for g++. + + Removed EasyBMP_StandardColors.h from standard package + +*--------------------------------------------------------------------* + +Version: 0.54 + Date: 2-27-2005 + + The fix of line 186 in EasyBMP_BMP4.h file appears to have + worked. I applied it through the remainder of the code. + Hopefully, this should ensure Visual Studio.Net compati- + bility. + + Fixed some typos in the comment lines + +*--------------------------------------------------------------------* + +Version: 0.55 + Date: 5-2-2005 + + Introduced RGBApixel struct. + + Introduced BMFH, BMIH, and BMP classes. + + Deprecated all old code to *_legacy.h. + + Rewrote EasyBMP_VariousBMPutilities.h to use the new + BMP class. + +*--------------------------------------------------------------------* + +Version: 0.56 + Date: 5-4-2005 + + Made Width, Height, and BitDepth private members and added + functions for accessing them. + + Made a new function, SetBitDepth, as the only means to + change the bit depth. It will create/resize a palette as + necessary. This simplifies the WriteToFile code, as well as + any palette altering algorithms. (All algorithms can now + assume that a properly-sized palette exists.) This will + help improve code stability greatly. + + Made a new function, SetSize, as the only way to change the + width and height of the image. + + Eliminated useless HasPalette and NumberOfColors members, + and added TellNumberOfColors() function. + + Updated EasyBMP_VariousBMPutilities.h to respect privacy + of data members. + +*--------------------------------------------------------------------* + +Version: 0.57 + Date: 5-8-2005 + + Removed fclose(fp) lines from EasyBMP_BMP.h and + EasyBMP_VariousBMPutilities.h whenever ( !fp ) occurs, + to avoid a crash when trying to close a non-existant file. + + + Added a line to set bmfh.bfType = 0; to getBMFH() routine + in the case where ( !fp ) occurs, so that a nonexistant file + doesn't falsely show up as a bitmap file. + + Made error messages in BMP::ReadFromFile(char*) more meaningful, + since Argh! doesn't help much. :-) + + Made ReadFromFile operations safer: can deal more effectively + with corrupted and/or truncated files by adding the new + SafeFread() wrapper function. + + Moved all change-log entries to the change log to make the source + file tidier. + + Removed all references to Palettes; renamed them to ColorTables. + +*--------------------------------------------------------------------* + +Version: 0.58 + Date: 5-13-2005 + + Rewrote ReadFromFile() to fix program crashes on reading 4-bit + files. (*grumble* I can't believe there was such a bug in such + a late version! */grumble*) + + Added support to ReadFromFile() for reading 1-bit files. + + Rewrote ReadFromFile() to avoid trying to read bitmap files of + depths other than 1, 4, 8, 24, and 32 bits. + + Tested reading 4-bit files of width 0,1,2, and 3 (modulo 4), + and 1-bit files of width 0,1,2,3,4,5,6, and 7 (modulo 8) + +*--------------------------------------------------------------------* + +Version: 0.59 + Date: 5-15-2005 + + Made ReadFromFile() more robust. Evidently, reading to the + same temp variable all the time made it unstable when reading + many files. I would never have guessed. I instead declare BMIH + and BMFH objects and read directly to their members. This appears + to be more stable when dealing with many ReadFromFile() calls. + + On a related note, made sure to not call SetSize( Width,Height), + which is a bit recursive, as well as SetBitDepth( BitDepth ). + This appears to help stability, since these two functions were + create precisely for the purpose of setting those variables + values safely. + + Made use of the boolean return value in SafeFread() to detect + when files are obviously corrupted. Used this to have an early + catch in ReadFromFile() and set it to a 1x1 1-bit image and + exit. + + Made ReadFromFile() stricter, in that it only reads recognized + bit depths (1,4,8,24,32). Any other bit depth will prompt the + routine to terminate and set it to a 1x1 1-bit file. + + Added write support for 1-bit files. + + Rewrote WriteToFile() for 4,8-bit files to match methods used + for reading them. + + Revised CreateStandardColorTable() and + CreateGreyscaleColorTable() to add support for 1-bit files. + + Rewrote WriteToFile() to be stricter in only writing known bit + depths (1,4,8,24,32) and ignoring all others. + +*--------------------------------------------------------------------* + +Version: 0.60 + Date: 5-21-2005 + + Deprecated *_legacy.h files. + + Tested library extensivey in linux with good results. + + Made CreateGreyscaleColorTable() stricter, in that it exits + if supplied a bit depth other than 1, 4, or 8. + + Made cosmetic changes in EasyBMP_DataStructures.h to + improve readability. + + Made SetBitDepth() stricter, in that it will never allow a bitmap + to be set to an unsupported bit depth. Only bit depths of 1, 4, + 8, 24, or 32 are accepted. + + Made SetSize() stricter, in that it will not allow negative + widths or heights. + + Made cosmetic changes in EasyBMP_BMP.h to improve readability. + + Added a check in ReadFromFile() to see if the requested width or + height is negative, a good sign of file corruption. In such a + case, the file is set to a blank 1x1 1-bit file. + + Added code to ReadFromFile() to set size to 1x1 and bit depth to + 1-bit if the file was not found. + +*--------------------------------------------------------------------* + +Version: 0.61 + Date: 5-22-2005 + + Fixed awIndex typo in WriteToFile(). + + Replaced double BestDistance comparisons in WriteToFile() + with int BestDistances (so as to do integer operations, + rather than double operations). This gave a roughly 100% + speedup in 8-bit, 4-bit, and 1-bit write operations on + unoptimized (no compiler flags) code and a 30% speedup + on optimized code. + + Removed checks like if( BestDistance < 1 ){ k=256; } .. from + WriteToFile(), as they give more overhead than savings in my + testing. For 8-bit files, there was a slight gain by putting + it back in with another method: + while( k < 256 && BestDistance > 0 ). + + Redefined StepSize in CreateGreyscaleColorTable() to give a + better range of greys in 4-bit mode. As it was, white was not + in the color table. (Colors were spaced by 256/16 = 16). Now, + colors are spaced by (255-1)/(16-1) = 17, which gives the full + range. + +*--------------------------------------------------------------------* + +Version: 0.62 + Date: 5-25-2005 + + Added endianess check function IsBigEndian() to + EasyBMP_DataStructures.h file. + + Added functions to swap bytes in WORD and DWORD multibyte + variables to EasyBMP_DataStructures.h file for future big-endian + support. + + Added functions to switch endianess to BMFH and BMIH objects + to EasyBMP_DataStructures.h file. + + Added endianess checks to ReadFromFile() and WriteToFile() + functions in EasyBMP_BMP.h file, along with endianess conversions + where necessary. + + Added endianess checks and conversions to GetBMFH() and GetBMIH() + functions in EasyBMP_VariousBMPutilities.h file. + + Rewrote GetBitmapInfo() function to use GetBMFH() and GetBMIH() + functions instead. (In EasyBMP_VariousBMPutilities.h.) This + cuts down on the redundancy in the code. + + Renamed GetBitmapInfo() to DisplayBitmapInfo() in the + EasyBMP_VariousBMPutilities.h file. + + With these changes, big-endian architectures should be supported, + including IBM PowerPC, Sun Sparc, Motorola 86k, etc., and + including Mac OSX. + +*--------------------------------------------------------------------* + +Version: 0.63 + Date: 7-20-2005 + + Added IntPow(int,int) function to help compiling with std + namespace. Besides, integer operations are faster and more + accurate. + + Moved Square(double), IntSquare(int), and IntPow(int,int) to + EasyBMP_DataStructures.h + + Simplified and cleaned up code in + Create4bitColorTable( RGBApixel**). + + Changed safety check in BMP.ReadFromFile(char*) to set size to + 1 x 1 if width or height is non-positive, rather than simply + negative. + + Added bounds checking to BMP.operator()(int,int) to automatically + truncate requested pixel if out of bounds. Also added a warning + to cue the user in. :-) + + Made error messages more consistent in format. + + Simplified and cleaned up code in + Create4bitColorTable( RGBApixel**). + + Added #include to EasyBMP.h, since EasyBMP uses + cout, etc. + + Simplified and cleaned up code in + Create1bitColorTable( RGBApixel**). + + Changed BMP.SetSize(int,int) to disallow non-positive widths and + heights, rather than simply negative widths and heights. Such + function calls are now ignored. + +*--------------------------------------------------------------------* + +Version: 0.64 + Date: 8-2-2005 + + Changed "include " to "include " for + ANSI-C++ compliance, as well as for better compatibility with the + std namespace and VC++. (Thanks, Tommy Li!) + + Added some #ifndef pragmas to each header so that it should be + fine to incluce EasyBMP.h in multiple files in larger projects. + + Added "using namespace std" inside any function that used C++ + math or I/O operations. I avoided putting "using namespace std" + anywhere with global scope for maximum compatibility with C++ + software in the wild. + + Added includes for and to EasyBMP.h + + Removed unused temporary variables (TempWORD and TempDWORD) from + EasyBMP_BMP.h for cleaner compiling. If I see any more such + unused variables, I'll remove them, too. + +*--------------------------------------------------------------------* + +Version: 0.65 + Date: 8-13-2005 + + Moved implementations of BMP::BMP(), BMP::~BMP(), and + BMP::operator()(int,int) outside of the class. This should help + for eventually moving everything into a separate cpp file. + + Made RGBApixel** Pixels a private data member of the class + BMP. + + Added function void BMP::SetColor(int,RGBApixel) to BMP class + to allow safe method of changing a color in the color table. + + Added function RGBApixel BMP::GetColor(int) to BMP class + to allow safe method of retrieving a color in the color + table. + + Cleaned up error messages in EasyBMP_BMP.h + + Cleaned up error messages in EasyBMP_VariousBMPutilities.h + +*--------------------------------------------------------------------* + +Version: 0.66 + Date: 8-18-2005 + + EasyBMP_StandardColorTables.h was removed from the library. + + CreateStandardColorTable(RGBApixel**,int) was changed to + CreateStandardColorTable() and made a member function of BMP. + All other CreateStandardColorTable functions are now unnecessary + and have been removed. + + CreateGreyscaleColorTable(RGBApixel**,int) was changed to + CreateStandardColorTable( BMP& ) and moved to + EasyBMP_VariousBMPutilities.h. + + RGBApixel* Colors was made a private data member of the BMP + class. + + CreateGreyscaleColorTable( BMP& ) was renamed to + CreateGrayscaleColorTable( BMP& ). + +*--------------------------------------------------------------------* + +Version: 0.67 + Date: 9-14-2005 + + Made the EasyBMP custom math functions in + EasyBMP_DataStructures.h inline. (Square,IntSquare,IntPow). + This should make those function calls faster while improving + compatibility with compiling DLL's. + + Separated the code from SafeFread() in EasyBMP_BMP.h to + improve compatibility with compiling DLL's. + + Removed #define _WINGDI_H from EasyBMP_DataStructures.h to + improve compatibility with win32 applications. Instead, + there's an extra #ifndef _SELF_DEFINED_BMP_DATA_TYPES + conditional added. + + _SELF_DEFINED_BMP_DATA_TYPES renamed to _SELF_DEFINED_WINGDI + in EasyBMP_DataStructures.h. + + All bit-flipping functions (IsBigEndian, FlipWORD, + FlipDWORD) in EasyBMP_DataStructures.h were made inline + to improve execution speed and improve compatibility with + compiling DLL's. + + All code was separated from function declarations in + EasyBMP_VariousBMPutilities.h to improve compatibility + with compiling DLL's. + + Updated and cleaned up layout of EasyBMP_ChangeLog.txt. + + Updated contact and support information in library files. + + Corrected the LGPL license version. + +*--------------------------------------------------------------------* + +Version: 0.68 + Date: 10-9-2005 + + Changed references to FILE to std::FILE in the SafeFread function + in EasyBMP_BMP.h to improve compatibility with Borland's compiler. + + Removed a few assignments in EasyBMP_BMP.h that weren't used to + improve efficiency and reduce Borland warnings. + + Changed calls like NotCorrupted = SafeFread() to + NotCorrupted &= SafeFread() in BMP::ReadFromFile() in EasyBMP_BMP.h + to improve robustness. Now, if the NotCorrupted bit is ever set + to false, it stays false, meaning that the function won't "forget" + that it encountered file corruption. + +*--------------------------------------------------------------------* + +Version: 0.69 + Date: 10-19-2005 + + Changed BMP::WriteToFile( char* ) to BMP::WriteToFile(const char*) + in EasyBMP_BMP.h to respond to a feature request. + + Changed BMP::ReadFromFile( char* ) to BMP::ReadToFile(const char*) + in EasyBMP_BMP.h to respond to a feature request. + + Made BMP::ReadFromFile() and BMP::WriteToFile() in EasyBMP_BMP.h + return true/false to indicate success/failure in the operations. + These functions previously returned void. + + Made BMP::SetSize() and BMP::SetBitDepth() in EasyBMP_BMP.h + return true/false to indicate success/failure in the operations. + These functions previously returned void. + + Made BMP::SetColor() and BMP::CreateStandardColorTable() in + EasyBMP_BMP.h return true/false to indicate success/failure in the + operations. These functions previously returned void. + + Made CreateGrayscaleColorTable() in EasyBMP_VariousBMPutilities.h + return true/false to indicate success/failure in the operations. + This function previously returned void. + + Changed the char* argument GetBMFH( char* ), GetBMIH( char* ), + DisplayBitmapInfo( char* ), and GetBitmapColorDepth( char* ) in + EasyBMP_VariousBMPutilities.h to const char* for cleaner, safer + programming. + +*--------------------------------------------------------------------* + +Version: 0.70 + Date: 10-19-2005 + + Found and fixed error in BMP::ReadFromFile() in the check for only + reading support bit depths. + + Changed license from LGPL to BSD (revised/modified) to simplify + licensing issues and resolve any lingering licensing questions. + + Fixed compiler error when using MSVC++. + + Improved fix to allow compiling with Borland without breaking + Borland support. + + Added a few lines to EasyBMP.h to make it easier to tailor code + to specific compilers. (For future use as needed.) + + Added a few lines to EasyBMP_BMP.h (in BMP::ReadFromFile(), + BMP::WriteToFile(), and BMP::SetBitDepth()) to eventually add + support for 16-bit files. + +*--------------------------------------------------------------------* + +Version: 0.71 + Date: 11-01-2005 + + Cleaned up comments in BMP::ReadFromFile() in EasyBMP_BMP.h + + Added endian-safe read support for 16-bit files that are in the + standard 5-5-5 format (not specified in bit fields) + + Added endian-safe read support for 16-bit files that use bit + fields, including 5-6-5 files. + + Added endian-safe write support for 16-bit files. Uses the 5-6-5 + encoding scheme to maximize the utility of the bits used. + + Added a check for compression in BMP::ReadFromFile(). Because + file compression is beyond the scope of EasyBMP, such files are + not supported, and EasyBMP now properly detects these situations + and exits with an error. + + Added a check for files that attempt to use bit fields but are not + 16-bit files to BMP::ReadFromFile(). Such files are not supported. + + Added a check to BMP::ReadFromFile() for files that use unknown + values of bmih.biCompression, such as old OS2 bitmaps. Such files + are not supported. + + Removed "switching endianness" messages from EasyBMP_BMP.h + + Added support for indexed (1, 4, and 8-bit) files that don't + specify all the colors. + + Added support for reading files that include extra meta data before + the pixels. This data is skipped. + + Added enclosing #ifndef EasyBMP ... lines to EasyBMP.h as a + further safeguard when EasyBMP is included in multiple cpp + files. + +*--------------------------------------------------------------------* + +Version: 1.00 + Date: 02-06-2006 + + First Production/Stable release. + + Corrected typographical errors in the comment sections of all + files. + + Updated copyright on all files. + + Removed extraneous comment in BMIH::BMIH() function in + EasyBMP_DataStructures.h file. + + Replaced instances of \n with the more modern endl in + EasyBMP_DataStructures.h, EasyBMP_BMP.h, and + EasyBMP_VariousBMPutilities.h. + + Added placeholder MetaData1 and MetaData2 data members to the + BMP class for potential future use. + + Removed extraneous comments from EasyBMP_BMP.h. + + Removed warning messages for switching endianness from + EasyBMP_VariousBMPutilities.h. + + Updated copyright in EasyBMP_ChangeLog.txt file. + + Fixed formatting issues in EasyBMP_ChangeLog.txt file. + + Added DefaultXpelsPerMeter and DefaultYpelsPerMeter in + EasyBMP.h. These will default to 96 dpi. + + Changed BMP::WriteToFile() to use DefaultXpelsPerMeter and + DefaultYpelsPerMeter when writing the BMIH structure. + + Added XpelsPerMeter and YpelsPerMeter data members to BMP + class so that horizontal and vertical resolution are handled + properly. Currently, upon reading a file, the stated resolutions + are preserved, and upon writing, if no resolutions are given, + the defaults (of 96 DPI) are used. + + Added function void BMP::SetDPI(int,int) to set the horizontal + and vertical resolutions. + + Removed some unnecessary code from GetBitmapColorDepth() in + EasyBMP_VariousBMPutilities.h. + + Fixed a bug in RangedPixelToPixelCopyTransparent() and + RangedPixelToPixelCopy() in EasyBMP_VariousBMPutilities.h which + caused copies to be truncated by an extra row or column in + certain circumstances. + + Fixed a bug in RangedPixelToPixelCopyTransparent() and + RangedPixelToPixelCopy() in EasyBMP_VariousBMPutilities.h which + checked the wrong variable (FromT instead of FromB) to see if + it was out of range. + + Added extra checks to RangedPixelToPixelCopyTransparent() and + RangedPixelToPixelCopy() in EasyBMP_VariousBMPutilities.h to + prevent attempted access of out-of-range pixels. + +*--------------------------------------------------------------------* + +Version: 1.01 + Date: 03-31-2006 + + Made only the short functions Square, IntSquare, IsBigEndian, + FlipWORD, and FlipDWORD inline functions in + EasyBMP_DataStructures.h. + + Moved all code (other than inline functions) to EasyBMP.cpp. + + Changed DefaultXPelsPerMeter and DefaultYPelsPerMeter to #define + lines in EasyBMP.h to make the library compatible with + with the header-code split. + + Removed memory hole in ~BMP() where "delete Colors;" was used + instead of "delete [] Colors;". Likewise with MetaData1 and + MetaData2. + + Fixed memory leak in BMP::SetBitDepth() by changing to + delete [] Colors; + + Removed potential memory leak in BMP::WriteToFile() in 24- and + 32-bit writing where szTemp wasn't delete at the end of a row. + + Fixed bug where XPelsPerMeter and YPelsPerMeter weren't + properly initialized in the BMP::BMP() constructor, leading + to strange horizontal and vertical resolutions. + + Fixed memory leak in BMP::ReadFromFile() where TempSkipBYTE + wasn't deleted. + + Fixed memory leak in BMP::ReadFromFile() where szTemp wasn't + deleted. + + Added BMP::TellVerticalDPI() and BMP::TellHorizontalDPI() + functions to give this information. If those values have + not yet been set, then they are first set to the EasyBMP + defaults of 96 dpi. + + Set uninitialized RGBApixel values to white (255,255,255,0) + in a few functions for the BMP class. + + Added a sample cpp application and makefile. + +*--------------------------------------------------------------------* + +Version: 1.02 + Date: 05-29-2006 + + Inserted a line into EasyBMP.h to suppress the Visual Studio + warnings. We'll keep using the C++ standard fopen for now + until fopen_s becomes a real standard. + + Moved the code sample and makefile to a subdirectory, so that + unzipping EasyBMP#_##.zip into a project directory doesn't + overwrite any crucial makefiles. + + Improved SafeFread() to check if the proper amount of data + could be read. + + Dramatically cleaned up ReadFromFile() code for 1 and 4 + bpp files. + + Fixed a typo (draw.o) in the sample makefile. + + Modified ReadFromFile() to use buffering when reading the pixel + data. This should substantially improve disk access performance. + Only 16 bpp files are read in the old, slower way. + + Changed DWORD from unsigned long to unsigned int. This should + fix the issue where 64-bit machines see DWORD as an 8-byte + data type, rather than 4 bytes. (Thank you to Bas Wegh!) + + Renamed BYTE, WORD, and DWORD data types to ebmpBYTE, ebmpWORD, + and ebmpDWORD to eliminate the possibility of conflict with + windows applications, particularly with 64-bit windows, which + likely uses 8 byte DWORDS. + + Modified WriteToFile() to use buffering when reading the pixel + data. This should substantially improve disk access performance. + Only 16 bpp files are read in the old, slower way. + + Added new function, EasyBMPcheckDataSize(), to check that + the ebmpBYTE, ebmpWORD, and ebmpDWORD types have the correct + type. + + Added some new macros of the EasyBMP version number for easier + version checking. New versions include _EasyBMP_Version_ + (a double), _EasyBMP_Version_String_ (a char* version), and + _EasyBMP_Version_Integer_ (an integer version, e.g., 102). + +*--------------------------------------------------------------------* + +Version: 1.03 + Date: 06-20-2006 + + Inserted a line into EasyBMP.h to suppress the Visual Studio + + Added a check to BMP.SetColor() to ensure that the color table + is defined before attempting to set a color entry. + + Added a check to BMP.GetColor() to ensure that the color table + is defined before attempting to retrieve a color entry. + + Simplified the conditional in BMP.WriteToFile() from + if( BitDepth == 1 || BitDepth == 4 || ... ) to the simpler + if( BitDepth != 16 ). + + Removed the old, unused code for writing 1- and 4-bit files + from BMP.WriteToFile(). + + Removed the line Colors = new RGBApixel [NumberOfColors]; in + BMP.ReadFromFile(). This operation is already covered by the + earlier SetBitDepth() call, and may contribute to a memory + leak. Furthermore, for files that had fewer than expected + number of colors (e.g., an 8-bit file with 236 colors), it + lead to memory access errors in BMP.GetColor() and BMP.SetColor(). + (In fact, this is the main motivation for release 1.03.) + + Added a warning when BMP.ReadFromFile() encounters an under- + specified color table, and code to pad the table with white + entries. + + Added screen output on EasyBMP version and project website to + the code sample. + +*--------------------------------------------------------------------* + +Version: 1.04 + Date: 07-22-2006 + + Removed the assignment to the integer i in IntPow() to eliminate a + Borland compiler warning. + + Removed the assignment to the integer i in the Read##bitRow() + functions to eliminate Borland compiler warnings. + + Removed the assignment to ZeroWORD in line 478 of EasyBMP.cpp in + BMP::WriteToFile() to eliminate Borland compiler warnings. + + Removed the assignment to ZeroWORD in line 825 of EasyBMP.cpp in + BMP::ReadFromFile() to eliminate Borland compiler warnings. + + The Borland warnings about conditions always being false are + incorrect. (Lines 1587, 1594, and 1601.) Likewise, the Borland + warnings about unreachable code (lines 1589, 1596, and 1603) are + incorrect. This code serves as a protection on unexpected hardware + where the data types may not be of the correct size, and helps to + future-proof EasyBMP. The first time this type of error was + encountered was on 64-bit CPUs, where the size of the DWORD was + larger than assumed when writing EasyBMP. Therefore, we will not + "correct" these "errors" detected by Borland. If they bother you, + compile with the -w-8008 and -w-8066 options. + + Borland issues warnings about argc and argv being unused in the + sample project. These are silly warnings and will be ignored. If + this warning bothers you, compile with the -w-8057 option. + + Modified the sample makefile so that EasyBMP.o depends upon + EasyBMP.cpp and EasyBMP*.h in the current working directory, rather + than the parent directory. + + Added a global EasyBMPwarnings boolean variable, and functions + SetEasyBMPwarningsOn() and SetEasyBMPwarningsOff() to enable and + disable EasyBMP warnings and errors. Note that this will not + disable error checking or any other EasyBMP behavior, other than + cout output of the warning and error messages. + + Added the function GetEasyBMPwarningState() to query the EasyBMP + warning state. (Either warnings are enabled or disabled.) + + Removed old commented code (Write1bitRow()) from EasyBMP.cpp. + + Replaced the 24-bit EasyBMPbackground.bmp image in the code sample + with a dithered 8-bit version to reduce the download size of the + core library. + +*--------------------------------------------------------------------* + +Version: 1.05 + Date: 11-01-2006 + + Renamed BytesRead to ItemsRead in the SafeFread() function in + EasyBMP.cpp for greater clarity. + + Added a copy constructor to the BMP class. However, note that + passing by value is not recommended practice. (Passing by refer- + ence is much faster, and consumes less memory.) + + Added a new function: + bool Rescale( BMP& InputImage, char mode, int NewDimension ); + to resize an image. The mode variables are as follows: + 'P': resizes the image to a new percentage of the old size, + e.g., 42%, 13%, etc. + example: Rescale( SomeImage, 'p', 42 ); + 'W': resizes the image such that the new width is as specified. + example: Rescale( SomeImage, 'W', 100 ); + 'H': resizes the image such that the new height is as specified. + example: Rescale( SomeImage, 'H', 100 ); + 'F': resizes the image to fit in a square of specified size. + example: Rescale( SomeImage, 'F', 100 ); // fits in 100x100 + // box + All rescaling is done with bilinear interpolation. + +*--------------------------------------------------------------------* + +Version: 1.06 + Date: 12-01-2006 + + Added includes for and to EasyBMP.h. These are + used and should have been included all along. This should help + with Intel icc compiling. + + Fixed the && bug in the copy constructor. (Thank you to user + fcnature!) + + Added image scaling to the supplied code sample. + + Added GetPixle() and SetPixel() functions for future use. These + will be added to enable more careful use of the const keyword. + +*--------------------------------------------------------------------* \ No newline at end of file diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_DataStructures.h b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_DataStructures.h new file mode 100644 index 0000000..41665e5 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_DataStructures.h @@ -0,0 +1,104 @@ +/************************************************* +* * +* EasyBMP Cross-Platform Windows Bitmap Library * +* * +* Author: Paul Macklin * +* email: macklin01@users.sourceforge.net * +* support: http://easybmp.sourceforge.net * +* * +* file: EasyBMP_DataStructures.h * +* date added: 05-02-2005 * +* date modified: 12-01-2006 * +* version: 1.06 * +* * +* License: BSD (revised/modified) * +* Copyright: 2005-6 by the EasyBMP Project * +* * +* description: Defines basic data structures for * +* the BMP class * +* * +*************************************************/ + +#ifndef _EasyBMP_Custom_Math_Functions_ +#define _EasyBMP_Custom_Math_Functions_ +inline double Square( double number ) +{ return number*number; } + +inline int IntSquare( int number ) +{ return number*number; } +#endif + +int IntPow( int base, int exponent ); + +#ifndef _EasyBMP_Defined_WINGDI +#define _EasyBMP_Defined_WINGDI + typedef unsigned char ebmpBYTE; + typedef unsigned short ebmpWORD; + typedef unsigned int ebmpDWORD; +#endif + +#ifndef _EasyBMP_DataStructures_h_ +#define _EasyBMP_DataStructures_h_ + +inline bool IsBigEndian() +{ + short word = 0x0001; + if((*(char *)& word) != 0x01 ) + { return true; } + return false; +} + +inline ebmpWORD FlipWORD( ebmpWORD in ) +{ return ( (in >> 8) | (in << 8) ); } + +inline ebmpDWORD FlipDWORD( ebmpDWORD in ) +{ + return ( ((in&0xFF000000)>>24) | ((in&0x000000FF)<<24) | + ((in&0x00FF0000)>>8 ) | ((in&0x0000FF00)<<8 ) ); +} + +// it's easier to use a struct than a class +// because we can read/write all four of the bytes +// at once (as we can count on them being continuous +// in memory + +typedef struct RGBApixel { + ebmpBYTE Blue; + ebmpBYTE Green; + ebmpBYTE Red; + ebmpBYTE Alpha; +} RGBApixel; + +class BMFH{ +public: + ebmpWORD bfType; + ebmpDWORD bfSize; + ebmpWORD bfReserved1; + ebmpWORD bfReserved2; + ebmpDWORD bfOffBits; + + BMFH(); + void display( void ); + void SwitchEndianess( void ); +}; + +class BMIH{ +public: + ebmpDWORD biSize; + ebmpDWORD biWidth; + ebmpDWORD biHeight; + ebmpWORD biPlanes; + ebmpWORD biBitCount; + ebmpDWORD biCompression; + ebmpDWORD biSizeImage; + ebmpDWORD biXPelsPerMeter; + ebmpDWORD biYPelsPerMeter; + ebmpDWORD biClrUsed; + ebmpDWORD biClrImportant; + + BMIH(); + void display( void ); + void SwitchEndianess( void ); +}; + +#endif diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_VariousBMPutilities.h b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_VariousBMPutilities.h new file mode 100644 index 0000000..3a2f464 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/EasyBMP_VariousBMPutilities.h @@ -0,0 +1,53 @@ +/************************************************* +* * +* EasyBMP Cross-Platform Windows Bitmap Library * +* * +* Author: Paul Macklin * +* email: macklin01@users.sourceforge.net * +* support: http://easybmp.sourceforge.net * +* * +* file: EasyBMP_VariousBMPutilities.h * +* date added: 05-02-2005 * +* date modified: 12-01-2006 * +* version: 1.06 * +* * +* License: BSD (revised/modified) * +* Copyright: 2005-6 by the EasyBMP Project * +* * +* description: Various utilities. * +* * +*************************************************/ + +#ifndef _EasyBMP_VariousBMPutilities_h_ +#define _EasyBMP_VariousBMPutilities_h_ + +typedef union { + int ratio; + int keepsize; + struct { + short width; + short height; + } dimension; +} ScaleParam; + +BMFH GetBMFH( const char* szFileNameIn ); +BMIH GetBMIH( const char* szFileNameIn ); +void DisplayBitmapInfo( const char* szFileNameIn ); +int GetBitmapColorDepth( const char* szFileNameIn ); +void PixelToPixelCopy( BMP& From, int FromX, int FromY, + BMP& To, int ToX, int ToY); +void PixelToPixelCopyTransparent( BMP& From, int FromX, int FromY, + BMP& To, int ToX, int ToY, + RGBApixel& Transparent ); +void RangedPixelToPixelCopy( BMP& From, int FromL , int FromR, int FromB, int FromT, + BMP& To, int ToX, int ToY ); +void RangedPixelToPixelCopyTransparent( + BMP& From, int FromL , int FromR, int FromB, int FromT, + BMP& To, int ToX, int ToY , + RGBApixel& Transparent ); +bool CreateGrayscaleColorTable( BMP& InputImage ); + +bool Rescale( BMP& InputImage , char mode, ScaleParam scale ); + + +#endif diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/EasyBMPbackground.bmp b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/EasyBMPbackground.bmp new file mode 100644 index 0000000..ae1dfa2 Binary files /dev/null and b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/EasyBMPbackground.bmp differ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/EasyBMPsample.cpp b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/EasyBMPsample.cpp new file mode 100644 index 0000000..2b25ca2 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/EasyBMPsample.cpp @@ -0,0 +1,82 @@ +/************************************************* +* * +* EasyBMP Cross-Platform Windows Bitmap Library * +* * +* Author: Paul Macklin * +* email: macklin01@users.sourceforge.net * +* support: http://easybmp.sourceforge.net * +* * +* file: EasyBMPsample.cpp * +* date added: 03-31-2006 * +* date modified: 12-01-2006 * +* version: 1.06 * +* * +* License: BSD (revised/modified) * +* Copyright: 2005-6 by the EasyBMP Project * +* * +* description: Sample application to demonstrate * +* some functions and capabilities * +* * +*************************************************/ + +#include "EasyBMP.h" +using namespace std; + +int main( int argc, char* argv[] ) +{ + cout << endl + << "Using EasyBMP Version " << _EasyBMP_Version_ << endl << endl + << "Copyright (c) by the EasyBMP Project 2005-6" << endl + << "WWW: http://easybmp.sourceforge.net" << endl << endl; + + BMP Text; + Text.ReadFromFile("EasyBMPtext.bmp"); + + BMP Background; + Background.ReadFromFile("EasyBMPbackground.bmp"); + + BMP Output; + Output.SetSize( Background.TellWidth() , Background.TellHeight() ); + Output.SetBitDepth( 24 ); + + RangedPixelToPixelCopy( Background, 0, Output.TellWidth()-1, + Output.TellHeight()-1 , 0, + Output, 0,0 ); + + RangedPixelToPixelCopyTransparent( Text, 0, 380, + 43, 0, + Output, 110,5, + *Text(0,0) ); + + RangedPixelToPixelCopyTransparent( Text, 0, Text.TellWidth()-1, + Text.TellWidth()-1, 50, + Output, 100,442, + *Text(0,49) ); + + Output.SetBitDepth( 32 ); + cout << "writing 32bpp ... " << endl; + Output.WriteToFile( "EasyBMPoutput32bpp.bmp" ); + + Output.SetBitDepth( 24 ); + cout << "writing 24bpp ... " << endl; + Output.WriteToFile( "EasyBMPoutput24bpp.bmp" ); + + Output.SetBitDepth( 8 ); + cout << "writing 8bpp ... " << endl; + Output.WriteToFile( "EasyBMPoutput8bpp.bmp" ); + + Output.SetBitDepth( 4 ); + cout << "writing 4bpp ... " << endl; + Output.WriteToFile( "EasyBMPoutput4bpp.bmp" ); + + Output.SetBitDepth( 1 ); + cout << "writing 1bpp ... " << endl; + Output.WriteToFile( "EasyBMPoutput1bpp.bmp" ); + + Output.SetBitDepth( 24 ); + Rescale( Output, 'p' , 50 ); + cout << "writing 24bpp scaled image ..." << endl; + Output.WriteToFile( "EasyBMPoutput24bpp_rescaled.bmp" ); + + return 0; +} diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/EasyBMPtext.bmp b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/EasyBMPtext.bmp new file mode 100644 index 0000000..6a9e00c Binary files /dev/null and b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/EasyBMPtext.bmp differ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/makefile b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/makefile new file mode 100644 index 0000000..591c649 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/lib/EasyBMP/sample/makefile @@ -0,0 +1,53 @@ +# +# EasyBMP Cross-Platform Windows Bitmap Library +# +# Author: Paul Macklin +# email: macklin01@users.sourceforge.net +# support: http://easybmp.sourceforge.net +# file: makefile +# date added: 04-22-2006 +# date modified: 12-01-2006 +# version: 1.06 +# +# License: BSD (revised/modified) +# Copyright: 2005-6 by the EasyBMP Project +# +# description: Sample makefile for compiling with +# the EasyBMP library. This compiles +# the EasyBMPsample.cpp program. +# + +CC = g++ + +# this line gives compiler optimizations that are geared towards g++ and Pentium4 +# computers. Comment it out if you don't have a Pentium 4 (or Athlon XP) or up + +# CFLAGS = -O3 -Wno-deprecated -mcpu=pentium4 -march=pentium4 \ +# -mfpmath=sse -msse -mmmx -msse2 -pipe -fomit-frame-pointer -s + +# Uncomment these two lines to use with any Pentium with MMX or up. + +# CFLAGS = -Wno-deprecated -mcpu=pentium -march=pentium -pipe \ +# -fomit-frame-pointer -mmmx -funroll-all-loops -s + +# Uncomment these lines for some "safe" optimization flags + +CFLAGS = -O3 -pipe -fomit-frame-pointer -funroll-all-loops -s + +EasyBMPTest: EasyBMP.o EasyBMPsample.o + g++ $(CFLAGS) EasyBMP.o EasyBMPsample.o -o EasyBMPtest + +EasyBMP.o: ../EasyBMP.cpp ../EasyBMP*.h + cp ../EasyBMP*.h . + cp ../EasyBMP.cpp . + g++ $(CFLAGS) -c EasyBMP.cpp + +EasyBMPsample.o: EasyBMPsample.cpp + g++ -c EasyBMPsample.cpp + +clean: + rm EasyBMP*.h + rm EasyBMP.cpp + rm EasyBMPtest* + rm EasyBMPoutput*.bmp + rm -f *.o diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/lib/libregex.a b/utility/demo-fw/pc-tools/CreateDemoBin/lib/libregex.a new file mode 100644 index 0000000..c20b68d Binary files /dev/null and b/utility/demo-fw/pc-tools/CreateDemoBin/lib/libregex.a differ diff --git a/utility/demo-fw/pc-tools/CreateDemoBin/readme.txt b/utility/demo-fw/pc-tools/CreateDemoBin/readme.txt new file mode 100644 index 0000000..e787e37 --- /dev/null +++ b/utility/demo-fw/pc-tools/CreateDemoBin/readme.txt @@ -0,0 +1,109 @@ +1> directory info: + +|-bin [dir]compile executive binary +|-include [dir]header files +|-lib [dir]libraries +|-PPT [dir]directory containing example PPT, demo bin file and vs script +|-src [dir]source files +|-Makefile [file]project file to make. use gnu/g++ as compiler. +|-Module1.bas [file]vb script source of macro 'ExportPPTInfo' +|-readme.txt [file]this file + + + +2> usage instructions: + +Suppose that demo is for at91sam3u-ek, and power point file is Sam3Demo.ppt. + +Sam3Demo.bin and SamDemoV.bin under ./PPT are created bin files with CreateDemoBin.exe, you can use it directly or use CreateDemoBin.exe to recreate it. + +Follow these instructions to create a bin from starting(use sam3demo.ppt as example): + +[step 1]: + Open Sam3DEMO.ppt, when a window pops up, select 'enable macros'. If no this window or you made wrong selection, please check Powerpoint menu 'tools->macro->security...', set it to medium, then close the program and reopen it.(Powerpoint 2003) + +[step 2]: + Select 'tools->macro->macros...', then run the macro named as 'ExportPPTInfo'. After running, there should be 'Sam3DEMO.txt' and dir 'Sam3DEMO' created. Inside dir 'Sam3DEMO', there should be bmp files named as 'slide1.bmp... slide10.bmp...' If macro 'ExportPPTInfo' is not available, please import content of 'Module1.bas' into VB script edit window, save it to file, then rerun it. + +[step 3]: + Run CreateDemoBin.bat (or CreateDemoBin sam3demo)under dir same as Sam3DEMO.ppt. If success, Sam3Demo.bin should be created. + + [Please NOTE]: +a:> Defaultly this bat will generate horizontal view demo binary for sdcard and nandflash(contained slide pics are 320*240 16bit bmp with 270 degree clockwise rotation). For vertical view demo binary, please use CreateDemoBinV.bat to generate sam3demo.bin, then RENAME it to SamDemoV.bin. Before Converting vertical view demo binary, previous generated horizontal view demo binary Sam3Demo.bin must be BACKUPed. Or converting vertical one and renaming it first, then converting horizontal one. Key word sam3demo could be replaced with any actual name of PPT. + +b:>This batch files are only for sam3u demo(assuming that PPT name is sam3demo.ppt). For other boards and PPT file, please replace conversion parameters and PPT name. In following section 3, more details about conversion tools with examples are given. + + + +[step 4]: + Copy the bin file into root dir of a SDCARD or using sam-ba to download it into flash1, the program will search the SDcard -> Nandflash -> Internal flash for the demo binary file.(you can use the default binary file Sam3DEMO.bin for SDcard and Nandflash, and DEMOBINFLASH1.bin for the internal flash) + +[step 5]: + Compile the gshell projects, and load it into sam3u4 flash0 to run.(if DEMOBININFLASH1 is defined, then program will read demo bin data from FLASH1, otherwise, it will read demo bin data with search order of sdcard->nandflash->flash1. Auto run in the init entry will try to read "sam3demo.bin" by default. You can use other demo bin file name under GShell console) + + + + +3> CreateDemoBin.exe options and examples: + + +Usage: CreateDemoBin.exe [options] + For example, sam3demo.ppt, after running VBS macro in PowerPoint, + copy this file under the same directory, then Run: + + CreateDemoBin.exe sam3demo + Options: + --help, show this information + -profile , build-in option sets, default board name is at91sam3u-ek + -profile help, display all build-in profile details + -width , default is 320 pixel + -height , default is 240 pixel + -bitdepth , default is 16 bit + -rotate , times of 90 degree within 360, default is 270 degre +e + -noreversebitmaporder, keep bitmap data original order, default reverse the order for at91sam3u-ek + + + +[Example 1:Generating demo binary of horizontal view]: + + For demo bin of default horizontal view(based on long side of LCD SCREEN) in sdcard or nandflash of at91sam3u-ek(sam3demo.ppt, and generated txt file and slide bitmap with macro): + +createdemobin sam3demo +or +createdemobin -profile at91sam3u-ek +or +createdemobin -width 320 -height 240 -bitdepth 16 -rotate 270 sam3demo + +The built-in default options are for Sam3u demo horizontal view, so you can convert it as first one to use default options. + +[Example 2:Generating demo binary of vertical view]: + + For demo bin of vertical view(based on long side of LCD SCREEN) in sdcard or nandflash of at91sam3u-ek(sam3demo.ppt, and generated txt file and slide bitmap with macro): + +CreateDemoBin -width 240 -height 320 -bitdepth 16 -rotate 0 sam3demo + +*NOTE: after generation, must RENAME sam3demo.bin to samdemov.bin for vertical view. + + +[Example 3:Merge two PPTs to generate a binary]: + +For example, PPT file Pa.ppt has 18 pages, PPT file Pb.ppt has 30 pages. It is required that all +Pb.ppt slide pages should be inserted after the16th page into Pa.ppt: +Steps: +? Insert 30 empty pages after the 16th page of Pa.ppt +? Enable macro security level to medium, and then import vb script macro Module1.bas +? Run macro ExportPPTInfo, when proceeding to popup window for prompting conversion +parameters, press cancel to ignore conversion step. +? Insert 16 pages before the 1st page of Pb.ppt +? Do steps 2 and 3 for Pb.ppt. +? Delete slide information file Pa.txt section from slide 17 to slide 46, then copy slide +information file Pb.txt section from slide 17 to slide 46 at the same position in Pa.txt +? Copy picture files from slide17.bmp to slide46.bmp in Pb directory to Pa directory to +overwrite them. +? Use command sequences above to generate horizontal or vertical binary file. + + + + + 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