Fix external image conversion on MS-Windows

* lisp/image/image-converter.el (image-converter--convert-magick)
(image-converter--convert): Force encoding/decoding to avoid any
text or EOL conversions, since we are reading/writing binary
data.  (Bug#56317)
This commit is contained in:
Eli Zaretskii 2022-06-30 13:50:34 +03:00
parent 6f22631a63
commit f5421104e9

View file

@ -227,19 +227,21 @@ Only suffixes that map to `image-mode' are returned."
(cadr (split-string (symbol-name image-format) "/")))) (cadr (split-string (symbol-name image-format) "/"))))
(defun image-converter--convert-magick (type source image-format) (defun image-converter--convert-magick (type source image-format)
(let ((command (image-converter--value type :command))) (let ((command (image-converter--value type :command))
(coding-system-for-read 'no-conversion))
(unless (zerop (if image-format (unless (zerop (if image-format
;; We have the image data in SOURCE. ;; We have the image data in SOURCE.
(progn (progn
(insert source) (insert source)
(apply #'call-process-region (point-min) (point-max) (let ((coding-system-for-write 'no-conversion))
(car command) t t nil (apply #'call-process-region (point-min) (point-max)
(append (car command) t t nil
(cdr command) (append
(list (format "%s:-" (cdr command)
(image-converter--mime-type (list (format "%s:-"
image-format)) (image-converter--mime-type
"png:-")))) image-format))
"png:-")))))
;; SOURCE is a file name. ;; SOURCE is a file name.
(apply #'call-process (car command) (apply #'call-process (car command)
nil t nil nil t nil
@ -252,18 +254,20 @@ Only suffixes that map to `image-mode' are returned."
(cl-defmethod image-converter--convert ((type (eql 'ffmpeg)) source (cl-defmethod image-converter--convert ((type (eql 'ffmpeg)) source
image-format) image-format)
"Convert using ffmpeg." "Convert using ffmpeg."
(let ((command (image-converter--value type :command))) (let ((command (image-converter--value type :command))
(coding-system-for-read 'no-conversion))
(unless (zerop (if image-format (unless (zerop (if image-format
(progn (progn
(insert source) (insert source)
(apply #'call-process-region (let ((coding-system-for-write 'no-conversion))
(point-min) (point-max) (car command) (apply #'call-process-region
t '(t nil) nil (point-min) (point-max) (car command)
(append t '(t nil) nil
(cdr command) (append
(list "-i" "-" (cdr command)
"-c:v" "png" (list "-i" "-"
"-f" "image2pipe" "-")))) "-c:v" "png"
"-f" "image2pipe" "-")))))
(apply #'call-process (apply #'call-process
(car command) (car command)
nil '(t nil) nil nil '(t nil) nil