# pdfTeX and JPEG2000

In Which graphics formats can be included in documents processed by latex or pdflatex?, the answers indicate that that pdfLaTeX understands JPEG2000. For me it doesn't work and the above link seems to be about the only place where a `.jp2`-positive statement is made.

Could someone please clarify the matter for me?

-
Are you using it as `\includegraphics{file.jp2}`? What about renaming it to `.jpg`? – Werner Feb 2 '14 at 18:55
"it doesn't work" is a useless message. Please read chiark.greenend.org.uk/~sgtatham/bugs.html – Martin Schröder Feb 2 '14 at 19:46
@Heiko It is a statement of not much use, indeed. Sorry. I tried giving the file in question a `.jpg` extension. Pdftex then says, "reading JPEG image failed (no JPEG header found)", which could be expected with a file in JPEG2000 format. When I include the file by `\includegraphics{file.jb2}`, i.e., with the explicit extension, I get "readfilehdr(): reading JBIG2 image file failed: ID string missing". Could this mean there is something wrong with my file? If it means anything, Irfanview recognizes the format and displays the file correctly. – AgoraPD Feb 2 '14 at 20:03
That answer was wrong; fixed. – Martin Schröder Feb 2 '14 at 22:45

pdfTeX cannot handle JPEG2000 images, but LuaTeX can.

For LuaTeX `pdftex.def` can be extended to support `.jp2` as file extension for JPEG2000 files:

Workaround:

``````\usepackage{graphicx}
\usepackage{ifluatex}
\ifluatex
\usepackage{ifpdf}
\ifpdf
\expandafter\ifx\csname Gin@rule@.jp2\endcsname\relax
\DeclareGraphicsRule{.jp2}{jpg}{.jp2}{#1}
\DeclareGraphicsRule{.JP2}{jpg}{.JP2}{#1}
\usepackage{grfext}
\AppendGraphicsExtensions{.jp2,.JP2}
\fi
\fi
\fi
``````

This adds a rule for `.jp2` (and the uppercase variant `.JP2`) and adds the extension to the search list of the supported graphics extensions.

A small test file worked for AR9.5.5/Linux, but other PDF viewers (xpdf 3.03, ghostscript 9.05, evince 3.4.0) are not able to display the image properly.

-
You're mixing JBIG2 and JPEG2000 images. – Martin Schröder Feb 2 '14 at 19:49
This doesn't help, I am afraid. The error message I now get is, "unknown type of image". Can you confirm that pdfLaTeX is able to handle JPEG2000 files? – AgoraPD Feb 2 '14 at 20:22
@MartinSchröder: Thanks, fixed. – Heiko Oberdiek Feb 2 '14 at 20:25
I am confused. Does luaTeX support JPEG2000 or not? – AlexG Feb 2 '14 at 21:26
@AlexG: I had converted a file with `image_to_j2k` to `.jp2` and LuaTeX 0.76.0 could read/include it in the output PDF file. Also the documentation of LuaTeX (4.5.8 img.types) says, that JPEG 2000 is supported. – Heiko Oberdiek Feb 2 '14 at 22:07

You may want to convert j2 to jpg by opening it in GIMP (which will take a while and throw a message about converting to sRGB), then export to jpg (or whatever else)

-