I'd like to create a bitmap (black and white) from within LuaTeX (or pdfTeX) and rescale it afterwards. For example (a 4×4 bitmap) could be made by
\makebitmap{0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0}
I don't really care about the interface. More important for me is the overall approach.
I would like to use it in LuaTeX, thus img.stream
could be useful for me. But a PDFTeX approach with \pdf...
commands would be fine, too.
Important restrictions: I must not create any intermediate file and it must work offline.
To make things clear: I am only interested in how to generate a bitmap graphics (png, bmp, whatever) within pdf/LuaTeX.
Background: I've developed a qrcode encoding lua library and I'd like make a LuaLaTeX package for it. I see three possible approaches:
- Use pdf instructions (
0 0 10 10 re f
for example) - Use
\rule
commands to make the black parts - Create a bitmap "file" and scale it.
I still experiment about the best approach.
I have tried with pdf instructions (item 1 above), and the result is ugly in some pdf viewer applications:
The black boxes are divided by some small white lines in some zoom settings. I want to avoid them. That is why I want to create bitmaps instead of pdf instructions.
Best Answer
For this you need to create and add a PDF object (using
\pdfobj
I guess; see thepdftex
manual) into the PDF which holds the (binary?) representation of the image and then reference this object where you like the image being shown. This is what\includegraphics
does for PDF output.Accroding to he PDF reference (31MB!), section 3.3.6 JBIG2Decode Filter the JBIG2 format was especially created for monochrome images like this. The best thing here is that it object stream can be given in ASCII, avoiding the need to handle binary material in TeX.
The following example is given there. I don't think there should be an issue adding this to a PDF using
\pdfobj
. You "only" need to produce the JBIG2 encoding of your image, which should be possible using Lua.I will try to create a LaTeX example file showing the principle.
So far I only figured out how to create the objects, but not how to display the image in the document.