MarkMLl / pesdump

A dump utility for PES files as used by Brother embroidery machines
GNU General Public License v3.0
8 stars 4 forks source link

Add .gitignore, remove unused local variables and use dots and spaces instead of ones and zeros in bitmap thumbnails #2

Closed maehw closed 1 month ago

maehw commented 2 months ago

Hi @MarkMLl ,

thanks for your help in #1 !

The pesdump tool now both compiles and works!

I directly tried to contribute something back and so I created this pull request.

I made the following changes:

  1. I added a .gitignore file that lists *.ppu and *.o files and the name of the compiled executable pesdump- this prevents committing those artifacts (I almost did commit them accidentially)
  2. I've replaced the 1 and 0 in the bitmap thumbnail output by the middle dot you've already been using · and a simple space character . In my opinion this makes it easier for the eye to grasp the pattern. (Details below.)
  3. I've removed local variables that seemed to be unused, as the fpc mentioned them in warnings notes during compilation. (Details below.)

Thanks for your tool and the time you've put into it! It really seems helpful!

I am totally OK if you don't want to merge all or any of those changes as they might not add big value to the project or even break things (thinking of post-processing those thumbnail previews).


Details about the thumbnails:

I've tried to get some free PES sample files to play around. Interestingly, Brother themselves provide some here: https://sewingcraft.brother.eu/en/inspiration-and-events/projects-and-free-patterns

Even more interesting: the newer files from 2024 seem to use newer file versions (seen 0080 in the "Paw Print" and even 0100 in the "Easter bunny"). So this file format still needs to be extended with new features - I am surprised! Going further down the list, the "Magic mushrooms" (file name Embroidery202401pes.pes) is the first one that uses an older version (0001) and that worked with your tool.

From the (modified) preview in "dot-space" style:

Thumbnail colour: 0
                          |P1
                          |# Thumbnail 0, colour 26 (Light Brown)
                          |48 38
055A2  00 00 00·00 00 00  |                                                
055A8  F0 FF FF·FF FF 0F  |    ········································    
055AE  08 00 00·00 00 10  |   ·                                        ·   
055B4  04 00 00·00 00 20  |  ·                                          ·  
055BA  02 00 00·00 00 40  | ·                                            · 
055C0  02 00 00·1C 00 40  | ·                        ···                 · 
055C6  02 00 00·7E 00 40  | ·                       ······               · 
055CC  02 00 60·7F 00 40  | ·                   ·· ·······               · 
055D2  02 00 F8·FF 00 40  | ·                 ·············              · 
055D8  02 00 FC·FF 01 40  | ·                ···············             · 
055DE  02 00 FE·FF 01 40  | ·               ················             · 
055E4  02 00 FF·FF 03 40  | ·              ··················            · 
055EA  02 80 FF·FF 03 40  | ·             ···················            · 
055F0  02 80 FF·FF 03 40  | ·             ···················            · 
055F6  02 80 FF·FF 00 40  | ·             ·················              · 
055FC  02 80 FF·3F 00 40  | ·             ···············                · 
05602  02 80 FF·3F 00 40  | ·             ···············                · 
05608  02 00 FF·3F 00 40  | ·              ··············                · 
0560E  02 00 F0·3C 01 40  | ·                  ····  ····  ·             · 
05614  02 00 E0·3C 01 40  | ·                   ···  ····  ·             · 
0561A  02 00 E0·3C 01 40  | ·                   ···  ····  ·             · 
05620  02 00 E0·BE 01 40  | ·                   ··· ····· ··             · 
05626  02 00 F0·FF 03 40  | ·                  ··············            · 
0562C  02 00 F0·FF 03 40  | ·                  ··············            · 
05632  02 00 F0·FF 03 40  | ·                  ··············            · 
05638  02 00 F8·FF 03 40  | ·                 ···············            · 
0563E  02 00 FC·FF 03 40  | ·                ················            · 
05644  02 00 FE·FF 03 40  | ·               ·················            · 
0564A  02 00 FE·FE 03 40  | ·               ······· ·········            · 
05650  02 00 FF·FE 03 40  | ·              ········ ·········            · 
05656  02 00 FF·FF 01 40  | ·              ·················             · 
0565C  02 00 FF·FF 01 40  | ·              ·················             · 
05662  02 80 F7·9F 00 40  | ·             ···· ·········  ·              · 
05668  02 00 83·1E 00 40  | ·              ··     · ····                 · 
0566E  04 00 00·00 00 20  |  ·                                          ·  
05674  08 00 00·00 00 10  |   ·                                        ·   
0567A  F0 FF FF·FF FF 0F  |    ········································    
05680  00 00 00·00 00 00  |
...
Thumbnail colour: 7
                          |P1
                          |# Thumbnail 7
                          |48 38
