PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/site/zpng-1.0.1/doc/index.html

https://github.com/vikram/lisplibraries
HTML | 266 lines | 201 code | 65 blank | 0 comment | 0 complexity | a16a067285aea171aef0065c072c8506 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, CC-BY-SA-3.0, LGPL-3.0, BSD-3-Clause, GPL-2.0
  1. <html>
  2. <head>
  3. <title>ZPNG - Create PNG files from Common Lisp</title>
  4. <style type="text/css">
  5. a, a:visited { text-decoration: none }
  6. a[href]:hover { text-decoration: underline }
  7. pre { background: #DDD; padding: 0.25em }
  8. p.download { color: red }
  9. .transparent { background-image: url(background.gif) }
  10. </style>
  11. </head>
  12. <body>
  13. <h2>ZPNG - Create PNG files from Common Lisp</h2>
  14. <blockquote class='abstract'>
  15. <h3>Abstract</h3>
  16. <p>ZPNG is a Common Lisp library for creating PNG files. It
  17. uses <a href='http://www.xach.com/lisp/salza2/'>Salza2</a> for
  18. compression.
  19. The current version is 1.0.1, released on January 3rd, 2008.
  20. <p class='download'>Download shortcut:
  21. <p><a href='http://www.xach.com/lisp/zpng.tgz'>http://www.xach.com/lisp/zpng.tgz</a>
  22. </blockquote>
  23. <h3>Contents</h3>
  24. <ol>
  25. <li> <a href='#sect-overview'>Overview and Limitations</a>
  26. <li> <a href='#sect-examples'>Examples</a>
  27. <li> <a href='#sect-dictionary'>Dictionary</a>
  28. <ul>
  29. <li> <a href='#png'><tt>png</tt></a>
  30. <li> <a href='#samples-per-pixel'><tt>samples-per-pixel</tt></a>
  31. <li> <a href='#image-data'><tt>image-data</tt></a>
  32. <li> <a href='#data-array'><tt>data-array</tt></a>
  33. <li> <a href='#width'><tt>width</tt></a>
  34. <li> <a href='#height'><tt>height</tt></a>
  35. <li> <a href='#color-type'><tt>color-type</tt></a>
  36. <li> <a href='#write-png'><tt>write-png</tt></a>
  37. <ul> <a href='#write-png-stream'><tt>write-png-stream</tt></a>
  38. </ul>
  39. <li> <a href='#sect-references'>References</a>
  40. <li> <a href='#sect-feedback'>Feedback</a>
  41. </ol>
  42. <a name='sect-overview'><h3>Overview and Limitations</h3></a>
  43. <p>ZPNG provides an interface for creating
  44. a <a href='#png'><tt>PNG</tt></a> object. The objects acts as a
  45. container for PNG sample data, which may be updated and saved to a
  46. file.
  47. <p>The PNG file format has many options, and ZPNG supports only a
  48. subset of them.
  49. <ul>
  50. <li> does not load PNG files
  51. <li> supports only 8 bits per sample
  52. <li> does not support filtering
  53. <li> does not support indexed color
  54. </ul>
  55. <a name='sect-examples'><h3>Examples</h3></a>
  56. <pre><div style='float: right' class='transparent'><img src='mandelbrot.png'
  57. ></div>(defun draw-mandelbrot (file)
  58. (let* ((png (make-instance '<a href='#png'>png</a>
  59. :color-type :grayscale-alpha
  60. :width 200
  61. :height 200))
  62. (image (<a href='#data-array'>data-array</a> png))
  63. (max 255))
  64. (dotimes (y 200 (<a href='#write-png'>write-png</a> png file))
  65. (dotimes (x 200)
  66. (let ((c (complex (- (/ x 100.0) 1.5) (- (/ y 100.0) 1.0)))
  67. (z (complex 0.0 0.0))
  68. (iteration 0))
  69. (loop
  70. (setf z (+ (* z z) c))
  71. (incf iteration)
  72. (cond ((< 4 (abs z))
  73. (setf (aref image y x 1) iteration)
  74. (return))
  75. ((= iteration max)
  76. (setf (aref image y x 1) 255)
  77. (return)))))))))
  78. </pre>
  79. <a name='sect-dictionary'><h3>Dictionary</h3></a>
  80. <p>The following symbols are exported from the ZPNG package.
  81. <p><a name='png'>[Class]</a><br>
  82. <b>png</b>
  83. <blockquote>
  84. Instances of this class may be created directly. Supported initargs:
  85. <ul>
  86. <li> <tt>:width</tt> - required, the width of the image
  87. <li> <tt>:height</tt> - required, the height of the image
  88. <li> <tt>:color-type</tt> - optional, the color type of the image, one
  89. of <tt>:grayscale</tt>, <tt>:truecolor</tt> (the
  90. default), <tt>:grayscale-alpha</tt>, or <tt>:truecolor-alpha</tt>
  91. <li> <tt>:image-data</tt> - optional, the sample data of the image. If
  92. specified, this must be an octet vector with a length of
  93. <i>width</i>&nbsp;&times;&nbsp;<i>height</i>&nbsp;&times;&nbsp;<i>samples-per-pixel</i>. If
  94. not specified, an image data vector of the appropriate size will be
  95. created automatically.
  96. </ul>
  97. </blockquote>
  98. <p><a name='samples-per-pixel'>[Function]</a><br>
  99. <b>samples-per-pixel</b> <i>png</i> => <i>samples</i>
  100. <blockquote>
  101. Returns the number of octet samples that make up a single pixel.
  102. <p><table cellpadding=0 cellspacing=5>
  103. <tr>
  104. <th>Image Color Type</th>
  105. <th>Samples per Pixel</th>
  106. </tr>
  107. <tr>
  108. <td>Grayscale</td><td align=center>1</td>
  109. </tr>
  110. <tr>
  111. <td>Truecolor</td><td align=center>3</td>
  112. </tr>
  113. <tr>
  114. <td>Grayscale with Alpha</td><td align=center>2</td>
  115. </tr>
  116. <tr>
  117. <td>Truecolor with Alpha</td><td align=center>4</td>
  118. </tr>
  119. </table>
  120. </blockquote>
  121. <p><a name='image-data'>[Function]</a><br>
  122. <b>image-data</b> <i>png</i> => <i>octet-vector</i>
  123. <blockquote>
  124. Returns the image data of png. Samples are laid out from left to
  125. right, top to bottom, so the first samples of data affect the
  126. upper-left of the image and the final samples affect the lower-right.
  127. <p><table cellpadding=0 cellspacing=5>
  128. <tr>
  129. <th>Image Color Type</th>
  130. <th>Pixel Sample Layout</th>
  131. </tr>
  132. <tr>
  133. <td>Grayscale</td><td>S|S|S...</td>
  134. </tr>
  135. <tr>
  136. <td>Truecolor</td><td>RGB|RGB|RGB...</td>
  137. </tr>
  138. <tr>
  139. <td>Grayscale with Alpha</td><td>SA|SA|SA...</td>
  140. </tr>
  141. <tr>
  142. <td>Truecolor with Alpha</td><td>RGBA|RGBA|RGBA...</td>
  143. </tr>
  144. </table>
  145. <p>Layout of the samples into pixels is done according to the image's
  146. color type and is fully documented in
  147. the <a href="http://www.w3.org/TR/PNG/">Portable Network Graphics
  148. Specification.
  149. </blockquote>
  150. <p><a name='data-array'>[Function]</a><br>
  151. <b>data-array</b> <i>png</i> => <i>data-array</i>
  152. <blockquote>
  153. Returns a multidimensional array representing the pixels
  154. of <i>png</i>. The dimensions correspond to the height, width, and
  155. pixel components, respectively. For example, to access the red
  156. component at &lt;53,100&gt; of a truecolor PNG, you could use this:
  157. <pre>
  158. (aref (data-array png) 100 53 0)
  159. </pre>
  160. <p>Note the reversed order of the coordinate arguments; this is a
  161. consequence of Common Lisp's row-major ordering of elements in a
  162. multidimensional array and PNG's specified sample layout.
  163. </blockquote>
  164. <p><a name='width'><a name='height'>[Functions]</a></a><br>
  165. <b>width</b> <i>png</i> => <i>width</i><br>
  166. <b>height</b> <i>png</i> => <i>height</i>
  167. <blockquote>
  168. Returns the width or height of <i>png</i>.
  169. </blockquote>
  170. <p><a name='color-type'>[Function]</a><br>
  171. <b>color-type</b> <i>png</i> => <i>color-type</i>
  172. <blockquote>
  173. Returns the color type of <i>png</i>, one of
  174. of <tt>:grayscale</tt>, <tt>:truecolor</tt>,
  175. <tt>:grayscale-alpha</tt>, or <tt>:truecolor-alpha</tt>.
  176. </blockquote>
  177. <p><a name='write-png'>[Function]</a><br>
  178. <b>write-png</b> <i>png</i> <i>file</i>
  179. <tt>&amp;key</tt> (<i>if-exists</i> <tt>:supersede</tt>) => pathname
  180. <blockquote>
  181. Writes <i>png</i> to <i>file</i> and returns the truename
  182. of <i>file</i>. <i>if-exists</i> is passed to the
  183. underlying <tt>OPEN</tt> call for opening the output file.
  184. </blockquote>
  185. <p><a name='write-png-stream'>[Function]</a><br>
  186. <b>write-png-stream</b> <i>png</i> <i>stream</i> => |
  187. <blockquote>
  188. Writes <i>png</i> to <i>stream</i>, which should be a stream that can
  189. accept octets.
  190. </blockquote>
  191. <a name='sect-references'><h3>References</h3></a>
  192. <ul>
  193. <li> W3C, <a href="http://www.w3.org/TR/PNG/">Portable Network
  194. Graphics Specification, Second Edition</a>
  195. <li>
  196. Wikipedia, <a href='http://en.wikipedia.org/wiki/Mandelbrot_set'>Mandelbrot
  197. set</a>
  198. </ul>
  199. <a name='sect-feedback'><h3>Feedback</h3></a>
  200. <p>Please direct any questions, comments, bug reports, or other
  201. feedback to <a href='mailto:xach@xach.com'>Zach Beane</a>.