Просмотр исходного кода

Add ICC profile, change scan to tiff not png

We now support scanner calibration profiles (created with argyllcms).
We also now scan to TIFF which has improved performance greatly,
because PNGs are slow.
cinaeco 2 месяцев назад
Родитель
Сommit
fd88d2583d
2 измененных файлов с 44 добавлено и 44 удалено
  1. 44 44
      scan-dialog
  2. BIN
      scanner.icm

+ 44 - 44
scan-dialog

@@ -24,80 +24,74 @@ function check_filename {
 }
 }
 export -f check_filename # Make available to run_scan's command substitution
 export -f check_filename # Make available to run_scan's command substitution
 
 
-# Run scanner. arguments: 1-folder 2-prefix 3-timestamp 4-format 5-papersize 6-resolution 7-colormode
+# Run scanner. arguments:
+# 1-folder 2-prefix 3-timestamp 4-format
+# 5-papersize 6-resolution 7-iccprofile 8-colourmode
 function run_scan {
 function run_scan {
 
 
   # Paper sizes.
   # Paper sizes.
   landscape=false
   landscape=false
   case $5 in
   case $5 in
   A4)
   A4)
-    x=210
-    y=297
+    x=210 y=297
     ;;
     ;;
   A4-R)
   A4-R)
-    x=210
-    y=297
-    landscape=true
+    x=210 y=297 landscape=true
     ;;
     ;;
   A5)
   A5)
-    x=148
-    y=210
+    x=148 y=210
     ;;
     ;;
   A5-R)
   A5-R)
     if [[ $6 == "150" ]] then
     if [[ $6 == "150" ]] then
       # Force A4 instead, and cut later.
       # Force A4 instead, and cut later.
       # Sane epson backend throws an out of memory error at ~A5R 150DPI.
       # Sane epson backend throws an out of memory error at ~A5R 150DPI.
-      x=210
-      y=297
+      x=210 y=297
     fi
     fi
-    x=210
-    y=148
+    x=210 y=148
     ;;
     ;;
   B5)
   B5)
-    x=176
-    y=250
+    x=176 y=250
     ;;
     ;;
   B5-R)
   B5-R)
-    x=176
-    y=250
-    landscape=true
+    x=176 y=250 landscape=true
     ;;
     ;;
   LTR)
   LTR)
-    x=216
-    y=279
+    x=216 y=279
     ;;
     ;;
   LTR-R)
   LTR-R)
-    x=216
-    y=279
-    landscape=true
+    x=216 y=279 landscape=true
     ;;
     ;;
   esac
   esac
 
 
   filename=$1/$2-$(date +"%Y-%m-%d-%H%M%S").$4
   filename=$1/$2-$(date +"%Y-%m-%d-%H%M%S").$4
   filename=$(check_filename $filename)
   filename=$(check_filename $filename)
   userid=$(id -u $USER)
   userid=$(id -u $USER)
-  tempname="/var/run/user/$userid/temp-$(date +%s).png"
+  tempname="/var/run/user/$userid/temp-$(date +%s).tif"
 
 
-  echo "$7 $6 $x $y $filename"
+  echo "$8 $6 $x $y $filename"
 
 
-  scanimage --mode=$7 --resolution=$6 -x $x -y $y --format=png --output-file=$tempname | \
-  yad --progress --text="Scanning to PNG..." --width=300 --no-buttons --auto-close
+  scanimage --mode=$8 --resolution=$6 -x $x -y $y --format=tiff --output-file=$tempname | \
+  yad --progress --text="Scanning (TIFF)..." --width=300 --no-buttons --auto-close
 
 
-  if [[ $landscape == true ]] then
-    convert $tempname -rotate 90 $tempname | \
-    yad --progress --text="Rotating to Landscape" --width=300 --no-buttons --auto-close
-  fi
+  options=""
+  [[ $landscape == true ]] && options="${options} -rotate 90"
+  [[ $7 == "Yes" ]] && options="${options} -profile /home/cinaeco/scan-dialog/scanner.icm"
+  echo "Options: $options"
+
+  convert $options $tempname $tempname | \
+  yad --progress --text="Modifying..." --width=300 --no-buttons --auto-close
 
 
   case $4 in
   case $4 in
     png)
     png)
-      cp $tempname $filename
+      convert $tempname $filename | \
+      yad --progress --text="Converting to $4..." --width=300 --no-buttons --auto-close
       ;;
       ;;
     jpg)
     jpg)
       convert -quality 85 $tempname $filename | \
       convert -quality 85 $tempname $filename | \
-      yad --progress --text="Converting to jpg..." --width=300 --no-buttons --auto-close
+      yad --progress --text="Converting to $4..." --width=300 --no-buttons --auto-close
       ;;
       ;;
     pdf)
     pdf)