05BDE  00 00 00·00 00 00  |                                                
05BE4  F0 FF FF·FF FF 0F  |    ········································    
05BEA  08 00 00·00 00 10  |   ·                                        ·   
05BF0  04 00 00·00 00 20  |  ·                                          ·  
05BF6  02 00 00·00 00 40  | ·                                            · 
05BFC  02 00 00·1C 00 40  | ·                        ···                 · 
05C02  02 00 00·36 00 40  | ·                       ·· ··                · 
05C08  02 00 40·57 00 40  | ·                    · ··· · ·               · 
05C0E  02 00 F0·E5 00 40  | ·                  ····· ·  ···              · 
05C14  02 00 6C·E7 01 40  | ·                ·· ·· ···  ····             · 
05C1A  02 00 34·D6 01 40  | ·                · ··   ·· · ···             · 
05C20  02 00 E3·96 03 40  | ·              ··   ··· ·· ·  ···            · 
05C26  02 80 21·7F 03 40  | ·             ··    ·  ······· ··            · 
05C2C  02 80 A7·D1 03 40  | ·             ····  · ··   · ····            · 
05C32  02 80 E7·FE 00 40  | ·             ····  ··· ·······              · 
05C38  02 80 0F·1F 00 40  | ·             ·····    ·····                 · 
05C3E  02 00 0F·2F 00 40  | ·              ····    ···· ·                · 
05C44  02 00 FE·27 00 40  | ·               ··········  ·                · 
05C4A  02 00 A0·24 01 40  | ·                   · ·  ·  ·  ·             · 
05C50  02 00 A0·24 01 40  | ·                   · ·  ·  ·  ·             · 
05C56  02 00 A0·3C 01 40  | ·                   · ·  ····  ·             · 
05C5C  02 00 A0·BE 01 40  | ·                   · · ····· ··             · 
05C62  02 00 A0·EB 01 40  | ·                   · ··· · ····             · 
05C68  02 00 90·EF 02 40  | ·                  ·  ····· ··· ·            · 
05C6E  02 00 90·90 00 40  | ·                  ·  ·    ·  ·              · 
05C74  02 00 98·FF 02 40  | ·                 ··  ········· ·            · 
05C7A  02 00 9C·F9 02 40  | ·                ···  ··  ····· ·            · 
05C80  02 00 BE·7F 03 40  | ·               ····· ········ ··            · 
05C86  02 00 BE·F6 03 40  | ·               ····· · ·· ······            · 
05C8C  02 00 FE·E6 01 40  | ·               ······· ··  ····             · 
05C92  02 00 FF·AE 00 40  | ·              ········ ··· · ·              · 
05C98  02 00 FB·3E 00 40  | ·              ·· ····· ·····                · 
05C9E  02 00 A0·1C 00 40  | ·                   · ·  ···                 · 
05CA4  02 00 00·00 00 40  | ·                                            · 
05CAA  04 00 00·00 00 20  |  ·                                          ·  
05CB0  08 00 00·00 00 10  |   ·                                        ·   
05CB6  F0 FF FF·FF FF 0F  |    ········································    
05CBC  00 00 00·00 00 00  |

The same file in "ones-zeros" style:

Thumbnail colour: 0
                          |P1
                          |# Thumbnail 0, colour 26 (Light Brown)
                          |48 38
