On 13 Nov 2013, at 10:18, Joris van der Hoeven <[email protected]> wrote:
> On Tue, Nov 12, 2013 at 11:22:40PM +0100, Massimiliano Gubinelli wrote: >>> As to pure image formats (jpg, png, tiff, svg, etc.), I would like to avoid >>> depending on too many libraries. Ideally, Qt should be able to do them >>> all for us. If not, Qt in combination with a tool such as ImageMagick >>> which supports many different formats. I agree that it is best to touch >>> images files as little as possible when including them in Pdf output. >>> Is there a way to include them in some kind of verbatim/escaped fashion? >> >>> I still don't understand why libpng and the jpeg library would be necessary. >> >> I was looking to how pdftex handle the problem. If I understand well their >> code they can include directly jpg images without any external support (and >> without uncompressing the jpg stream). For png they rely on libpng to read >> the files. I think I can use Qt to read the actual bits and obtain enough >> information (DPI, color depth, color map, to reconstruct a faithful >> representation of the png data inside the pdf). > > I still don't understand something. > How exactly are png and jpg images stored in Pdf files? > If they are compressed in the standard png/jpg way, > then I would expect the images to be included in > a verbatim/escaped way. If they are compressed in > an ad hoc Pdf way, then why would we need libpng, > except for obtaining the pixmaps (which Qt can give us)? > PDF has various encoding possibilities for images, some of them corresponds to particular cases of PNG and JPG. In these cases a direct copy of the compressed images and a straighforward translation of the metadata is enough, in the other cases the data has to be reencoded, for example by writing the pixels and then using standard lossless compression methods for PDF streams which are for free already in the library. For JPG I can do without jpg library I found some simple code in pdfTeX to do the job. Strangely I didn't found any example to read directly png images, all the software I found uses the png library. I'm not sure I want to spend much time on this issue. Also if we decide to use ImageMagick then all this is somewhat useless since ImageMagick can treat all the formats and more. But I'm not sure it will do the best job, especially for lossy formats. I found this page https://github.com/josch/img2pdf which comments how direct inclusion for jpg provide better results than programs like ImageMagick. >> The point is that ideally one should keep (lossy and lossless) compressed >> formats compressed. Qt can read all the formats but give back only the >> uncompressed bits, so this is almost useless if you want to put the image >> into a compressed file format like PDF. The point is to try to maintain the >> data compressed without wasting time in uncompressing it and then >> recompressing it (in necessarily unoptimal ways). > > I agree that compressed images should not be touched. > But if we do not want to touch them, why do we need libpng? > As said above: you cannot simply copy the image file, you have to put the metadata in some format and then put elsewhere the compressed streams into proper PDF structures. >>> There is also the question of producing image files directly from TeXmacs, >>> for instance when exporting mathematical formulas to Html. What exactly >>> does Qt provide for the manipulation of image _files_? >> >> Qt can produce images (especially raster) to any common format (png, maybe >> jpg, pdf and eps) so I think there are no problem producing them. > > Does Qt also perform the corresponding compression? > I do not know. PDF provide basic compression (Zip) so things are not very bad and lossy compression is not very useful for images generated in TeXmacs so I do not think this is a main issue. My main worry is to treat properly (at least in PDF) lossy image formats like JPG and for that I think I found a solution which does not involve the jpg library or external programs. Max > Best wishes, --Joris > > _______________________________________________ > Texmacs-dev mailing list > [email protected] > https://lists.gnu.org/mailman/listinfo/texmacs-dev _______________________________________________ Texmacs-dev mailing list [email protected] https://lists.gnu.org/mailman/listinfo/texmacs-dev
