]> granicus.if.org Git - imagemagick/blob - tests/validate-colorspace.sh
33edb9a1942f9402397e4f59893e2a724c80b799
[imagemagick] / tests / validate-colorspace.sh
1 #!/bin/bash
2 #
3 #  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization
4 #  dedicated to making software imaging solutions freely available.
5 #
6 #  You may not use this file except in compliance with the License.  You may
7 #  obtain a copy of the License at
8 #
9 #    http://www.imagemagick.org/script/license.php
10 #
11 #  Unless required by applicable law or agreed to in writing, software
12 #  distributed under the License is distributed on an "AS IS" BASIS,
13 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #  See the License for the specific language governing permissions and
15 #  limitations under the License.
16 #
17 . ${srcdir}/tests/common.sh
18
19 # how to generate a one pixel (average rose) color and output its values
20 in="rose: -scale 1x1"    # a one pixel image of the average color.
21 out="-format '%[fx:int(255*r)],%[fx:int(255*g)],%[fx:int(255*b)]' info:-"
22
23 # ----------------
24
25 # Colors to compare results to.
26 error=false
27 average=`eval ${MAGICK} "$in" -noop "$out"`
28 too_light=`eval ${MAGICK} "$in" -colorspace RGB "$out"`
29 too_dark=`eval ${MAGICK} "$in" -set colorspace RGB -colorspace sRGB "$out"`
30 format='%-30s%s\n'        # results formating
31 format2='%-30s%-14s%s\n'
32
33 printf "$format2" "Average \"rose:\" Color"  "$average" "sRGB(rose)"
34 printf "$format2" "Too Light Color" "$too_light" "sRGB(rose)->RGB result"
35 printf "$format2" "Too Dark Color"  "$too_dark"  "RGB(rose)->sRGB result"
36 echo ''
37
38 # Sanity checks
39 if [ "X$average" != "X145,89,80" ]; then
40   echo "Sanity Failure: Average expected to be 145,89,80 - ABORTING"
41   error=true
42 fi
43 if [ "X$too_light" != "X72,25,20" ]; then
44   echo "Sanity Failure: Too Light expected to be 72,25,20 - ABORTING"
45   error=true
46 fi
47 if [ "X$too_dark" != "X199,159,152" ]; then
48   echo "Sanity Failure: Too Dark expected to be 199,159,152 - ABORTING"
49   error=true
50 fi
51 $error && exit 1
52
53 test_color() {
54   test="sRGB(rose)"
55   cs='';
56   for i in "$@"; do
57     test="${test}->$i"        # format of the test being performed
58     cs="$cs -colorspace $i"   # colorspace operations to perform test
59   done
60   color=`eval ${MAGICK} "$in" $cs "$out"`
61
62   if [ "X$color" = "X$average" ]; then
63     printf "$format" "$test" "good"
64     return
65   fi
66   error=false
67   if [ "X$color" = "X$too_light" ]; then
68     printf "$format" "$test" "TOO_LIGHT"
69     return
70   fi
71   if [ "X$color" = "X$too_dark" ]; then
72     printf "$format" "$test" "TOO_DARK"
73     return
74   fi
75   printf "$format" "$test" "UNKNOWN COLOR (expect $average, got $color)"
76 }
77
78 # ----------------
79
80 test_color RGB sRGB
81 test_color XYZ sRGB
82 test_color RGB XYZ sRGB
83 test_color XYZ RGB sRGB
84
85 test_color CMY   sRGB
86 test_color CMYK  sRGB
87 test_color HSL   sRGB
88 test_color HSB   sRGB
89 test_color Lab   sRGB
90 test_color YIQ   sRGB
91 test_color YCbCr sRGB
92
93 $error