055A2  00 00 00·00 00 00  |000000000000000000000000000000000000000000000000
055A8  F0 FF FF·FF FF 0F  |000011111111111111111111111111111111111111110000
055AE  08 00 00·00 00 10  |000100000000000000000000000000000000000000001000
055B4  04 00 00·00 00 20  |001000000000000000000000000000000000000000000100
055BA  02 00 00·00 00 40  |010000000000000000000000000000000000000000000010
055C0  02 00 00·1C 00 40  |010000000000000000000000001110000000000000000010
055C6  02 00 00·7E 00 40  |010000000000000000000000011111100000000000000010
055CC  02 00 60·7F 00 40  |010000000000000000000110111111100000000000000010
055D2  02 00 F8·FF 00 40  |010000000000000000011111111111110000000000000010
055D8  02 00 FC·FF 01 40  |010000000000000000111111111111111000000000000010
055DE  02 00 FE·FF 01 40  |010000000000000001111111111111111000000000000010
055E4  02 00 FF·FF 03 40  |010000000000000011111111111111111100000000000010
055EA  02 80 FF·FF 03 40  |010000000000000111111111111111111100000000000010
055F0  02 80 FF·FF 03 40  |010000000000000111111111111111111100000000000010
055F6  02 80 FF·FF 00 40  |010000000000000111111111111111110000000000000010
055FC  02 80 FF·3F 00 40  |010000000000000111111111111111000000000000000010
05602  02 80 FF·3F 00 40  |010000000000000111111111111111000000000000000010
05608  02 00 FF·3F 00 40  |010000000000000011111111111111000000000000000010
0560E  02 00 F0·3C 01 40  |010000000000000000001111001111001000000000000010
05614  02 00 E0·3C 01 40  |010000000000000000000111001111001000000000000010
0561A  02 00 E0·3C 01 40  |010000000000000000000111001111001000000000000010
05620  02 00 E0·BE 01 40  |010000000000000000000111011111011000000000000010
05626  02 00 F0·FF 03 40  |010000000000000000001111111111111100000000000010
0562C  02 00 F0·FF 03 40  |010000000000000000001111111111111100000000000010
05632  02 00 F0·FF 03 40  |010000000000000000001111111111111100000000000010
05638  02 00 F8·FF 03 40  |010000000000000000011111111111111100000000000010
0563E  02 00 FC·FF 03 40  |010000000000000000111111111111111100000000000010
05644  02 00 FE·FF 03 40  |010000000000000001111111111111111100000000000010
0564A  02 00 FE·FE 03 40  |010000000000000001111111011111111100000000000010
05650  02 00 FF·FE 03 40  |010000000000000011111111011111111100000000000010
05656  02 00 FF·FF 01 40  |010000000000000011111111111111111000000000000010
0565C  02 00 FF·FF 01 40  |010000000000000011111111111111111000000000000010
05662  02 80 F7·9F 00 40  |010000000000000111101111111110010000000000000010
05668  02 00 83·1E 00 40  |010000000000000011000001011110000000000000000010
0566E  04 00 00·00 00 20  |001000000000000000000000000000000000000000000100
05674  08 00 00·00 00 10  |000100000000000000000000000000000000000000001000
0567A  F0 FF FF·FF FF 0F  |000011111111111111111111111111111111111111110000
05680  00 00 00·00 00 00  |000000000000000000000000000000000000000000000000
...
Thumbnail colour: 7
                          |P1
                          |# Thumbnail 7
                          |48 38
