generate_resources.sh (2450B)
1 #!/bin/bash 2 # This generates the png and jxl images needed. 3 4 # Function to check if a command exists 5 command_exists() { 6 command -v "$1" &> /dev/null 7 } 8 9 # Function to convert and compress an image 10 convert_and_compress() { 11 local input_image=$1 12 local base_name=$2 13 local color_space=$3 14 15 cjxl "$input_image" temp.jxl -d 0 16 djxl temp.jxl "${base_name}_${color_space}_lossless.png" 17 cjxl "${base_name}_${color_space}_lossless.png" "${base_name}_${color_space}_lossy.jxl" -d 0.0001 -e 7 18 djxl "${base_name}_${color_space}_lossy.jxl" "${base_name}_${color_space}_lossy.png" 19 cjxl "${base_name}_${color_space}_lossless.png" "${base_name}_${color_space}_lossless.jxl" -d 0 20 } 21 22 # Check for required tools 23 for tool in convert cjxl djxl; do 24 if ! command_exists "$tool"; then 25 echo "$tool could not be found. Please install it and run the script again." 26 exit 1 27 fi 28 done 29 30 # Create a 3x3 transparent image 31 convert -size 3x3 xc:none 3x3a.png 32 33 # Draw colors with alpha values 34 convert 3x3a.png \ 35 -fill "rgba(255,0,0,0.5)" -draw "point 0,0" \ 36 -fill "rgba(0,255,0,0.5)" -draw "point 1,0" \ 37 -fill "rgba(0,0,255,0.5)" -draw "point 2,0" \ 38 -fill "rgba(128,64,64,0.5)" -draw "point 0,1" \ 39 -fill "rgba(64,128,64,0.5)" -draw "point 1,1" \ 40 -fill "rgba(64,64,128,0.5)" -draw "point 2,1" \ 41 -fill "rgba(255,255,255,0.5)" -draw "point 0,2" \ 42 -fill "rgba(128,128,128,0.5)" -draw "point 1,2" \ 43 -fill "rgba(0,0,0,0.5)" -draw "point 2,2" \ 44 3x3a.png 45 46 # Generate initial image with alpha values 47 generate_image 3x3a.png 48 49 # Generate a version without alpha channel 50 convert 3x3a.png -alpha off 3x3.png 51 52 # Define color spaces 53 # TODO(firsching): add "RGB_D65_202_Rel_PeQ" and "RGB_D65_202_Rel_HLG" as color spaces here 54 color_spaces=("srgb") 55 56 # Loop through color spaces and convert/compress images 57 for color_space in "${color_spaces[@]}"; do 58 convert_and_compress 3x3.png "3x3" "$color_space" 59 convert_and_compress 3x3a.png "3x3a" "$color_space" 60 done 61 62 convert 3x3.png -quality 70 3x3.jpg 63 # lossless recompression 64 cjxl 3x3.jpg 3x3_jpeg_recompression.jxl 65 # checking that it was actually byte exact 66 djxl 3x3_jpeg_recompression.jxl 3x3_recovered.jpg 67 diff 3x3.jpg 3x3_recovered.jpg 68 if [ $? -ne 0 ]; then 69 echo "The recovery of the recompressed jpg failed: 3x3.png and 3x3_recovered.jpg differ" 70 exit 1 71 fi 72 # generate reference png 73 djxl 3x3_jpeg_recompression.jxl 3x3_jpeg_recompression.png 74 75 # Cleanup temporary file 76 rm -f temp.jxl 3x3.png 3x3a.png 3x3.jpg 3x3_recovered.jpg