source: ImageMagick/branches/ImageMagick-6/tests/validate-colorspace.sh @ 7619

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