05BDE  00 00 00·00 00 00  |000000000000000000000000000000000000000000000000
05BE4  F0 FF FF·FF FF 0F  |000011111111111111111111111111111111111111110000
05BEA  08 00 00·00 00 10  |000100000000000000000000000000000000000000001000
05BF0  04 00 00·00 00 20  |001000000000000000000000000000000000000000000100
05BF6  02 00 00·00 00 40  |010000000000000000000000000000000000000000000010
05BFC  02 00 00·1C 00 40  |010000000000000000000000001110000000000000000010
05C02  02 00 00·36 00 40  |010000000000000000000000011011000000000000000010
05C08  02 00 40·57 00 40  |010000000000000000000010111010100000000000000010
05C0E  02 00 F0·E5 00 40  |010000000000000000001111101001110000000000000010
05C14  02 00 6C·E7 01 40  |010000000000000000110110111001111000000000000010
05C1A  02 00 34·D6 01 40  |010000000000000000101100011010111000000000000010
05C20  02 00 E3·96 03 40  |010000000000000011000111011010011100000000000010
05C26  02 80 21·7F 03 40  |010000000000000110000100111111101100000000000010
05C2C  02 80 A7·D1 03 40  |010000000000000111100101100010111100000000000010
05C32  02 80 E7·FE 00 40  |010000000000000111100111011111110000000000000010
05C38  02 80 0F·1F 00 40  |010000000000000111110000111110000000000000000010
05C3E  02 00 0F·2F 00 40  |010000000000000011110000111101000000000000000010
05C44  02 00 FE·27 00 40  |010000000000000001111111111001000000000000000010
05C4A  02 00 A0·24 01 40  |010000000000000000000101001001001000000000000010
05C50  02 00 A0·24 01 40  |010000000000000000000101001001001000000000000010
05C56  02 00 A0·3C 01 40  |010000000000000000000101001111001000000000000010
05C5C  02 00 A0·BE 01 40  |010000000000000000000101011111011000000000000010
05C62  02 00 A0·EB 01 40  |010000000000000000000101110101111000000000000010
05C68  02 00 90·EF 02 40  |010000000000000000001001111101110100000000000010
05C6E  02 00 90·90 00 40  |010000000000000000001001000010010000000000000010
05C74  02 00 98·FF 02 40  |010000000000000000011001111111110100000000000010
05C7A  02 00 9C·F9 02 40  |010000000000000000111001100111110100000000000010
05C80  02 00 BE·7F 03 40  |010000000000000001111101111111101100000000000010
05C86  02 00 BE·F6 03 40  |010000000000000001111101011011111100000000000010
05C8C  02 00 FE·E6 01 40  |010000000000000001111111011001111000000000000010
05C92  02 00 FF·AE 00 40  |010000000000000011111111011101010000000000000010
05C98  02 00 FB·3E 00 40  |010000000000000011011111011111000000000000000010
05C9E  02 00 A0·1C 00 40  |010000000000000000000101001110000000000000000010
05CA4  02 00 00·00 00 40  |010000000000000000000000000000000000000000000010
05CAA  04 00 00·00 00 20  |001000000000000000000000000000000000000000000100
05CB0  08 00 00·00 00 10  |000100000000000000000000000000000000000000001000
05CB6  F0 FF FF·FF FF 0F  |000011111111111111111111111111111111111111110000
05CBC  00 00 00·00 00 00  |000000000000000000000000000000000000000000000000

Warnings+notes from fpc after my changes:

$ fpc pesdump.lpr 
Free Pascal Compiler version 3.2.2+dfsg-9ubuntu1 [2022/04/11] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling pesdump.lpr
Compiling patchandio.pas
patchandio.pas(605,17) Warning: Local variable "patch" of a managed type does not seem to be initialized
Compiling midlevelio.pas
midlevelio.pas(354,5) Warning: Local variable "chars" of a managed type does not seem to be initialized
midlevelio.pas(804,19) Warning: function result variable of a managed type does not seem to be initialized
midlevelio.pas(849,19) Warning: function result variable of a managed type does not seem to be initialized
midlevelio.pas(894,19) Warning: function result variable of a managed type does not seem to be initialized
midlevelio.pas(939,19) Warning: function result variable of a managed type does not seem to be initialized
midlevelio.pas(976,6) Note: Local variable "r" not used
pesdump.lpr(227,3) Note: Local variable "backtrack" is assigned but never used
pesdump.lpr(521,3) Note: Local variable "backtrack" is assigned but never used
pesdump.lpr(549,3) Note: Local variable "backtrack" is assigned but never used
pesdump.lpr(590,3) Note: Local variable "backtrack" is assigned but never used
pesdump.lpr(669,3) Note: Local variable "i" not used
pesdump.lpr(730,3) Note: Local variable "backtrack" is assigned but never used
pesdump.lpr(731,12) Note: Local variable "x" not used
pesdump.lpr(731,15) Note: Local variable "y" not used
pesdump.lpr(803,3) Note: Local variable "backtrack" is assigned but never used
pesdump.lpr(1300,3) Note: Local variable "currentRoutine" not used
pesdump.lpr(210,3) Note: Local variable "waitingForPec" is assigned but never used
Linking pesdump
3947 lines compiled, 0.3 sec
6 warning(s) issued
12 note(s) issued

