1\name{readJPEG} 2\alias{readJPEG} 3\title{ 4Read a bitmap image stored in the JPEG format 5} 6\description{ 7Reads an image from a JPEG file/content into a raster array. 8} 9\usage{ 10readJPEG(source, native = FALSE) 11} 12\arguments{ 13 \item{source}{Either name of the file to read from or a raw vector 14 representing the JPEG file content.} 15 \item{native}{determines the image representation - if \code{FALSE} 16 (the default) then the result is an array, if \code{TRUE} then the 17 result is a native raster representation.} 18} 19%\details{ 20%} 21\value{ 22If \code{native} is \code{FALSE} then an array of the dimensions height 23x width x channels. If there is only one channel the result is a 24matrix. The values are reals between 0 and 1. If \code{native} is 25\code{TRUE} then an object of the class \code{nativeRaster} is 26returned instead. The latter cannot be easily computed on but is the 27most efficient way to draw using \code{rasterImage}. 28 29Most common files decompress into RGB (3 channels) or 30Grayscale (1 channel). Note that Grayscale images 31cannot be directly used in \code{\link{rasterImage}} unless 32\code{native} is set to \code{TRUE} because \code{rasterImage} requires 33RGB or RGBA format (\code{nativeRaster} is always 8-bit RGBA). 34 35JPEG doesn't support alpha channel, you may want to use PNG instead in 36such situations. 37} 38%\references{ 39%} 40%\author{ 41%} 42\note{ 43 CMYK JPEG images saved by Adobe Photoshop may have inverted ink values due 44 to a bug in Photoshop. Unfortunately this includes some sample CMYK 45 images that are floating around, so beware of the source when 46 converting the result to other color spaces. \code{readJPEG} will 47 preserve values exactly as they are encoded in the file. 48} 49\seealso{ 50\code{\link{rasterImage}}, \code{\link{writeJPEG}} 51} 52\examples{ 53# read a sample file (R logo) 54img <- readJPEG(system.file("img", "Rlogo.jpg", package="jpeg")) 55 56# read it also in native format 57img.n <- readJPEG(system.file("img", "Rlogo.jpg", package="jpeg"), TRUE) 58 59# if your R supports it, we'll plot it 60if (exists("rasterImage")) { # can plot only in R 2.11.0 and higher 61 plot(1:2, type='n') 62 63 rasterImage(img, 1.2, 1.27, 1.8, 1.73) 64 rasterImage(img.n, 1.5, 1.5, 1.9, 1.8) 65} 66} 67\keyword{IO} 68