Mercurial > hgrepos > Python2 > PyMuPDF
view mupdf-source/docs/examples/pdf-dejpx.js @ 38:8934ac156ef5
Allow to build with the PyPI package "clang" instead of "libclang".
1. It seems to be maintained.
2. In the FreeBSD base system there is no pre-built libclang.so. If you
need this library you have to install llvm from ports additionally.
2. On FreeBSD there is no pre-built wheel "libclang" with a packaged
libclang.so.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Tue, 23 Sep 2025 10:27:15 +0200 |
| parents | b50eed0cc0ef |
| children |
line wrap: on
line source
// Find all JPEG-2000 images and turn them into regular images. var doc = Document.openDocument(scriptArgs[0]); function isJPXImage(ref) { if ("Filter" in ref) { var filter = ref.Filter; if (filter == "JPXDecode") return true; if (filter.isArray()) for (var i = 0; i < filter.length; ++i) if (filter[i] == "JPXDecode") return true; } return false; } var i, n, ref; var jpxList = {}; var smaskList = {}; // Preload and destroy all JPX images. n = doc.countObjects(); for (i=1; i < n; ++i) { ref = doc.newIndirect(i, 0); if (isJPXImage(ref)) { print("Loading JPX image:", i) jpxList[i] = doc.loadImage(ref); if ("SMask" in ref) smaskList[i] = ref.SMask; ref.writeObject(null); // make sure we don't reuse the JPX image resource } } for (i in jpxList) { ref = doc.newIndirect(i, 0); var jpx = jpxList[i]; var pix = jpx.toPixmap(); var raw = new Image(pix); // Create a new image, then copy the data to the old object, then delete it. print("Decompressed image:", i); var img = doc.addImage(raw); if (i in smaskList) img.SMask = smaskList[i]; ref.writeObject(img.resolve()); ref.writeRawStream(img.readRawStream()); doc.deleteObject(img); // Invoke the GC to free intermediate pixmaps and images. gc(); } doc.save(scriptArgs[1], "compress,garbage=compact");
