This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,23 @@
# Convert color image (PPM) to greyscale image (PGM)
(de ppm->pgm (Ppm)
(mapcar
'((Y)
(mapcar
'((C)
(/
(+
(* (car C) 2126) # Red
(* (cadr C) 7152) # Green
(* (caddr C) 722) ) # Blue
10000 ) )
Y ) )
Ppm ) )
# Convert greyscale image (PGM) to color image (PPM)
(de pgm->ppm (Pgm)
(mapcar
'((Y)
(mapcar
'((G) (list G G G))
Y ) )
Pgm ) )

View file

@ -0,0 +1,26 @@
# Write greyscale image (PGM) to file
(de pgmWrite (Pgm File)
(out File
(prinl "P5")
(prinl (length (car Pgm)) " " (length Pgm))
(prinl 255)
(for Y Pgm (apply wr Y)) ) )
# Create an empty image of 120 x 90 pixels
(setq *Ppm (make (do 90 (link (need 120)))))
# Fill background with green color
(ppmFill *Ppm 0 255 0)
# Draw a diagonal line
(for I 80 (ppmSetPixel *Ppm I I 0 0 0))
# Convert to greyscale image (PGM)
(setq *Pgm (ppm->pgm *Ppm))
# Write greyscale image to .pgm file
(pgmWrite *Pgm "img.pgm")
# Convert to color image and write to .ppm file
(ppmWrite (pgm->ppm *Pgm) "img.ppm")