用emacs显示BMP文件

在前面的文章 当中,为了在emacs中实现ray tracer生成图像,我们实现了一些ppm文件的生成工具,现在只要再加上一些代码,就可以让emacs显示windows中最广泛的BMP文件了。谁说emacs不能做图像处理呢?

 

;BMP loader (defun ppm--read (file beg size) (with-temp-buffer (insert-file-contents-literally file nil beg (+ beg size)) (buffer-string))) (defun ppm--int4 (s) (logior (get-byte 0 s) (lsh (get-byte 1 s) 8) (lsh (get-byte 2 s) 16) (lsh (get-byte 3 s) 24))) (defun ppm--int3 (s) (logior (get-byte 0 s) (lsh (get-byte 1 s) 8) (lsh (get-byte 2 s) 16))) (defun ppm--int1 (s) (get-byte 0 s)) (defun ppm-from-bmp (filename) "make a ppm object from a .bmp file. only 24bit .bmp is supportted." (let* ((offset (ppm--int4 (ppm--read filename 10 4))) (headsize (ppm--int4 (ppm--read filename 14 4))) (width (ppm--int4 (ppm--read filename 18 4))) (height (ppm--int4 (ppm--read filename 22 4))) (rowbytes (lsh (lsh (+ (* width 3) 3) -2) 2)) (ppm (ppm-make width height)) (bytes (ppm--read filename offset (* rowbytes height))) (idx) (pixels (oref ppm pixels)) ) (loop for y from 0 to (1- height) do (loop for x from 0 to (1- width) do (setq idx (+ (* rowbytes y) (* 3 x))) (ppm-pixels-plot pixels x (- height y 1) (ppm-rgb (get-byte idx bytes) (get-byte (+ idx 1) bytes) (get-byte (+ idx 2) bytes)) width) )) ppm )) ;; (let ((filename "e:/foo.bmp")) ;; (ppm-show (ppm-from-bmp filename)) ;; )

 

P.S:bmp的加载,也是相当的慢啊。

你可能感兴趣的:(windows,object,File,工具,emacs,图像处理)