-      if [[ $7 != "Lineart" ]] then
+      if [[ $8 != "Lineart" ]] then
         tempname2="${tempname%.png}.jpg"
         tempname2="${tempname%.png}.jpg"
         convert -quality 85 $tempname $tempname2 | \
         convert -quality 85 $tempname $tempname2 | \
         yad --progress --text="Converting to jpg..." --width=300 --no-buttons --auto-close
         yad --progress --text="Converting to jpg..." --width=300 --no-buttons --auto-close
@@ -105,14 +99,17 @@ function run_scan {
         tempname=$tempname2
         tempname=$tempname2
       fi
       fi
       convert $tempname $filename | \
       convert $tempname $filename | \
-      yad --progress --text="Converting to pdf..." --width=300 --no-buttons --auto-close
+      yad --progress --text="Converting to $4..." --width=300 --no-buttons --auto-close
+      ;;
+    tiff)
+      cp $tempname $filename
       ;;
       ;;
   esac
   esac
 
 
   size_raw=$(stat -c%s $filename)
   size_raw=$(stat -c%s $filename)
   size_kb=$((size_raw/1024))
   size_kb=$((size_raw/1024))
 
 
-  yad --picture --title="Filesize: $size_kb KB ($4)" --size=fit --width=750 --height=1000  --filename=$tempname
+  yad --picture --title="Filesize: $size_kb KB ($4)" --size=fit --width=750 --height=1000 --filename=$tempname
   rm $tempname
   rm $tempname
 }
 }
 export -f run_scan # Make function available to yad button command.
 export -f run_scan # Make function available to yad button command.
@@ -123,19 +120,22 @@ yad --form --orient=hor --maximized --width=750 --height=250 --columns=3 --focus
   --field="Scan Folder:SFL" /mnt/public/scans \
   --field="Scan Folder:SFL" /mnt/public/scans \
   --field="Filename Prefix:SFL" scan \
   --field="Filename Prefix:SFL" scan \
   --field="Timestamp:CB" Yes\!No \
   --field="Timestamp:CB" Yes\!No \
-  --field="File format:CB" jpg\!png\!pdf \
+  --field="File format:CB" jpg\!png\!pdf\!tiff \
   --field="Paper Size:CB" A4\!A4-R\!A5\!A5-R\!B5\!B5-R\!LTR\!LTR-R\! \
   --field="Paper Size:CB" A4\!A4-R\!A5\!A5-R\!B5\!B5-R\!LTR\!LTR-R\! \
   --field="Resolution (DPI):CB" 75\!150\!^300\!600\!1200 \
   --field="Resolution (DPI):CB" 75\!150\!^300\!600\!1200 \
+  --field="Apply ICC Profile:CB" Yes\!No \
   --field="Scan Buttons:BTN" "" \
   --field="Scan Buttons:BTN" "" \
-  --field="Colour:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 %6 Color"' \
-  --field="Grayscale:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 %6 Gray"' \
-  --field="B&W:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 %6 Lineart"' \
+  --field="Colour:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 %6 %7 Color"' \
+  --field="Grayscale:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 %6 %7 Gray"' \
+  --field="B&W:FBTN" 'bash -c "run_scan %1 %2 %3 %4 %5 %6 %7 Lineart"' \
+  --field="...:BTN" "" \
   --field="...:BTN" "" \
   --field="...:BTN" "" \
   --field="...:BTN" "" \
   --field="...:BTN" "" \
   --field="Presets:BTN" "" \
   --field="Presets:BTN" "" \
-  --field="Art (Colour PNG):FBTN" 'bash -c "run_scan %1 art %3 png %5 %6 Color"' \
-  --field="Art (Colour JPG):FBTN" 'bash -c "run_scan %1 art %3 jpg %5 %6 Color"' \
-  --field="Doc (Colour PDF):FBTN" 'bash -c "run_scan %1 doc %3 pdf %5 %6 Color"' \
-  --field="Doc (Gray PDF):FBTN" 'bash -c "run_scan %1 doc %3 pdf %5 %6 Gray"' \
-  --field="Doc (B&W PDF):FBTN" 'bash -c "run_scan %1 doc %3 pdf %5 %6 Lineart"' \
+  --field="Art (Colour PNG):FBTN" 'bash -c "run_scan %1 art %3 png %5 %6 %7 Color"' \
+  --field="Art (Colour JPG):FBTN" 'bash -c "run_scan %1 art %3 jpg %5 %6 %7 Color"' \
+  --field="Doc (Colour PDF):FBTN" 'bash -c "run_scan %1 doc %3 pdf %5 %6 %7 Color"' \
+  --field="Doc (Gray PDF):FBTN"   'bash -c "run_scan %1 doc %3 pdf %5 %6 %7 Gray"' \
+  --field="Doc (B&W PDF):FBTN" 'bash -c "run_scan %1 doc %3 pdf %5 %6 %7 Lineart"' \
+  --field="...:BTN" "" \
   --no-buttons --buttons-layout=center
   --no-buttons --buttons-layout=center