From jeffz at jeffz.name Sun May 6 10:14:19 2007 From: jeffz at jeffz.name (jeffz) Date: Sun, 6 May 2007 20:14:19 +1000 Subject: [cl-pdf-devel] creating pdfs with many pages Message-ID: <20070506101419.GA2842@jeffz.name> Hi I'm fairly new to common lisp and have just today come accross cl-pdf. I thought I'd try stripping down one of the examples and creating a pdf with many pages. Using cl-pdf-current.tar.gz and sbcl 1.0.5 on GNU/Linux, I tested as follows: (asdf:oos 'asdf:load-op :cl-pdf) (defun example4 (&optional (file #P"/tmp/ex4.pdf")) (pdf:with-document () (loop for i from 1 to 1000 do (pdf:with-page () (pdf:with-outline-level ((format nil "Page ~d" i)(pdf:register-page-reference))))) (pdf:write-document file))) (example4) This creates the pdf successfully. $ ls -ltr /tmp/ex4.pdf -rw-r--r-- 1 jeffz jeffz 455424 2007-05-06 19:53 /tmp/ex4.pdf However, if I say (loop for i from 1 to 1001 ... The pdf is not created, which leaves me a bit confused. Am I doing something wrong? Thanks in advance, Jeff From marc.battyani at fractalconcept.com Sun May 6 10:29:39 2007 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Sun, 6 May 2007 12:29:39 +0200 Subject: [cl-pdf-devel] creating pdfs with many pages References: <20070506101419.GA2842@jeffz.name> Message-ID: <052a01c78fc9$738c4700$1402a8c0@marcx2> "jeffz" wrote: > Hi > > I'm fairly new to common lisp and have just today come accross cl-pdf. > > I thought I'd try stripping down one of the examples and creating a > pdf with many pages. Using cl-pdf-current.tar.gz and sbcl 1.0.5 on > GNU/Linux, I tested as follows: > > (asdf:oos 'asdf:load-op :cl-pdf) > > (defun example4 (&optional (file #P"/tmp/ex4.pdf")) > (pdf:with-document () > (loop for i from 1 to 1000 > do (pdf:with-page () > (pdf:with-outline-level ((format nil "Page ~d" > i)(pdf:register-page-reference))))) > (pdf:write-document file))) > > (example4) > > This creates the pdf successfully. > > $ ls -ltr /tmp/ex4.pdf > -rw-r--r-- 1 jeffz jeffz 455424 2007-05-06 19:53 /tmp/ex4.pdf > > However, if I say (loop for i from 1 to 1001 ... > > The pdf is not created, which leaves me a bit confused. > > Am I doing something wrong? Just change the *max-number-of-pages* value in config.lisp ;-) Have fun, Marc From jeffz at jeffz.name Sun May 6 11:57:36 2007 From: jeffz at jeffz.name (jeffz) Date: Sun, 6 May 2007 21:57:36 +1000 Subject: [cl-pdf-devel] creating pdfs with many pages In-Reply-To: <052a01c78fc9$738c4700$1402a8c0@marcx2> References: <20070506101419.GA2842@jeffz.name> <052a01c78fc9$738c4700$1402a8c0@marcx2> Message-ID: <20070506115736.GB2842@jeffz.name> On Sun, May 06, 2007 at 12:29:39PM +0200, Marc Battyani wrote: > "jeffz" wrote: > > >Am I doing something wrong? > > Just change the *max-number-of-pages* value in config.lisp ;-) > > Have fun, > > Marc > > Ah ha... thanks :) how brainless of me. Thank you for what looks to be an excellent package! From ch-lisp at bobobeach.com Wed May 9 00:31:13 2007 From: ch-lisp at bobobeach.com (Cyrus Harmon) Date: Tue, 8 May 2007 17:31:13 -0700 Subject: [cl-pdf-devel] cl-pdf image question Message-ID: Ok, I'm probably doing something here, but when I try: (cl:defpackage #:cl-pdf-test (:use #:cl)) (cl:in-package :cl-pdf-test) (defun png-test (file) (pdf:with-document () (let ((pdf-image (pdf::make-image file))) (pdf:with-page () (pdf:add-images-to-page pdf-image) (pdf:draw-image pdf-image 300 300 500 300 0 t))) (pdf:write-document (merge-pathnames (make-pathname :type "pdf") file)))) ;;; doesn't work (png-test "circles.png") ;;; works (png-test "circles-small.png") where circles-small is a cropped version of the bigger png, circles- small works as expected, but the big image either prints nothing or a single black line. I've attached a tgz with the images in question. I'm new to cl-pdf, so this could very easily be operator error, but, nevertheless, I'm a bit stumped. Thanks, Cyrus -------------- next part -------------- A non-text attachment was scrubbed... Name: cl-pdf-test.tgz Type: application/octet-stream Size: 24848 bytes Desc: not available URL: -------------- next part -------------- From ch-lisp at bobobeach.com Wed May 9 05:29:17 2007 From: ch-lisp at bobobeach.com (Cyrus Harmon) Date: Tue, 8 May 2007 22:29:17 -0700 Subject: [cl-pdf-devel] encoding question Message-ID: So, now that I'm finally getting around to exploring cl-pdf a bit, I'm running across issues that others have run into before. Is there any documentation on the encoding besides just seeing what's in encodings.lisp and in the pdf file? I don't know a lot about SBCLs encodings either, much less other lisps, but it would be nice if there were some mappings between the encodings of the lisp and the pdf encodings. As it is it seems like there are mappings on top of a single encoding (different for each lisp of course) and that the codes of that encoding, not the characters per se, are then remapped to postscript encodings. I used trial and error to see what was what. While it's nice that #\COPYRIGHT_SIGN does the right thing, it would be even nicer if #\LEFT_DOUBLE_QUOTATION_MARK, e.g. and the rest of the postscript-available symbols worked with their equivalents in the encoding of the host lisp. > > Am I missing something really simple trying to insert these > characters? > > The > > pdf itself comes out with an 'A' with a carat over it and then the > > character I > > want. I'm using shift-alt-0 for copyright and alt-e for trademark. > > It depends of the encoding used in the pdf font. You can look at the > encodings or you can write a program to output a code=>character > table to > see what is the code of a given character. > > Marc Thanks, Cyrus From marc.battyani at fractalconcept.com Wed May 9 07:15:33 2007 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Wed, 9 May 2007 09:15:33 +0200 Subject: [cl-pdf-devel] cl-pdf image question References: Message-ID: <13b901c79209$d860c510$1402a8c0@marcx2> "Cyrus Harmon" wrote: > Ok, I'm probably doing something here, but when I try: > > > (cl:defpackage #:cl-pdf-test > (:use #:cl)) > > (cl:in-package :cl-pdf-test) > > (defun png-test (file) > (pdf:with-document () > (let ((pdf-image (pdf::make-image file))) > (pdf:with-page () > (pdf:add-images-to-page pdf-image) > (pdf:draw-image pdf-image > 300 300 500 300 > 0 t))) > (pdf:write-document (merge-pathnames (make-pathname :type "pdf") > file)))) > ;;; doesn't work > (png-test "circles.png") > > ;;; works > (png-test "circles-small.png") > > where circles-small is a cropped version of the bigger png, circles- > small works as expected, but the big image either prints nothing or a > single black line. I've attached a tgz with the images in question. > I'm new to cl-pdf, so this could very easily be operator error, but, > nevertheless, I'm a bit stumped. What you do seems OK and it works when the image is converted to jpg. So there is probably a problem with the png reading. Indeed (pdf::read-png-file "circles.png") gives a png-image with 4 bytes. Marc From marc.battyani at fractalconcept.com Wed May 9 07:21:43 2007 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Wed, 9 May 2007 09:21:43 +0200 Subject: [cl-pdf-devel] encoding question References: Message-ID: <13c001c7920a$b4baae90$1402a8c0@marcx2> "Cyrus Harmon" wrote: > So, now that I'm finally getting around to exploring cl-pdf a bit, I'm > running across issues that others have run into before. Is there any > documentation on the encoding besides just seeing what's in > encodings.lisp and in the pdf file? I don't know a lot about SBCLs > encodings either, much less other lisps, but it would be nice if there > were some mappings between the encodings of the lisp and the pdf > encodings. As it is it seems like there are mappings on top of a single > encoding (different for each lisp of course) and that the codes of that > encoding, not the characters per se, are then remapped to postscript > encodings. I used trial and error to see what was what. While it's nice > that #\COPYRIGHT_SIGN does the right thing, it would be even nicer if > #\LEFT_DOUBLE_QUOTATION_MARK, e.g. and the rest of the > postscript-available symbols worked with their equivalents in the > encoding of the host lisp. The character encoding is an tricky issue, you have to match the Lisp/OS/PDF encodings if you want this to work. Or you can try to use Unicode but right now it's more difficult to use. (see the unicode read-me) The default cl-pdf encoding is :win-ansi-encoding which probably a not a so good choice. Maybe latin-1 would be better. Marc From ch-lisp at bobobeach.com Wed May 9 16:39:42 2007 From: ch-lisp at bobobeach.com (Cyrus Harmon) Date: Wed, 9 May 2007 09:39:42 -0700 Subject: [cl-pdf-devel] cl-pdf image question In-Reply-To: <13b901c79209$d860c510$1402a8c0@marcx2> References: <13b901c79209$d860c510$1402a8c0@marcx2> Message-ID: <19E3FF21-C1A7-4D70-A214-4EFE830384B4@bobobeach.com> On May 9, 2007, at 12:15 AM, Marc Battyani wrote: > What you do seems OK and it works when the image is converted to > jpg. So there is probably a problem with the png reading. > Indeed (pdf::read-png-file "circles.png") gives a png-image with 4 > bytes. Duh. Should have checked that I guess. Looks like we were only saving the last chunk. The following patch fixes things. Thanks again, Cyrus Index: png.lisp =================================================================== --- png.lisp (revision 139) +++ png.lisp (working copy) @@ -101,8 +101,15 @@ (let ((position (position 0 trns))) (when position (list position)))))))) ((string= marker "IDAT") ; image data block - (setq data (make-array octet-length :element-type '(unsigned-byte 8))) - (read-sequence data stream)) + (let ((start 0)) + (if (null data) + (setf data (make-array octet-length + :element-type '(unsigned- byte 8) + :adjustable t)) + (progn + (setf start (first (array-dimensions data))) + (adjust-array data (+ start octet-length)))) + (read-sequence data stream :start start))) ((string= marker "IEND") (return)) (t ;"pHYs" From marc.battyani at fractalconcept.com Wed May 9 17:11:29 2007 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Wed, 9 May 2007 19:11:29 +0200 Subject: [cl-pdf-devel] cl-pdf image question References: <13b901c79209$d860c510$1402a8c0@marcx2> <19E3FF21-C1A7-4D70-A214-4EFE830384B4@bobobeach.com> Message-ID: <196701c7925d$155d5340$1402a8c0@marcx2> "Cyrus Harmon" wrote: > On May 9, 2007, at 12:15 AM, Marc Battyani wrote: >> What you do seems OK and it works when the image is converted to >> jpg. So there is probably a problem with the png reading. >> Indeed (pdf::read-png-file "circles.png") gives a png-image with 4 >> bytes. > > Duh. Should have checked that I guess. Looks like we were only saving > the last chunk. The following patch fixes things. > > Thanks again, > > Cyrus > > Index: png.lisp > =================================================================== > --- png.lisp (revision 139) > +++ png.lisp (working copy) > @@ -101,8 +101,15 @@ > (let ((position (position 0 trns))) > (when position (list position)))))))) > ((string= marker "IDAT") ; image data block > - (setq data (make-array octet-length :element-type > '(unsigned-byte 8))) > - (read-sequence data stream)) > + (let ((start 0)) > + (if (null data) > + (setf data (make-array octet-length > + :element-type '(unsigned- > byte 8) > + :adjustable t)) > + (progn > + (setf start (first (array-dimensions data))) > + (adjust-array data (+ start octet-length)))) > + (read-sequence data stream :start start))) > ((string= marker "IEND") > (return)) > (t ;"pHYs" Thanks for the patch. Does it work for you? I tried your example with LW and got an error. Marc From ch-lisp at bobobeach.com Wed May 9 17:43:32 2007 From: ch-lisp at bobobeach.com (Cyrus Harmon) Date: Wed, 9 May 2007 10:43:32 -0700 Subject: [cl-pdf-devel] cl-pdf image question In-Reply-To: <196701c7925d$155d5340$1402a8c0@marcx2> References: <13b901c79209$d860c510$1402a8c0@marcx2> <19E3FF21-C1A7-4D70-A214-4EFE830384B4@bobobeach.com> <196701c7925d$155d5340$1402a8c0@marcx2> Message-ID: <3220DEF5-DD0C-43FC-A65E-2D8D3C8D251F@bobobeach.com> well, I see what might be an email client cut and paste error where unsigned-byte -> unsigned- byte, but other than that, yeah, it works for me. what's the error? I've included the patch as an attachment. Thanks, Cyrus -------------- next part -------------- A non-text attachment was scrubbed... Name: cl-pdf-png-fix.patch Type: application/octet-stream Size: 1080 bytes Desc: not available URL: -------------- next part -------------- On May 9, 2007, at 10:11 AM, Marc Battyani wrote: > "Cyrus Harmon" wrote: > >> On May 9, 2007, at 12:15 AM, Marc Battyani wrote: >>> What you do seems OK and it works when the image is converted to >>> jpg. So there is probably a problem with the png reading. >>> Indeed (pdf::read-png-file "circles.png") gives a png-image with >>> 4 bytes. >> Duh. Should have checked that I guess. Looks like we were only >> saving the last chunk. The following patch fixes things. >> Thanks again, >> Cyrus >> Index: png.lisp >> =================================================================== >> --- png.lisp (revision 139) >> +++ png.lisp (working copy) >> @@ -101,8 +101,15 @@ >> (let ((position (position 0 trns))) >> (when position (list >> position)))))))) >> ((string= marker "IDAT") ; image data block >> - (setq data (make-array octet-length :element-type >> '(unsigned-byte 8))) >> - (read-sequence data stream)) >> + (let ((start 0)) >> + (if (null data) >> + (setf data (make-array octet-length >> + :element-type >> '(unsigned- byte 8) >> + :adjustable t)) >> + (progn >> + (setf start (first (array-dimensions data))) >> + (adjust-array data (+ start octet-length)))) >> + (read-sequence data stream :start start))) >> ((string= marker "IEND") >> (return)) >> (t ;"pHYs" > > Thanks for the patch. > Does it work for you? I tried your example with LW and got an error. > > Marc > > From marc.battyani at fractalconcept.com Wed May 9 18:10:03 2007 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Wed, 9 May 2007 20:10:03 +0200 Subject: [cl-pdf-devel] cl-pdf image question References: <13b901c79209$d860c510$1402a8c0@marcx2> <19E3FF21-C1A7-4D70-A214-4EFE830384B4@bobobeach.com> <196701c7925d$155d5340$1402a8c0@marcx2> <3220DEF5-DD0C-43FC-A65E-2D8D3C8D251F@bobobeach.com> Message-ID: <19c101c79265$447a33c0$1402a8c0@marcx2> "Cyrus Harmon" wrote: > well, I see what might be an email client cut and paste error where > unsigned-byte -> unsigned- byte, but other than that, yeah, it works > for me. what's the error? Oops sorry, I did not apply the patch to the correct directory. It works > I've included the patch as an attachment. That's better anyway. Thanks a lot I've commited it to the repository. Marc From ch-lisp at bobobeach.com Sat May 19 07:42:04 2007 From: ch-lisp at bobobeach.com (Cyrus Harmon) Date: Sat, 19 May 2007 00:42:04 -0700 Subject: [cl-pdf-devel] transparency? Message-ID: <013899F2-90BD-4F5B-A05E-F3CB7D546931@bobobeach.com> Is there a way that I can set the page background to be transparent using cl-pdf? I'd like to be able to draw (at least partially) opaque items onto a transparent background but can't figure out how to do so. Thanks, Cyrus From marc.battyani at fractalconcept.com Thu May 24 21:39:58 2007 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Thu, 24 May 2007 23:39:58 +0200 Subject: [cl-pdf-devel] transparency? References: <013899F2-90BD-4F5B-A05E-F3CB7D546931@bobobeach.com> Message-ID: <094001c79e4c$169b7b60$1702a8c0@marcc2> "Cyrus Harmon" wrote: > Is there a way that I can set the page background to be transparent using > cl-pdf? I'd like to be able to draw (at least partially) opaque items > onto a transparent background but can't figure out how to do so. What do you mean by transparency? Alpha channels? The text drawing for instance has no background color so is already transparent except for the glyphs. IIRC, the PNG also supports transparency for the images. Otherwise the PDF format supports an exhaustive tranparency model (chapter 7 in the PDF reference). So it's probably not that hard to do whatever you want to. Marc From ch-lisp at bobobeach.com Fri May 25 06:30:23 2007 From: ch-lisp at bobobeach.com (Cyrus Harmon) Date: Thu, 24 May 2007 23:30:23 -0700 Subject: [cl-pdf-devel] transparency? In-Reply-To: <094001c79e4c$169b7b60$1702a8c0@marcc2> References: <013899F2-90BD-4F5B-A05E-F3CB7D546931@bobobeach.com> <094001c79e4c$169b7b60$1702a8c0@marcc2> Message-ID: <11D92AAE-0868-4348-BF40-1460D5CE7044@bobobeach.com> On May 24, 2007, at 2:39 PM, Marc Battyani wrote: > "Cyrus Harmon" wrote: > >> Is there a way that I can set the page background to be >> transparent using cl-pdf? I'd like to be able to draw (at least >> partially) opaque items onto a transparent background but can't >> figure out how to do so. > > What do you mean by transparency? Alpha channels? The text drawing > for instance has no background color so is already transparent > except for the glyphs. What I want in this case is solid text on a transparent background. I'll keep digging. > IIRC, the PNG also supports transparency for the images. hmm... the png reading code says: (otherwise (error "Alpha channel not supported ~s" pathname)) so it would appear that pngs with alpha channels aren't supported, BICBW. Thanks, Cyrus From marc.battyani at fractalconcept.com Fri May 25 21:39:28 2007 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Fri, 25 May 2007 23:39:28 +0200 Subject: [cl-pdf-devel] transparency? References: <013899F2-90BD-4F5B-A05E-F3CB7D546931@bobobeach.com><094001c79e4c$169b7b60$1702a8c0@marcc2> <11D92AAE-0868-4348-BF40-1460D5CE7044@bobobeach.com> Message-ID: <0ec201c79f15$2eef1ae0$1702a8c0@marcc2> "Cyrus Harmon" wrote: > > On May 24, 2007, at 2:39 PM, Marc Battyani wrote: > >> "Cyrus Harmon" wrote: >> >>> Is there a way that I can set the page background to be transparent >>> using cl-pdf? I'd like to be able to draw (at least partially) opaque >>> items onto a transparent background but can't figure out how to do so. >> >> What do you mean by transparency? Alpha channels? The text drawing for >> instance has no background color so is already transparent except for >> the glyphs. > > What I want in this case is solid text on a transparent background. I'll > keep digging. I don't understand what you mean. Text is already solid on a transparent background. The page is white if you don't put something on it but it's not the text that paints it white. >> IIRC, the PNG also supports transparency for the images. > > hmm... the png reading code says: > > (otherwise (error "Alpha channel not supported ~s" pathname)) > > so it would appear that pngs with alpha channels aren't supported, BICBW. No alpha channels, but tranparency is there. There is even an example in png-example.lisp Marc From tl at di.fc.ul.pt Wed May 30 09:37:09 2007 From: tl at di.fc.ul.pt (Thibault Langlois) Date: Wed, 30 May 2007 10:37:09 +0100 Subject: [cl-pdf-devel] png image representation Message-ID: <45df8e510705300237w79b783d3k7f7330e3f98fe5c5@mail.gmail.com> Hello, I would like to know what is the representation used in the data slot of a PDF::PNG-IMAGE. My goal is to be able to use a png image made with the imago package in a cl-pdf document. In an IMAGO:RGB-IMAGE a slot (PIXELS) contains a bidimensional array of (UNSIGNED-BYTE 32) that contains the image pixels. I want to translate this representation into a representation that can be used by cl-pdf. Thanks Thibault From tl at di.fc.ul.pt Wed May 30 21:41:23 2007 From: tl at di.fc.ul.pt (Thibault Langlois) Date: Wed, 30 May 2007 22:41:23 +0100 Subject: [cl-pdf-devel] png image representation In-Reply-To: <877iqqr285.fsf@localhost> References: <45df8e510705300237w79b783d3k7f7330e3f98fe5c5@mail.gmail.com> <877iqqr285.fsf@localhost> Message-ID: <45df8e510705301441j692f7d49x2d865346ab2b582f@mail.gmail.com> On 5/30/07, iso at localhost.di.fc.ul.pt wrote: > > Hello, > > > > I would like to know what is the representation used in the data > > slot of a PDF::PNG-IMAGE. My goal is to be able to use a png image > > made with the imago package in a cl-pdf document. > > In an IMAGO:RGB-IMAGE a slot (PIXELS) contains a bidimensional > > array of (UNSIGNED-BYTE 32) that contains the image pixels. > > I want to translate this representation into a representation > > that can be used by cl-pdf. > > > > Thanks > > > > Thibault > > Maybe you don't need PNG for that. If you have a vector of pixel > values, then just use something like this: > > (defun my-image (pixels width height) > (let ((image (make-instance 'pdf:image > :color-space "DeviceCMYK" > :filter nil > :bits pixels > :width width > :height height))) > (pdf:add-images-to-page image) > (pdf:paint-image image))) > Each pixel in the imago format is a unsigned 32bits that represents R, G, B and Alpha channel. > This assumes that you want to use colour separations and that the > dimensions of the pixel vector are (* width height 4). If you > have a grayscale image, then use DeviceGray instead of DeviceCMYK. Of Each pixel in the imago format is a unsigned 32bits that represents R, G, B and Alpha channel. > course, you can also use DeviceRGB (then the pixel vector should look > like this: R00 G00 B00 R01 G01 B01 ..., where R01 is the Red value of > the pixel at row 0 column 1). I tried to follow your suggestion using a DeviceRGB. First I got an error when the :bits argument is a vector of bytes. Looking at the code it seems that this argument must be a string (the data is passed to a pdf-stream and then to the compress-pdf-stream function where compress-string is called). So I converted each byte into a char to build a string. I do not get any errors but the image does not appear in the document. (defun image-example-1 (&optional (file #P"/home/tl/Desktop/ex.pdf")) (pdf:with-document () (let* ((imago-image ;; Load an image as a imago:rgb-image (imago:read-png "/home/tl/Photos/lemon-slice.png")) (pdf-image ;; make a pdf-image using image data (make-instance 'pdf:image :color-space "DeviceRGB" :filter nil :bits (string-of-bytes imago-image) :width (imago:image-width imago-image) :height (imago:image-height imago-image)))) (pdf:with-page (:bounds (vector 0 0 400 300)) (pdf:add-images-to-page pdf-image) (pdf:draw-image pdf-image 10 100 250 120 0 t) (pdf:write-document file))))) The string-of-bytes function collect the r g b components and build a string: (defun string-of-bytes (imago-rgb-image) (let (color-values) (imago:do-image-pixels (imago-rgb-image c x y) (setq color-values (nconc color-values (list (code-char (imago:color-red c)) (code-char (imago:color-green c)) (code-char (imago:color-blue c)))))) (coerce color-values 'string))) My first attempt was to make a vector: (defun vector-of-bytes (imago-rgb-image) (let (color-values) (imago:do-image-pixels (imago-rgb-image c x y) (setq color-values (nconc color-values (list (imago:color-red c) (imago:color-green c) (imago:color-blue c))))) (coerce color-values 'vector))) Any help will be appreciated. Thibault From marc.battyani at fractalconcept.com Wed May 30 21:49:32 2007 From: marc.battyani at fractalconcept.com (Marc Battyani) Date: Wed, 30 May 2007 23:49:32 +0200 Subject: [cl-pdf-devel] png image representation References: <45df8e510705300237w79b783d3k7f7330e3f98fe5c5@mail.gmail.com><877iqqr285.fsf@localhost> <45df8e510705301441j692f7d49x2d865346ab2b582f@mail.gmail.com> Message-ID: <0b3e01c7a304$6af24f10$1602a8c0@marcc2> "Thibault Langlois" wrote: > On 5/30/07, iso at localhost.di.fc.ul.pt wrote: >> >> Maybe you don't need PNG for that. If you have a vector of pixel >> values, then just use something like this: >> >> (defun my-image (pixels width height) >> (let ((image (make-instance 'pdf:image >> :color-space "DeviceCMYK" >> :filter nil >> :bits pixels >> :width width >> :height height))) >> (pdf:add-images-to-page image) >> (pdf:paint-image image))) Yes I think it's probably easier than going through a png. > Each pixel in the imago format is a unsigned 32bits that > represents R, G, B and Alpha channel. > >> This assumes that you want to use colour separations and that the >> dimensions of the pixel vector are (* width height 4). If you >> have a grayscale image, then use DeviceGray instead of DeviceCMYK. Of > > Each pixel in the imago format is a unsigned 32bits that > represents R, G, B and Alpha channel. > >> course, you can also use DeviceRGB (then the pixel vector should look >> like this: R00 G00 B00 R01 G01 B01 ..., where R01 is the Red value of >> the pixel at row 0 column 1). > > I tried to follow your suggestion using a DeviceRGB. > First I got an error when the :bits argument is a vector of > bytes. Looking at the code it seems that this argument must > be a string (the data is passed to a pdf-stream and then to the > compress-pdf-stream function where compress-string is called). > > So I converted each byte into a char to build a string. I do not > get any errors but the image does not appear in the document. > > (defun image-example-1 (&optional (file #P"/home/tl/Desktop/ex.pdf")) > (pdf:with-document () > (let* ((imago-image ;; Load an image as a imago:rgb-image > (imago:read-png "/home/tl/Photos/lemon-slice.png")) > (pdf-image ;; make a pdf-image using image data > (make-instance 'pdf:image > :color-space "DeviceRGB" > :filter nil > :bits (string-of-bytes imago-image) > :width (imago:image-width imago-image) > :height (imago:image-height imago-image)))) > (pdf:with-page (:bounds (vector 0 0 400 300)) > (pdf:add-images-to-page pdf-image) > (pdf:draw-image pdf-image 10 100 250 120 0 t) > (pdf:write-document file))))) > > The string-of-bytes function collect the r g b components and > build a string: > (defun string-of-bytes (imago-rgb-image) > (let (color-values) > (imago:do-image-pixels (imago-rgb-image c x y) > (setq color-values > (nconc color-values > (list (code-char (imago:color-red c)) > (code-char (imago:color-green c)) > (code-char (imago:color-blue c)))))) > (coerce color-values 'string))) > > My first attempt was to make a vector: > > (defun vector-of-bytes (imago-rgb-image) > (let (color-values) > (imago:do-image-pixels (imago-rgb-image c x y) > (setq color-values > (nconc color-values > (list (imago:color-red c) > (imago:color-green c) > (imago:color-blue c))))) > (coerce color-values 'vector))) > > Any help will be appreciated. Have you looked at example3 in examples.lisp? It creates an in memory image that is put into the pdf. Marc From woudshoo+cl-typesetting at xs4all.nl Thu May 31 15:49:53 2007 From: woudshoo+cl-typesetting at xs4all.nl (Wim Oudshoorn) Date: Thu, 31 May 2007 17:49:53 +0200 (CEST) Subject: [cl-pdf-devel] Writing binary data fails with SBCL Message-ID: <13975.213.84.192.76.1180626593.squirrel@webmail.xs4all.nl> For me every example in cl-typesetting failed with SBCL 1.0.2 because SBCL does by default not open streams in such a way that binary data can be written. The relevant section in the SBCL documentation is: 9.1 Bivalent Streams A bivalent stream can be used to read and write both character and (unsigned-byte 8) values. A bivalent stream is created by calling open with the argument :element-type :default. On such a stream, both binary and character data can be read and written with the usual input and output functions. I fixed it by the following patch, although, keep in mind that I just started to play with common lisp so I hesitate to suggest it to do it this way. *** cl-pdf/pdf.lisp Tue Jan 3 17:01:21 2006 --- ../asdf-source/cl-pdf/pdf.lisp Thu May 31 16:56:44 2007 *************** *** 528,535 **** (format s "~%>>~%startxref~%~d~%%%EOF~%" startxref)))) (defmethod write-document ((filename pathname) &optional (document *document*)) ! (with-open-file (s filename :direction :output :if-exists :supersede ! :external-format +external-format+) (write-document s document))) (defmethod write-document ((filename string) &optional (document *document*)) --- 528,536 ---- (format s "~%>>~%startxref~%~d~%%%EOF~%" startxref)))) (defmethod write-document ((filename pathname) &optional (document *document*)) ! (with-open-file (s filename :direction :output :if-exists :supersede ! #+sbcl :element-type #+sbcl :default ! :external-format +external-format+) (write-document s document))) (defmethod write-document ((filename string) &optional (document *document*)) From tl at di.fc.ul.pt Thu May 31 21:48:32 2007 From: tl at di.fc.ul.pt (Thibault Langlois) Date: Thu, 31 May 2007 22:48:32 +0100 Subject: [cl-pdf-devel] png image representation In-Reply-To: <0b3e01c7a304$6af24f10$1602a8c0@marcc2> References: <45df8e510705300237w79b783d3k7f7330e3f98fe5c5@mail.gmail.com> <877iqqr285.fsf@localhost> <45df8e510705301441j692f7d49x2d865346ab2b582f@mail.gmail.com> <0b3e01c7a304$6af24f10$1602a8c0@marcc2> Message-ID: <45df8e510705311448y6fd07b2fw6fcbb4c18c0a8781@mail.gmail.com> On 5/30/07, Marc Battyani wrote: > "Thibault Langlois" wrote: > > > On 5/30/07, iso at localhost.di.fc.ul.pt wrote: > >> > >> Maybe you don't need PNG for that. If you have a vector of pixel > >> values, then just use something like this: > >> > >> (defun my-image (pixels width height) > >> (let ((image (make-instance 'pdf:image > >> :color-space "DeviceCMYK" > >> :filter nil > >> :bits pixels > >> :width width > >> :height height))) > >> (pdf:add-images-to-page image) > >> (pdf:paint-image image))) > > Yes I think it's probably easier than going through a png. > > > > Each pixel in the imago format is a unsigned 32bits that > > represents R, G, B and Alpha channel. > > > >> This assumes that you want to use colour separations and that the > >> dimensions of the pixel vector are (* width height 4). If you > >> have a grayscale image, then use DeviceGray instead of DeviceCMYK. Of > > > > Each pixel in the imago format is a unsigned 32bits that > > represents R, G, B and Alpha channel. > > > >> course, you can also use DeviceRGB (then the pixel vector should look > >> like this: R00 G00 B00 R01 G01 B01 ..., where R01 is the Red value of > >> the pixel at row 0 column 1). > > > > I tried to follow your suggestion using a DeviceRGB. > > First I got an error when the :bits argument is a vector of > > bytes. Looking at the code it seems that this argument must > > be a string (the data is passed to a pdf-stream and then to the > > compress-pdf-stream function where compress-string is called). > > > > So I converted each byte into a char to build a string. I do not > > get any errors but the image does not appear in the document. > > > > (defun image-example-1 (&optional (file #P"/home/tl/Desktop/ex.pdf")) > > (pdf:with-document () > > (let* ((imago-image ;; Load an image as a imago:rgb-image > > (imago:read-png "/home/tl/Photos/lemon-slice.png")) > > (pdf-image ;; make a pdf-image using image data > > (make-instance 'pdf:image > > :color-space "DeviceRGB" > > :filter nil > > :bits (string-of-bytes imago-image) > > :width (imago:image-width imago-image) > > :height (imago:image-height imago-image)))) > > (pdf:with-page (:bounds (vector 0 0 400 300)) > > (pdf:add-images-to-page pdf-image) > > (pdf:draw-image pdf-image 10 100 250 120 0 t) > > (pdf:write-document file))))) > > > > The string-of-bytes function collect the r g b components and > > build a string: > > (defun string-of-bytes (imago-rgb-image) > > (let (color-values) > > (imago:do-image-pixels (imago-rgb-image c x y) > > (setq color-values > > (nconc color-values > > (list (code-char (imago:color-red c)) > > (code-char (imago:color-green c)) > > (code-char (imago:color-blue c)))))) > > (coerce color-values 'string))) > > > > My first attempt was to make a vector: > > > > (defun vector-of-bytes (imago-rgb-image) > > (let (color-values) > > (imago:do-image-pixels (imago-rgb-image c x y) > > (setq color-values > > (nconc color-values > > (list (imago:color-red c) > > (imago:color-green c) > > (imago:color-blue c))))) > > (coerce color-values 'vector))) > > > > Any help will be appreciated. > > Have you looked at example3 in examples.lisp? It creates an in memory image > that is put into the pdf. Strangely I started with example7 ... Thanks for the suggestion. I solved my problem after looking at example3. Thibault > > Marc > > > -- Thibault Langlois FCUL / DI