Warnings+notes from fpc after my changes:

$ fpc pesdump.lpr
Free Pascal Compiler version 3.2.2+dfsg-9ubuntu1 [2022/04/11] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling pesdump.lpr
Compiling patchandio.pas
patchandio.pas(605,17) Warning: Local variable "patch" of a managed type does not seem to be initialized
Compiling midlevelio.pas
midlevelio.pas(354,5) Warning: Local variable "chars" of a managed type does not seem to be initialized
midlevelio.pas(804,19) Warning: function result variable of a managed type does not seem to be initialized
midlevelio.pas(849,19) Warning: function result variable of a managed type does not seem to be initialized
midlevelio.pas(894,19) Warning: function result variable of a managed type does not seem to be initialized
midlevelio.pas(939,19) Warning: function result variable of a managed type does not seem to be initialized
pesdump.lpr(227,3) Note: Local variable "backtrack" is assigned but never used
pesdump.lpr(521,3) Note: Local variable "backtrack" is assigned but never used
pesdump.lpr(549,3) Note: Local variable "backtrack" is assigned but never used
pesdump.lpr(590,3) Note: Local variable "backtrack" is assigned but never used
pesdump.lpr(730,3) Note: Local variable "backtrack" is assigned but never used
pesdump.lpr(803,3) Note: Local variable "backtrack" is assigned but never used
pesdump.lpr(210,3) Note: Local variable "waitingForPec" is assigned but never used
Linking pesdump
3946 lines compiled, 0.3 sec
6 warning(s) issued
7 note(s) issued

(I didn't really dare to touch backtrack as this seems to be used for debugging...)

MarkMLl commented 2 months ago

Thanks, I'll take a look at those but not necessarily immediately.

The graphics character one should probably be controlled by an option: leave it with me. I'm a little uncomfortable with having it in the output stream by default since it implies either UTF-8 or some other multibyte Unicode, which would be a PITA if somebody wanted to postprocess it for some reason... debugging output is a different matter. I'll check precisely what I did and why I did it: memory is shaky after four years :-)

Those "uninitialised variable" warnings are (arguably) a compiler/library bug: there's various places where procedures/functions in the standard library are incorrectly declared with a "var" parameter when it should be "out". Some of the notes etc. can- of course- be trivially fixed, others can be hidden by a directive (which the Lazarus IDE can insert semi-automatically) to tell the compiler to not report them. However I'm reluctant to hide the library's shortcomings like that :-)

In possibly the longer term, I'll try to take a look at that format extension, but obviously a lot depends on being able to find info. I'll try to remember to ask about that on the EEVBlog forum.

Mark

maehw commented 2 months ago

Hi Mark,

thanks for your fast and detailed reply.

Sure, no rush!

Thank you very much for your time to support me in getting your tool running and for adding all the background information. — Very appreciated!

Mäh

MarkMLl commented 2 months ago

Ah yes... midlevelio.pas shows that Dot is in there as a placeholder for ASCII control characters and to mark the middle of a run of hex, and I've specifically made the actual expansion conditional on compiler version.

Late stages of FPC v2 were around for a long time, since the core team were struggling with extra targets, OSes and so on. But Unicode support was patchy...

Anyway, right now I need to get back to the ADS-B stuff related (although not derived from) the other project in my repo.

Mark

MarkMLl commented 1 month ago

I've finally got around to reconciling your changes with my local copy. I've made the dot/space vs 1/0 selection configurable (by a compiler pragma), since if a user is trying to print the file dump and for some reason can't do so in a monospaced character set digits will always have the same width while other characters probably won't.

maehw commented 1 month ago

Hi Mark,

thanks for the time and effort you took to review and communicate. It's really appreciated. Cool, that my changes could me merged.

Mäh

MarkMLl commented 1 month ago

Thanks for using and appreciating the program. I'll try to take a look at those newer formats at some point, but I'm only just coming down off the ceiling after a frantic Summer working on some seasonal stuff (certain test data is only available in dryish weather).

I think the zero-one business does highlight one thing: think carefully before outputting Unicode that might possibly be post-processed, or where a user might possibly try to print it and have character-width problems.

Mark