cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
Cristy | f6ff9ea | 2016-12-05 09:53:35 -0500 | [diff] [blame] | 3 | # Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 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 | # |
cristy | 3a350cf | 2012-12-29 22:54:19 +0000 | [diff] [blame] | 17 | . ./common.shi |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 18 | . ${srcdir}/tests/common.shi |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 19 | |
| 20 | depth=`eval ${MAGICK} xc:none -format '%[fx:QuantumRange]' info:-` |
cristy | a304441 | 2013-03-02 22:02:49 +0000 | [diff] [blame] | 21 | if [ "X$depth" = "X255" ]; then |
cristy | 61e6e54 | 2012-08-22 17:07:58 +0000 | [diff] [blame] | 22 | echo "1..1" |
| 23 | echo "ok" |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 24 | exit 0 |
| 25 | fi |
cristy | 61e6e54 | 2012-08-22 17:07:58 +0000 | [diff] [blame] | 26 | echo "1..19" |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 27 | |
| 28 | # how to generate a one pixel (average rose) color and output its values |
| 29 | in="rose: -scale 1x1" # a one pixel image of the average color. |
| 30 | out="-format '%[fx:int(255*r+.5)],%[fx:int(255*g+.5)],%[fx:int(255*b+.5)]' info:-" |
| 31 | |
| 32 | # ---------------- |
| 33 | |
| 34 | # Colors to compare results to. |
| 35 | error=false |
| 36 | average=`eval ${MAGICK} "$in" -noop "$out"` |
| 37 | too_dark=`eval ${MAGICK} "$in" -colorspace RGB "$out"` |
| 38 | too_light=`eval ${MAGICK} "$in" -set colorspace RGB -colorspace sRGB "$out"` |
| 39 | format='%-30s%s\n' # results formating |
| 40 | format2='%-30s%-14s%s\n' |
| 41 | |
| 42 | printf "$format2" "Average \"rose:\" Color" "$average" "sRGB(rose)" |
| 43 | printf "$format2" "Too Dark Color" "$too_dark" "sRGB(rose)->RGB result" |
| 44 | printf "$format2" "Too Light Color" "$too_light" "RGB(rose)->sRGB result" |
| 45 | echo '' |
| 46 | |
| 47 | # |
| 48 | # Sanity checks |
| 49 | # |
| 50 | # NOTE: as a extra validation on sanity checks below... |
| 51 | # eval ${MAGICK} "$in" -gamma .454545 "$out" |
| 52 | # produces a value of 74,25,20 which is close to 73,26,21 below. |
| 53 | # eval ${MAGICK} "$in" -gamma 2.2 "$out" |
| 54 | # produces a value of 198,158,151 whcih is close to 199,160,152 below. |
| 55 | # |
| 56 | # Actual values used below come from IM v6.5.4-7 colorspace conversions |
| 57 | # |
| 58 | error=false |
| 59 | if [ "X$average" != "X146,89,80" ]; then |
| 60 | echo "Sanity Failure: Average expected to be 145,89,80 - ABORTING" |
| 61 | error=true |
| 62 | fi |
| 63 | if [ "X$too_dark" != "X73,26,21" ]; then |
| 64 | echo "Sanity Failure: Too Dark expected to be 73,26,21 - ABORTING" |
| 65 | error=true |
| 66 | fi |
| 67 | if [ "X$too_light" != "X199,160,152" ]; then |
| 68 | echo "Sanity Failure: Too Light expected to be 199,160,152 - ABORTING" |
| 69 | error=true |
| 70 | fi |
| 71 | $error && exit 1 |
| 72 | |
| 73 | test_color() { |
| 74 | test="sRGB" |
| 75 | cs=''; |
| 76 | for i in "$@"; do |
| 77 | test="${test}->$i" # format of the test being performed |
| 78 | cs="$cs -colorspace $i" # colorspace operations to perform test |
| 79 | done |
| 80 | color=`eval ${MAGICK} "$in" $cs "$out"` |
| 81 | |
| 82 | if [ "X$color" = "X$average" ]; then |
cristy | 8391c6a | 2012-08-21 15:25:07 +0000 | [diff] [blame] | 83 | return 0 |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 84 | fi |
| 85 | # Its failed the round-trip test, now report how it failed! |
| 86 | error=true |
| 87 | if [ "X$color" = "X$too_light" ]; then |
cristy | 8391c6a | 2012-08-21 15:25:07 +0000 | [diff] [blame] | 88 | return 1 |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 89 | fi |
| 90 | if [ "X$color" = "X$too_dark" ]; then |
cristy | 8391c6a | 2012-08-21 15:25:07 +0000 | [diff] [blame] | 91 | return 1 |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 92 | fi |
cristy | 8391c6a | 2012-08-21 15:25:07 +0000 | [diff] [blame] | 93 | return 1 |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | # ---------------- |
| 97 | |
cristy | 8391c6a | 2012-08-21 15:25:07 +0000 | [diff] [blame] | 98 | test_color RGB sRGB && echo "ok" || echo "not ok" |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 99 | |
cristy | 8391c6a | 2012-08-21 15:25:07 +0000 | [diff] [blame] | 100 | test_color XYZ sRGB && echo "ok" || echo "not ok" |
| 101 | test_color XYZ RGB sRGB && echo "ok" || echo "not ok" |
| 102 | test_color RGB XYZ sRGB && echo "ok" || echo "not ok" |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 103 | |
cristy | 8391c6a | 2012-08-21 15:25:07 +0000 | [diff] [blame] | 104 | test_color LAB sRGB && echo "ok" || echo "not ok" |
| 105 | test_color XYZ LAB sRGB && echo "ok" || echo "not ok" |
| 106 | test_color LAB XYZ sRGB && echo "ok" || echo "not ok" |
| 107 | test_color RGB LAB sRGB && echo "ok" || echo "not ok" |
| 108 | test_color LAB RGB sRGB && echo "ok" || echo "not ok" |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 109 | |
cristy | 8391c6a | 2012-08-21 15:25:07 +0000 | [diff] [blame] | 110 | test_color CMY sRGB && echo "ok" || echo "not ok" |
| 111 | test_color CMYK sRGB && echo "ok" || echo "not ok" |
| 112 | test_color HSL sRGB && echo "ok" || echo "not ok" |
| 113 | test_color HSB sRGB && echo "ok" || echo "not ok" |
| 114 | test_color HWB sRGB && echo "ok" || echo "not ok" |
| 115 | test_color Log sRGB && echo "ok" || echo "not ok" |
| 116 | test_color YIQ sRGB && echo "ok" || echo "not ok" |
| 117 | test_color YUV sRGB && echo "ok" || echo "not ok" |
| 118 | test_color YCbCr sRGB && echo "ok" || echo "not ok" |
| 119 | test_color OHTA sRGB && echo "ok" || echo "not ok" |
cristy | 19a2b0d | 2012-08-21 11:46:58 +0000 | [diff] [blame] | 120 | : |