| 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+.5)],%[fx:int(255*g+.5)],%[fx:int(255*b+.5)]' 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 | # |
|---|
| 39 | # Sanity checks |
|---|
| 40 | # |
|---|
| 41 | # NOTE: as a extra validation on sanity checks below... |
|---|
| 42 | # eval ${MAGICK} "$in" -gamma .454545 "$out" |
|---|
| 43 | # produces a value of 74,25,20 which is close to 73,26,21 below. |
|---|
| 44 | # eval ${MAGICK} "$in" -gamma 2.2 "$out" |
|---|
| 45 | # produces a value of 198,158,151 whcih is close to 199,160,152 below. |
|---|
| 46 | # |
|---|
| 47 | # Actual values used below come from IM v6.5.4-7 colorspace conversions |
|---|
| 48 | # |
|---|
| 49 | if [ "X$average" != "X146,89,80" ]; then |
|---|
| 50 | echo "Sanity Failure: Average expected to be 146,89,80 - ABORTING" |
|---|
| 51 | error=true |
|---|
| 52 | fi |
|---|
| 53 | if [ "X$too_light" != "X73,26,21" ]; then |
|---|
| 54 | echo "Sanity Failure: Too Light expected to be 73,26,21 - ABORTING" |
|---|
| 55 | error=true |
|---|
| 56 | fi |
|---|
| 57 | if [ "X$too_dark" != "X199,160,152" ]; then |
|---|
| 58 | echo "Sanity Failure: Too Dark expected to be 199,160,152 - ABORTING" |
|---|
| 59 | error=true |
|---|
| 60 | fi |
|---|
| 61 | $error && exit 1 |
|---|
| 62 | |
|---|
| 63 | test_color() { |
|---|
| 64 | test="sRGB(rose)" |
|---|
| 65 | cs=''; |
|---|
| 66 | for i in "$@"; do |
|---|
| 67 | test="${test}->$i" # format of the test being performed |
|---|
| 68 | cs="$cs -colorspace $i" # colorspace operations to perform test |
|---|
| 69 | done |
|---|
| 70 | color=`eval ${MAGICK} "$in" $cs "$out"` |
|---|
| 71 | |
|---|
| 72 | if [ "X$color" = "X$average" ]; then |
|---|
| 73 | printf "$format" "$test" "good" |
|---|
| 74 | return |
|---|
| 75 | fi |
|---|
| 76 | error=false |
|---|
| 77 | if [ "X$color" = "X$too_light" ]; then |
|---|
| 78 | printf "$format" "$test" "TOO_LIGHT" |
|---|
| 79 | return |
|---|
| 80 | fi |
|---|
| 81 | if [ "X$color" = "X$too_dark" ]; then |
|---|
| 82 | printf "$format" "$test" "TOO_DARK" |
|---|
| 83 | return |
|---|
| 84 | fi |
|---|
| 85 | printf "$format" "$test" "UNKNOWN COLOR (expect $average, got $color)" |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | # ---------------- |
|---|
| 89 | |
|---|
| 90 | test_color RGB sRGB |
|---|
| 91 | test_color XYZ sRGB |
|---|
| 92 | test_color XYZ RGB sRGB |
|---|
| 93 | |
|---|
| 94 | test_color CMY sRGB |
|---|
| 95 | test_color CMYK sRGB |
|---|
| 96 | test_color HSL sRGB |
|---|
| 97 | test_color HSB sRGB |
|---|
| 98 | test_color Lab sRGB |
|---|
| 99 | test_color YIQ sRGB |
|---|
| 100 | test_color YCbCr sRGB |
|---|
| 101 | |
|---|
| 102 | $error |
|---|