Forráskód Böngészése

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 hónapja
szülő
commit
fd88d2583d
2 módosított fájl, 44 hozzáadás és 44 törlés
  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
 
-# 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 {
 
   # Paper sizes.
   landscape=false
   case $5 in
   A4)
-    x=210
-    y=297
+    x=210 y=297
     ;;
   A4-R)
-    x=210
-    y=297
-    landscape=true
+    x=210 y=297 landscape=true
     ;;
   A5)
-    x=148
-    y=210
+    x=148 y=210
     ;;
   A5-R)
     if [[ $6 == "150" ]] then
       # Force A4 instead, and cut later.
       # Sane epson backend throws an out of memory error at ~A5R 150DPI.
-      x=210
-      y=297
+      x=210 y=297
     fi
-    x=210
-    y=148
+    x=210 y=148
     ;;
   B5)
-    x=176
-    y=250
+    x=176 y=250
     ;;
   B5-R)
-    x=176
-    y=250
-    landscape=true
+    x=176 y=250 landscape=true
     ;;
   LTR)
-    x=216
-    y=279
+    x=216 y=279
     ;;
   LTR-R)
-    x=216
-    y=279
-    landscape=true
+    x=216 y=279 landscape=true
     ;;
   esac
 
   filename=$1/$2-$(date +"%Y-%m-%d-%H%M%S").$4
   filename=$(check_filename $filename)
   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
     png)
-      cp $tempname $filename
+      convert $tempname $filename | \
+      yad --progress --text="Converting to $4..." --width=300 --no-buttons --auto-close
       ;;
     jpg)
       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)
-      if [[ $7 != "Lineart" ]] then
+      if [[ $8 != "Lineart" ]] then
         tempname2="${tempname%.png}.jpg"
         convert -quality 85 $tempname $tempname2 | \
         yad --progress --text="Converting to jpg..." --width=300 --no-buttons --auto-close
@@ -105,14 +99,17 @@ function run_scan {
         tempname=$tempname2
       fi
       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
 
   size_raw=$(stat -c%s $filename)
   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
 }
 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="Filename Prefix:SFL" scan \
   --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="Resolution (DPI):CB" 75\!150\!^300\!600\!1200 \
+  --field="Apply ICC Profile:CB" Yes\!No \
   --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="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

BIN
scanner.icm