Lets say we have a bitonal image
example_bw.tif like
- Black/White layer of example text image example_bw.tif
- example_bw.jpg (20.39 KiB) Viewed 13714 times
We do a conversion with our favorite DJVU/bw tool, e.g.
minidjvu or
cjb2, e.g.
Code: Select all
cjb2 -dpi 100 -lossy example_bw.tif example_bw.djvu
to create the DJVU text mask
example_bw.djvu.
To add color to this DJVU-document, load the image
example_bw.tif into your favorite graphic editor.
I will use
gimp. Now do the following tasks:
- Change image mode to RGB.
- Swap black/white with color inversion.
- Make this text layer transparent.
- Delete the now white non text area.
- Add a new non-transparent layer filled with black below this text layer and select it for editing.
Now use the rectangle tool to select areas which contain letters to be filled with a specific color
and fill the rectangle with the wanted color. I like to do this by specifying a background color and subsequently typing the delete key.
We may get a situations like
- Colored rectangles in GIMP
- example_color.jpg (26.61 KiB) Viewed 13714 times
Now delete the text layer (or make it unvisible). Then save the image to a PPM file, e.g.
example_rect.ppm.
This should look like
- Saved PPM image with rectangular color information, file example_rect.ppm
- example_rect.jpg (4.06 KiB) Viewed 13714 times
Then use my utility
ppmrectlist from the above mentioned toolkit in Your favorite operating system:
Code: Select all
ppmrectlist example_rect.ppm > example_rect.txt
This generates the rectangle color information we need. The content of the file
example_rect.txt
looks like
Code: Select all
#4be1a3:111,184,52,33#df5140:63,72,109,50#636ed7:117,13,128,52
Finally feed this file at the appropriate place into
djvumake:
Code: Select all
djvumake example.djvu INFO=,,100 Sjbz=example_bw.djvu FGbz=`cat example_rect.txt`
You can combine both programs within one call if You like:
Code: Select all
djvumake example.djvu INFO=,,100 Sjbz=example_bw.djvu FGbz=`ppmrectlist example_rect.ppm`
If You are using Windows You have to specify the content of the file
example_rect.txt instead of the last quoted terms.
Or You use
cygwin with a unix shell. The quotes will execute the system command
cat, which displays the
content of the file like
type in windows and splice the result as text in the
djvumake command.
Now the DJVU-file
example.djvu should contain our final result und should look like
- Final colored DJVU file example.djvu
- example.jpg (23.57 KiB) Viewed 13714 times
The file size of this (ridiculous) example
example_bw.djvu is 458 bytes. The file size of the color augmented result
example.djvu is 520 bytes. For more realistic file sizes, the increase in file size remains negligible.
Note that due to the implementation of
djvumake each rectangle of the image increases the final file size by three bytes
(a RGB color palette entry in the FGbz chunk). The other increment in file size is due to a compressed (with BZZ) index table with
16bit entries into the above color palette for each encoded text symbol.
Note that it is not crucial that a text character is fully contained in a rectangle to obtain the respective color. But if there are
unconnected parts (like the dot of the letter "i" in our example) their bounding boxes must all intersect the corresponding rectangle.
If there are multiple rectangles intersecting the bounding box of a letter, the last rectangle wins.