blob: d38f0a1abc0c8bd2e3ca50f9e3917dd9ac16abcf [file] [log] [blame]
cristy19a2b0d2012-08-21 11:46:58 +00001#!/bin/sh
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.shi
cristy8391c6a2012-08-21 15:25:07 +000018echo "1..19"
cristy19a2b0d2012-08-21 11:46:58 +000019
20depth=`eval ${MAGICK} xc:none -format '%[fx:QuantumRange]' info:-`
21if [ "X$depth" == "X255" ]; then
22 exit 0
23fi
24
25# how to generate a one pixel (average rose) color and output its values
26in="rose: -scale 1x1" # a one pixel image of the average color.
27out="-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.
32error=false
33average=`eval ${MAGICK} "$in" -noop "$out"`
34too_dark=`eval ${MAGICK} "$in" -colorspace RGB "$out"`
35too_light=`eval ${MAGICK} "$in" -set colorspace RGB -colorspace sRGB "$out"`
36format='%-30s%s\n' # results formating
37format2='%-30s%-14s%s\n'
38
39printf "$format2" "Average \"rose:\" Color" "$average" "sRGB(rose)"
40printf "$format2" "Too Dark Color" "$too_dark" "sRGB(rose)->RGB result"
41printf "$format2" "Too Light Color" "$too_light" "RGB(rose)->sRGB result"
42echo ''
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#
55error=false
56if [ "X$average" != "X146,89,80" ]; then
57 echo "Sanity Failure: Average expected to be 145,89,80 - ABORTING"
58 error=true
59fi
60if [ "X$too_dark" != "X73,26,21" ]; then
61 echo "Sanity Failure: Too Dark expected to be 73,26,21 - ABORTING"
62 error=true
63fi
64if [ "X$too_light" != "X199,160,152" ]; then
65 echo "Sanity Failure: Too Light expected to be 199,160,152 - ABORTING"
66 error=true
67fi
68$error && exit 1
69
70test_color() {
71 test="sRGB"
72 cs='';
73 for i in "$@"; do
74 test="${test}->$i" # format of the test being performed
75 cs="$cs -colorspace $i" # colorspace operations to perform test
76 done
77 color=`eval ${MAGICK} "$in" $cs "$out"`
78
79 if [ "X$color" = "X$average" ]; then
cristy8391c6a2012-08-21 15:25:07 +000080 return 0
cristy19a2b0d2012-08-21 11:46:58 +000081 fi
82 # Its failed the round-trip test, now report how it failed!
83 error=true
84 if [ "X$color" = "X$too_light" ]; then
cristy8391c6a2012-08-21 15:25:07 +000085 return 1
cristy19a2b0d2012-08-21 11:46:58 +000086 fi
87 if [ "X$color" = "X$too_dark" ]; then
cristy8391c6a2012-08-21 15:25:07 +000088 return 1
cristy19a2b0d2012-08-21 11:46:58 +000089 fi
cristy8391c6a2012-08-21 15:25:07 +000090 return 1
cristy19a2b0d2012-08-21 11:46:58 +000091}
92
93# ----------------
94
cristy8391c6a2012-08-21 15:25:07 +000095test_color RGB sRGB && echo "ok" || echo "not ok"
cristy19a2b0d2012-08-21 11:46:58 +000096
cristy8391c6a2012-08-21 15:25:07 +000097test_color XYZ sRGB && echo "ok" || echo "not ok"
98test_color XYZ RGB sRGB && echo "ok" || echo "not ok"
99test_color RGB XYZ sRGB && echo "ok" || echo "not ok"
cristy19a2b0d2012-08-21 11:46:58 +0000100
cristy8391c6a2012-08-21 15:25:07 +0000101test_color LAB sRGB && echo "ok" || echo "not ok"
102test_color XYZ LAB sRGB && echo "ok" || echo "not ok"
103test_color LAB XYZ sRGB && echo "ok" || echo "not ok"
104test_color RGB LAB sRGB && echo "ok" || echo "not ok"
105test_color LAB RGB sRGB && echo "ok" || echo "not ok"
cristy19a2b0d2012-08-21 11:46:58 +0000106
cristy8391c6a2012-08-21 15:25:07 +0000107test_color CMY sRGB && echo "ok" || echo "not ok"
108test_color CMYK sRGB && echo "ok" || echo "not ok"
109test_color HSL sRGB && echo "ok" || echo "not ok"
110test_color HSB sRGB && echo "ok" || echo "not ok"
111test_color HWB sRGB && echo "ok" || echo "not ok"
112test_color Log sRGB && echo "ok" || echo "not ok"
113test_color YIQ sRGB && echo "ok" || echo "not ok"
114test_color YUV sRGB && echo "ok" || echo "not ok"
115test_color YCbCr sRGB && echo "ok" || echo "not ok"
116test_color OHTA sRGB && echo "ok" || echo "not ok"
cristy19a2b0d2012-08-21 11:46:58 +0000117: