Updated version to 1.2.1.
[zpng.git] / conditions.lisp
blob48a80b7f6275b895a8d1d93b69015bebd9e7e7f3
1 ;;;
2 ;;; Copyright (c) 2008 Zachary Beane, All Rights Reserved
3 ;;;
4 ;;; Redistribution and use in source and binary forms, with or without
5 ;;; modification, are permitted provided that the following conditions
6 ;;; are met:
7 ;;;
8 ;;; * Redistributions of source code must retain the above copyright
9 ;;; notice, this list of conditions and the following disclaimer.
10 ;;;
11 ;;; * Redistributions in binary form must reproduce the above
12 ;;; copyright notice, this list of conditions and the following
13 ;;; disclaimer in the documentation and/or other materials
14 ;;; provided with the distribution.
15 ;;;
16 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
17 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 ;;;
28 ;;; conditions.lisp
30 (in-package #:zpng)
32 (define-condition zpng-error (error) ())
34 (define-condition invalid-size (zpng-error)
35 ((width
36 :initarg :width
37 :reader invalid-size-width)
38 (height
39 :initarg :height
40 :reader invalid-size-height))
41 (:report (lambda (condition stream)
42 (format stream "Invalid PNG size ~Ax~A; ~
43 both width and height must be positive"
44 (invalid-size-width condition)
45 (invalid-size-height condition)))))
47 (define-condition invalid-row-length (zpng-error)
48 ((expected-length
49 :initarg :expected-length
50 :accessor invalid-row-length-expected-length)
51 (actual-length
52 :initarg :actual-length
53 :accessor invalid-row-length-actual-length))
54 (:report (lambda (condition stream)
55 (format stream "Invalid row length ~A (expected ~A)"
56 (invalid-row-length-actual-length condition)
57 (invalid-row-length-expected-length condition)))))
59 (define-condition insufficient-rows (zpng-error)
60 ((written
61 :initarg :written
62 :accessor insufficient-rows-written)
63 (needed
64 :initarg :needed
65 :accessor insufficient-rows-needed))
66 (:report (lambda (condition stream)
67 (format stream "Insufficient rows written; need ~A, but only ~A ~
68 written"
69 (insufficient-rows-needed condition)
70 (insufficient-rows-written condition)))))
72 (define-condition incomplete-row (zpng-error)
73 ((written
74 :initarg :written
75 :accessor incomplete-row-written)
76 (needed
77 :initarg :needed
78 :accessor incomplete-row-needed))
79 (:report (lambda (condition stream)
80 (format stream "Incomplete row started; need ~A, but only ~A ~
81 written"
82 (incomplete-row-needed condition)
83 (incomplete-row-written condition)))))
85 (define-condition too-many-rows (zpng-error)
86 ((count
87 :initarg :count
88 :accessor too-many-rows-count))
89 (:report (lambda (condition stream)
90 (format stream "Too many rows written for PNG; maximum row count ~
91 is ~A"
92 (too-many-rows-count condition)))))
94 (define-condition color-type-mismatch (zpng-error)
95 ((given
96 :initarg :given
97 :accessor color-type-mismatch-given)
98 (expected
99 :initarg :expected
100 :accessor color-type-mismatch-expected))
101 (:report (lambda (condition stream)
102 (format stream "Wrong number of samples for PNG pixel; need ~A, ~
103 but only ~A written"
104 (color-type-mismatch-expected condition)
105 (color-type-mismatch-given condition)))))