]> granicus.if.org Git - imagemagick/blob - tests/validate-colorspace.sh
cb6b51967ac8d7737ee945f9904fbf986d094ff0
[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 depth=`eval ${MAGICK} xc:none -format '%[fx:QuantumRange]' info:-`
20 echo $depth
21 if [ "$depth" != "65535" ]; then
22   exit 0
23 fi
24
25 # how to generate a one pixel (average rose) color and output its values
26 in="rose: -scale 1x1"    # a one pixel image of the average color.
27 out="-format '%[fx:int(255*r+.5)],%[fx:int(255*g+.5)],%[fx:int(255*b+.5)]' info:-"
28
29 # ----------------
30
31 # Colors to compare results to.
32 error=false
33 average=`eval ${MAGICK} "$in" -noop "$out"`
34 too_light=`eval ${MAGICK} "$in" -colorspace RGB "$out"`
35 too_dark=`eval ${MAGICK} "$in" -set colorspace RGB -colorspace sRGB "$out"`
36 format='%-30s%s\n'        # results formating
37 format2='%-30s%-14s%s\n'
38
39 printf "$format2" "Average \"rose:\" Color"  "$average" "sRGB(rose)"
40 printf "$format2" "Too Light Color" "$too_light" "sRGB(rose)->RGB result"
41 printf "$format2" "Too Dark Color"  "$too_dark"  "RGB(rose)->sRGB result"
42 echo ''
43
44 #
45 # Sanity checks
46 #
47 # NOTE: as a extra validation on sanity checks below...
48 #    eval ${MAGICK} "$in" -gamma .454545 "$out"
49 # produces a value of  74,25,20   which is close to 73,26,21 below.
50 #    eval ${MAGICK} "$in" -gamma 2.2 "$out"
51 # produces a value of  198,158,151  whcih is close to 199,160,152 below.
52 #
53 # Actual values used below come from IM v6.5.4-7 colorspace conversions
54 #
55 if [ "X$average" != "X146,89,80" ]; then
56   echo "Sanity Failure: Average expected to be 146,89,80 - ABORTING"
57   error=true
58 fi
59 if [ "X$too_light" != "X73,26,21" ]; then
60   echo "Sanity Failure: Too Light expected to be 73,26,21 - ABORTING"
61   error=true
62 fi
63 if [ "X$too_dark" != "X199,160,152" ]; then
64   echo "Sanity Failure: Too Dark expected to be 199,160,152 - ABORTING"
65   error=true
66 fi
67 $error && exit 1
68
69 test_color() {
70   test="sRGB(rose)"
71   cs='';
72   for i in "$@"; do
73     test="${test}->$i"        # format of the test being performed
74     cs="$cs -colorspace $i"   # colorspace operations to perform test
75   done
76   color=`eval ${MAGICK} "$in" $cs "$out"`
77
78   if [ "X$color" = "X$average" ]; then
79     printf "$format" "$test" "good"
80     return
81   fi
82   error=false
83   if [ "X$color" = "X$too_light" ]; then
84     printf "$format" "$test" "TOO_LIGHT"
85     return
86   fi
87   if [ "X$color" = "X$too_dark" ]; then
88     printf "$format" "$test" "TOO_DARK"
89     return
90   fi
91   printf "$format" "$test" "UNKNOWN COLOR (expect $average, got $color)"
92 }
93
94 # ----------------
95
96 test_color RGB sRGB
97 test_color XYZ sRGB
98 test_color XYZ RGB sRGB
99
100 test_color CMY   sRGB
101 test_color CMYK  sRGB
102 test_color HSL   sRGB
103 test_color HSB   sRGB
104 test_color HWB   sRGB
105 test_color Lab   sRGB
106 test_color YIQ   sRGB
107 test_color YUV   sRGB
108 test_color YCbCr sRGB
109 test_color OHTA  sRGB
110
111 eval ! $error