Tuesday, March 25, 2014

Modifying LightZone sidecar files

LightZone sidecar file

My this blog is about the internals of the LightZone sidecar file and what you can do with it. As I mentioned in one of my posts in the LightZone forum that I'll create a small utility that can extract the LightZone "receipe" from the _lzn.jpg file. The only obstacle was that I needed to learn Python first.

I found from an old unofficial LightZone blog an lzntool utility made by Alex Sidorenko. The software was created for situations where you move or rename the original raw image. Quote from the original web site: "As these two files [_lzn.jpg and RAW] are interrelated, moving/renaming them can create problems. Usually moving both files to another directory is OK (we will discuss this later). But if you change the name of your raw file, LZ will see it as unrelated to LZN-file. Just renaming the associated lzn-file will not help - you need to change the contents of LZN-file as well." So if you want to move or rename the RAW file you need do the changes in the file system and then modify the contents of the LZN file to reflect the changes.

The problem is that the LZN files are binary and the LightZone block is preceded with binary length so editing the files would require a binary editor and manual calculations for the block length. For that reason Alex created his Python program to solve this problem.  Alex explains on the web page well how to identify the LigthZone block from the JPEG file.

I took his program, converted it from Python 2 to Python 3 and added an option to extract the LZN block to a new .lzn file without the JPEG preview image. This file can then be edited with Notepad or other text editors and used in LZ. This is a command line utility and you need to have Python 3 installed.

>Python lzntool020.py --help
usage: lzntool020.py [-h] [-l] [--setrawpath SETRAWPATH]
                     [--setrawrelpath SETRAWRELPATH] [--setname SETNAME] [-t]
                     [-v] [--version]
                     fname

positional arguments:
  fname                 _lzn.jpg file

optional arguments:
  -h, --help            show this help message and exit
  -l, --list            list path names as used by LZ and exit. Adding '-v'
                        will print the whole LZ-section
  --setrawpath SETRAWPATH
                        Modify RAW file pathname in LZN-file. This does not
                        rename the real RAW-file
  --setrawrelpath SETRAWRELPATH
                        Modify RAW file relpathname in LZN-file. This does not
                        rename the real RAW-file
  --setname SETNAME     Modify both path and relPath by changing name only, do
                        not modify the directory parts
  -t, --text            Extract the LZN info from the file and store it as
                        .lzn file
  -v                    verbose output
  --version             Display version information and exit.

There are some issues you need to be aware
  • if you specify --setname and --setrawpath and/or --setrawrelpath the --setname will be overwritten by the two other parameters
  • using the .lzn file in LightZone has some issues (see below)

LightZone opens the .lzn file without any problems. The problem I haven't been able to solve is how to make LZ to save the changes as .lzn. Currently LZ saves the changes with the preview image (like _lzn.jpg). This file generates an error in LZ when reopened unless the .lzn is renamed to _lzn.jpg, then LZ works fine. The error message is "Error reading the file Couldn't read XML:com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence."

I looked at the source code in github and guessed that setting <Save type="LZN"> would work. But when I try to open the file in LZ I get an error "Malformed LightZone file No valid SaveOptions data". For time being I have left the  <Save type="JPEG (sidecar)"> with the side effects.

Has the support for saving as .lzn been removed in some older version even the backwards compatibility to read the .lzn files has been kept? I hope someone having better understanding of the insides of LZ could help me.

Download

No comments: