From colimal at mails.selgrad.org Thu Mar 11 17:29:21 2010 From: colimal at mails.selgrad.org (colimal at mails.selgrad.org) Date: Thu, 11 Mar 2010 18:29:21 +0100 Subject: [cl-gd-devel] [question] change of colors when tiling an image Message-ID: <20100311172921.GA27863@deathmetal> Hello all :) I'm using cl-gd to generate tiles of a larger image. I'm generating a set of tiles of each, e.g. 256x256 pixels, from an input image that is much larger, e.g. 4096x2048. When using "debug-images" (pngs) with few colors and large areas of the same color this works well. However, when I want to tile a png file with higher frequencies and lots of colors the resulting tile images seem to be resampled somehow, with a huge loss of quality. Here is part of my code: (with-image-from-file (src input-name) (let ((width (image-width src)) (height (image-height src))) ;; store a single tile (defun generate-tile (x y) "Generates a single tile. The index of which is given in x and y" (with-image (dest size size) (copy-image src dest (* x size) (* y size) 0 0 size size) (write-image-to-file (concatenate 'string output-base "-" (write-to-string x) "-" (write-to-string y) "." ext) :image dest :if-exists :supersede :compression-level 0))) ;; master's actual code (let ((count-x (ceiling (/ width size))) (count-y (ceiling (/ height size)))) (format t "Slicing up ~s (~d x ~d) into (~d x ~d) tiles of size (~d x ~d).~%" input-name width height count-x count-y size size) (dotimes (x count-x) (dotimes (y count-y) (generate-tile x y)))))) As you can see, I don't compress the image (doesn't change, if I leave the compression key out), and only copy a given section to the output image. The version of cl-gd I'm using is 0.5.7, the version of is libgd 2.0.0. I would appreciate if someone would hint me to what I'm missing :) Thanks in advance, Kai. From hans.huebner at gmail.com Thu Mar 11 18:02:15 2010 From: hans.huebner at gmail.com (=?ISO-8859-1?Q?Hans_H=FCbner?=) Date: Thu, 11 Mar 2010 19:02:15 +0100 Subject: [cl-gd-devel] [question] change of colors when tiling an image In-Reply-To: <20100311172921.GA27863@deathmetal> References: <20100311172921.GA27863@deathmetal> Message-ID: Kai, I guess your tiles are written in palette mode. Have a look at the optional TRUE-COLOR-P argument that WITH-IMAGE provides. -Hans On Thu, Mar 11, 2010 at 18:29, wrote: > Hello all :) > > I'm using cl-gd to generate tiles of a larger image. I'm generating a set of > tiles of each, e.g. 256x256 pixels, from an input image that is much larger, > e.g. 4096x2048. > > When using "debug-images" (pngs) with few colors and large areas of the same > color this works well. However, when I want to tile a png file with higher > frequencies and lots of colors the resulting tile images seem to be resampled > somehow, with a huge loss of quality. > > Here is part of my code: > > ?(with-image-from-file (src input-name) > ? (let ((width (image-width src)) > ? ? ? ? (height (image-height src))) > > ? ? ? ?;; store a single tile > ? ? ? ?(defun generate-tile (x y) > ? ? ? ? ?"Generates a single tile. The index of which is given in x and y" > ? ? ? ? ?(with-image (dest size size) > ? ? ? ? ? ?(copy-image src dest (* x size) (* y size) 0 0 size size) > ? ? ? ? ? ?(write-image-to-file (concatenate 'string output-base "-" (write-to-string x) "-" (write-to-string y) "." ext) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? :image dest :if-exists :supersede :compression-level 0))) > > ? ? ? ?;; master's actual code > ? ? ? ?(let ((count-x (ceiling (/ width size))) > ? ? ? ? ? ? ?(count-y (ceiling (/ height size)))) > ? ? ? ? ? ? (format t "Slicing up ~s (~d x ~d) into (~d x ~d) tiles of size (~d x ~d).~%" input-name width height count-x count-y size size) > ? ? ? ? ? ? (dotimes (x count-x) > ? ? ? ? ? ? ? ? ? ? ?(dotimes (y count-y) > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (generate-tile x y)))))) > > As you can see, I don't compress the image (doesn't change, if I leave the > compression key out), and only copy a given section to the output image. > The version of cl-gd I'm using is 0.5.7, the version of is libgd 2.0.0. > > I would appreciate if someone would hint me to what I'm missing :) > > Thanks in advance, > ? Kai. > > > _______________________________________________ > cl-gd-devel site list > cl-gd-devel at common-lisp.net > http://common-lisp.net/mailman/listinfo/cl-gd-devel > From colimal at mails.selgrad.org Thu Mar 11 20:14:54 2010 From: colimal at mails.selgrad.org (colimal at mails.selgrad.org) Date: Thu, 11 Mar 2010 21:14:54 +0100 Subject: [cl-gd-devel] [question] change of colors when tiling an image In-Reply-To: References: <20100311172921.GA27863@deathmetal> Message-ID: <20100311201454.GA28952@deathmetal> Thank you! Should have guessed something like that... :) Kai. On 19:02 Thu 11 Mar , Hans H?bner wrote: > Kai, > > I guess your tiles are written in palette mode. Have a look at the > optional TRUE-COLOR-P argument that WITH-IMAGE provides. > > -Hans >