diff options
author | Graeme Geldenhuys <graemeg@gmail.com> | 2015-09-02 10:20:05 +0100 |
---|---|---|
committer | Graeme Geldenhuys <graemeg@gmail.com> | 2015-09-02 10:20:05 +0100 |
commit | 34bf07549f9eaabf39402911cbf4e46ecf7e9399 (patch) | |
tree | 0262be1833b3a771bc099ee9100b5eb3aa7cbd45 /docview | |
parent | fdb7b18ba4d4dc0ba80bcc5e0a253e5dae36d625 (diff) | |
parent | e534fc59e15458a2b3196eafd349efde0d05bdd1 (diff) | |
download | fpGUI-34bf07549f9eaabf39402911cbf4e46ecf7e9399.tar.xz |
Merge branch 'docview-image-fix' into fixes_1.4
Diffstat (limited to 'docview')
-rw-r--r-- | docview/src/HelpBitmap.pas | 64 | ||||
-rw-r--r-- | docview/src/docview_clean.prj | 381 | ||||
-rw-r--r-- | docview/src/frm_main.pas | 1 | ||||
-rw-r--r-- | docview/src/lzwdecompress.pas | 55 |
4 files changed, 441 insertions, 60 deletions
diff --git a/docview/src/HelpBitmap.pas b/docview/src/HelpBitmap.pas index 45855a1f..b5464cbf 100644 --- a/docview/src/HelpBitmap.pas +++ b/docview/src/HelpBitmap.pas @@ -1,7 +1,7 @@ { fpGUI - Free Pascal GUI Toolkit - Copyright (C) 2006 - 2013 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2015 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, @@ -73,7 +73,7 @@ type end; - THelpBitmap = class( TfpgImage ) + THelpBitmap = class(TfpgImage) protected _Header: INFBITMAPHEADER; _PaletteColorCount: longint; @@ -81,12 +81,12 @@ type _BitsSize: longint; FileHandle: TFileStream; _UncompressedBlockSize: longint; - function GetPaletteSize: longint; - procedure BitmapError(Msg: string); - procedure ReadBitmapData( Blocks: TList; TotalSize: longword); + function GetPaletteSize: longint; + procedure BitmapError(Msg: string); + procedure ReadBitmapData( Blocks: TList; TotalSize: longword); public - constructor CreateFromHelpFile(var AFileHandle: TFileStream; Offset: longint); - destructor Destroy; override; + constructor CreateFromHelpFile(var AFileHandle: TFileStream; Offset: longword); + destructor Destroy; override; end; @@ -128,7 +128,7 @@ begin inherited Destroy; end; -constructor THelpBitmap.CreateFromHelpFile(var AFileHandle: TFileStream; Offset: longint); +constructor THelpBitmap.CreateFromHelpFile(var AFileHandle: TFileStream; Offset: longword); var WordsPerLine: longint; LineSize: longint; @@ -282,10 +282,14 @@ var ptr: PByte; i: integer; img: TfpgImage; + {$IFDEF LZW_DEBUG} + s: TFileStream; + {$ENDIF} begin BitmapOutputPointer := nil; BitmapData := nil; ptr := nil; + lastOutByte := $0; // Allocate memory to store the bitmap BitmapData := GetMem( TotalSize ); @@ -309,6 +313,9 @@ begin case Block._CompressionType of 0,1: // uncompressed (I'm not sure about 1) begin + {$IFDEF LZW_DEBUG} + writeln('Uncompressed image type'); + {$ENDIF} MemCopy( Block._Data^, BitmapOutputPointer^, Block._Size ); BytesWrittenFromBlock := Block._Size; inc( BytesWritten, BytesWrittenFromBlock ); @@ -316,6 +323,9 @@ begin 2: // LZW compression begin + {$IFDEF LZW_DEBUG} + writeln('LZW compressed image type'); + {$ENDIF} LZWDecompressBlock( Block._Data, Block._Size, BitmapOutputPointer, @@ -353,35 +363,25 @@ begin > BitmapData + TotalSize ) then assert( false ); -{ NOTE: This doesn't seem right. It moves the pointer so later the moving of data to - ImageData will be wrong! } -// inc( BitmapOutputPointer, BytesWrittenFromBlock ); TPersistentObjectState + inc( BitmapOutputPointer, BytesWrittenFromBlock ); end; - i := TotalSize + SizeOf(_Header) + GetPaletteSize; - img := CreateImage_BMP(BitmapData, i); - - AllocateImage(32, _Header.cx, _Header.cy); - {$IFDEF LZW_DEBUG} - writeln('Width = ', Width); - writeln('Height = ', Height); - writeln('ImageDataSize = ', ImageDataSize); - writeln('------------- START -------------'); - for i := 1 to ImageDataSize do - begin - write(HexStr(BitmapOutputPointer[i-1],2)+' '); - if (i mod 16 = 0) then - writeln('') - else if (i mod 4 = 0) then - write (' | '); - end; - Writeln(''); - writeln('------------- END -------------'); + // write the decompressed image to a .BMP file to verify it is okay + s := TFileStream.Create(Format('/tmp/image_%d.bmp', [TotalSize]), fmCreate); + BitmapData[0] := Byte('B'); + s.WriteBuffer(BitmapData^, TotalSize); + s.Destroy; + BitmapData[0] := Byte('b'); {$ENDIF} -// Move(BitmapOutputPointer^, ImageData^, ImageDataSize); - Move(img.ImageData^, self.ImageData^, img.ImageDataSize); + img := CreateImage_BMP(BitmapData, TotalSize); + + FreeImage; // just as a precaution + AllocateImage(32, _Header.cx, _Header.cy); + // copy imagedata from the img instance to our THelpBitmap.ImageData + MemCopy(img.ImageData^, self.ImageData^, img.ImageDataSize); + UpdateImage; img.Free; diff --git a/docview/src/docview_clean.prj b/docview/src/docview_clean.prj new file mode 100644 index 00000000..829ae97f --- /dev/null +++ b/docview/src/docview_clean.prj @@ -0,0 +1,381 @@ +[projectoptions] +mainfile=docview.lpr +targetfile=${PROJECTNAME}${EXEEXT} +messageoutputfile= +makecommand=${COMPILER} +makedir= +unitdirs=8 + ../components/richtext + ${FPTest}3rdparty/epiktimer/ + ${FPTest}src/ + ${FPGUI}/src + ${FPGUI}/src/corelib/gdi + ${FPGUI}/src/corelib/x11 + ${FPGUI}/src/gui + ${FPGUI}/src/corelib +unitpref=-Fu +incpref=-Fi +libpref=-Fl +objpref=-Fo +targpref=-o +befcommand=0 +aftcommand=0 +makeoptions=6 + -l -Mobjfpc -Sh + -gl -O- + -B + -O2 -XX -Xs -CX + -FUunits/${TargetCPU}-${TargetOS}/ + -gh +codetemplatedirs=1 + ${TEMPLATEDIR} +toolmenus=1 + fpGUI &UI Designer +toolfiles=1 + ${FPGUI_DIR}/uidesigner/units/${TargetCPU}-${TargetOS}/uidesigner${EXEEXT} +toolparams=1 + ${CURSOURCEFILE} +fontnames=0 +scriptbeforecopy= +scriptaftercopy= +newprojectfiles=4 + ${TEMPLATEDIR}/fptest/program.pas + ${TEMPLATEDIR}fpgui/units/i386-linux/placeholder.txt + ${TEMPLATEDIR}fpgui/units/i386-win32/placeholder.txt + ${TEMPLATEDIR}fpgui/units/x86_64-linux/placeholder.txt +newprojectfilesdest=4 + ${%PROJECTNAME%}.pas + ${%PROJECTDIR%}units/i386-linux/placeholder.txt + ${%PROJECTDIR%}units/i386-win32/placeholder.txt + ${%PROJECTDIR%}units/x86_64-linux/placeholder.txt +newfinames=3 + Program + Test Unit + Textfile +newfifilters=3 + "*.pas" "*.pp" + "*.pas" "*.pp" + +newfiexts=3 + pas + pas + +newfisources=3 + ${TEMPLATEDIR}fptest/program.pas + ${TEMPLATEDIR}fptest/unit.pas + +newfonames=2 + Mainform + Simple Form +newfonamebases=2 + + +newfosources=2 + ${TEMPLATEDIR}fpgui/mainform.pas + ${TEMPLATEDIR}fpgui/simpleform.pas +newfoforms=2 + + +forcezorder=0 +stripmessageesc=0 +copymessages=0 +closemessages=0 +checkmethods=1 +colorerror=-1610612712 +colorwarning=-1610612717 +colornote=-1610612716 +usercolors=30 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +usercolorcomment=30 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +formatmacronames=0 +formatmacrovalues=0 +settingsfile=docview_clean.prj +settingseditor=1 +settingsdebugger=1 +settingsstorage=1 +settingsprojecttree=0 +settingsautoload=0 +settingsautosave=0 +modulenames=0 +moduletypes=0 +modulefiles=0 +befcommandon=0 +makeoptionson=6 + 63 + 31 + 34 + 32 + 63 + 60 +aftcommandon=0 +unitdirson=8 + 65599 + 65599 + 65599 + 196671 + 196640 + 196639 + 65581 + 196647 +macroon=7 + 9 + 3 + 6 + 4 + 8 + 63 + 63 +macronames=7 + TargetCPU + TargetOS + TargetCPU + TargetOS + TargetOS + HelpPath + FPTest +macrovalues=7 + x86_64 + linux + i386 + win32 + freebsd + /data/devel/FPC_Docs/inf/ + /data/devel/fptest/ +macrogroup=3 +groupcomments=6 + Linux 64-bit + Linux 32-bit + Windows 32-bit + FreeBSD 64-bit + + +toolsave=1 + -1 +toolhide=1 + 0 +toolparse=1 + 0 +toolmessages=1 + 0 +fontalias=0 +fontancestors=0 +fontheights=0 +fontwidths=0 +fontoptions=0 +fontxscales=0 +expandprojectfilemacros=4 + 1 + -1 + -1 + -1 +loadprojectfile=4 + 1 + 0 + 0 + 0 +newinheritedforms=2 + 0 + 0 +uid=0 +sourcefilemasks=5 + "*.pas" "*.dpr" "*.pp" "*.inc" "*.lpr" + "*.c" "*.cc" "*.h" + "*.mfm" + "*.ipf" + "*.sql" +syntaxdeffiles=5 + ${SYNTAXDEFDIR}pascal_dark.sdef + ${SYNTAXDEFDIR}cpp.sdef + ${SYNTAXDEFDIR}objecttext.sdef + ${SYNTAXDEFDIR}ipf2.sdef + ${SYNTAXDEFDIR}sql.sdef +filemasknames=5 + Source + Forms + Text + IPF help + All Files +filemasks=5 + "*.pp" "*.pas" "*.inc" "*.dpr" "*.lpr" + frm_*.pas + *.txt + *.ipf + * +showgrid=1 +snaptogrid=1 +moveonfirstclick=1 +noformdesignerdocking=0 +gridsizex=8 +gridsizey=8 +autoindent=1 +blockindent=2 +linenumberson=1 +rightmarginon=1 +rightmarginchars=80 +scrollheight=0 +tabstops=2 +spacetabs=1 +showtabs=0 +tabindent=0 +editfontname=Raize +editfontheight=16 +editfontwidth=0 +editfontextraspace=0 +editfontcolor=-1879048183 +editbkcolor=-1879048186 +statementcolor=14745599 +editfontantialiased=1 +editmarkbrackets=1 +backupfilecount=0 +encoding=0 +codetemplatedirs=1 + ${TEMPLATEDIR} +debugcommand=${DEBUGGER} +debugoptions= +debugtarget= +runcommand= +xtermcommand=xterm -S${PTSN}/${PTSH} +remoteconnection= +uploadcommand= +gdbprocessor=x86_64 +gdbservercommand= +gdbservercommandattach= +beforeconnect= +afterconnect= +beforeload= +afterload= +beforerun= +sourcebase= +sourcedirs=16 + ../components/richtext/ + ${FPCDIR}src/rtl/${TargetCPU}/ + ${FPCDIR}src/rtl/inc/ + ${FPCDIR}src/rtl/linux/${TargetCPU}/ + ${FPCDIR}src/rtl/linux/ + ${FPCDIR}src/rtl/unix/ + ${FPCDIR}src/rtl/objpas/sysutils/ + ${FPCDIR}src/rtl/objpas/classes/ + ${FPCDIR}src/rtl/objpas/ + ${FPTest}/ + ${tiOPF}Options/ + ${tiOPF}Core/ + ${FPGUI}/src/corelib/gdi/X/ + ${FPGUI}/src/corelib/x11/ + ${FPGUI}/src/*/ + ./ +defines=0 +progparameters=/data/devel/fpgui/docview/docs/IPFREF_v4.INF +progworkingdirectory= +envvarnames=0 +envvarvalues=0 +defineson=0 +stoponexception=0 +valuehints=1 +activateonbreak=1 +raiseonbreak=1 +showconsole=1 +externalconsole=0 +settty=1 +gdbdownload=0 +downloadalways=0 +startupbkpt=0 +startupbkpton=0 +gdbsimulator=0 +gdbserverstartonce=0 +gdbloadtimeout= +gdbserverwait=0 +nogdbserverexit=0 +gdbservertty=0 +exceptclassnames=1 + EconvertError +exceptignore=1 + 0 +nodebugbeginend=0 +sigsettings=27 + 1,1,T,F + 3,3,T,F + 4,4,T,F + 6,6,T,F + 7,7,T,F + 8,8,T,F + 9,9,T,F + 10,10,T,F + 11,11,T,F + 12,12,T,F + 13,13,T,F + 15,15,T,F + 16,16,T,F + 17,17,F,F + 18,18,T,F + 19,19,T,F + 20,20,T,F + 21,21,T,F + 22,22,T,F + 23,23,T,F + 24,24,T,F + 25,25,T,F + 26,26,T,F + 27,27,T,F + 28,28,T,F + 29,29,T,F + 30,30,T,F +defaultmake=4 diff --git a/docview/src/frm_main.pas b/docview/src/frm_main.pas index a74b4027..27f2c51a 100644 --- a/docview/src/frm_main.pas +++ b/docview/src/frm_main.pas @@ -1747,6 +1747,7 @@ begin // Now load the various parts of the file(s) // into the user interface DisplayFiles( tmpHelpFiles, FirstContentsNode ); + tmpHelpFiles.Free; //if CmdLineParameters.getHelpManagerFlag then // ShowLeftPanel := Settings.ShowLeftPanel_Help diff --git a/docview/src/lzwdecompress.pas b/docview/src/lzwdecompress.pas index 0ebba38c..6645890c 100644 --- a/docview/src/lzwdecompress.pas +++ b/docview/src/lzwdecompress.pas @@ -1,7 +1,8 @@ { fpGUI - Free Pascal GUI Toolkit - Copyright (C) 2006 - 2013 See the file AUTHORS.txt, included in this + Copyright (C) 2001 - Aaron Lawrence (aaronl@consultant.com) + Copyright (C) 2006 - 2015 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, @@ -24,9 +25,9 @@ interface uses SysUtils, types; -procedure LZWDecompressBlock( pbInput: pByte; +procedure LZWDecompressBlock( pbInput: PByte; number_bytes: LongWord; - pbOutput: PBYTE; + pbOutput: PByte; Var bytesOut: LongWord; Var FinalCode: byte ); @@ -57,9 +58,9 @@ Implementation * Variables renamed etc to make things clearer. */ *) -// -- Stuff for LZW decompression -- */ +// -- Stuff for LZW decompression -- const INIT_BITS = 9; -const MAX_BITS = 12; //PLF Tue 95-10-03 02:16:56*/ +const MAX_BITS = 12; const HASHING_SHIFT = MAX_BITS - 8; {if MAX_BITS == 15 @@ -140,9 +141,11 @@ begin inc( pbInput ); end else - input_bit_buffer:= input_bit_buffer - or - ( longword( 0 ) shl ( 24 - input_bit_count ) ); + input_bit_buffer := input_bit_buffer or longword($00); +{ The C version of LZWDecompress uses only "or $00", so I'm assuming the code + below is not needed. Tested and I see no difference. } +// or +// ( longword( 0 ) shl ( 24 - input_bit_count ) ); inc( bytes_out ); inc( input_bit_count, 8 ); end; @@ -153,7 +156,7 @@ begin if bytes_out > bytes_to_read then begin - // flush static vars and quit */ + // flush static vars and quit bytes_out:= 0; input_bit_count:= 0; input_bit_buffer:= 0; @@ -167,11 +170,7 @@ end; // this takes one of the INF bitmap blocks // and decompresses it using LZW algorithms. -procedure LZWDecompressBlock( pbInput: pByte; - number_bytes: LongWord; - pbOutput: PBYTE; - Var bytesOut: LongWord; - Var FinalCode: byte ); +procedure LZWDecompressBlock(pbInput: PByte; number_bytes: LongWord; pbOutput: PByte; var bytesOut: LongWord; var FinalCode: byte); var nextAvailableCode: LongWord; currentCode: LongWord; @@ -196,40 +195,40 @@ begin begin if clear_flag then begin - clear_flag:= false; - lastCode:= currentCode; - character:= currentCode; + clear_flag := false; + lastCode := currentCode; + character := currentCode; - pbOutput^:= currentCode; + pbOutput^ := currentCode; inc( pbOutput ); - FinalCode:= currentCode; + FinalCode := currentCode; inc( BytesOut ); end else if currentCode = CLEAR_TABLE then begin - clear_flag:= true; - nextAvailableCode:= FIRST_CODE; - bitsPerCode:= INIT_BITS; - maxDictionaryCode:= MaxValNBits( bitsPerCode ); + clear_flag := true; + nextAvailableCode := FIRST_CODE; + bitsPerCode := INIT_BITS; + maxDictionaryCode := MaxValNBits( bitsPerCode ); end else begin if currentCode >= nextAvailableCode then begin decode_stack[ 0 ]:= character; - theString:= decode_string( Addr( decode_stack[ 1 ] ), + theString := decode_string( Addr( decode_stack[ 1 ] ), lastCode ); end else - theString:= decode_string( Addr( decode_stack[ 0 ] ), + theString := decode_string( Addr( decode_stack[ 0 ] ), currentCode ); - character:= longword( theString^ ); + character := longword( theString^ ); while theString >= Addr( decode_stack[ 0 ] ) do begin - FinalCode:= theString^; + FinalCode := theString^; - pbOutput^:= theString^; + pbOutput^ := theString^; inc( pbOutput ); dec( TheString ); |