/* * Sample application to read an image from the CAM60 sensor * * * Copyright 2009, KwikByte * * Revision history: * * 04MAY2009 Initial creation */ #include #include #include #include #include #include #include #include #include #include /* * This is highly configurable and depends on image size and jpg quality. * We will use 1600x1200 at 400KB for this demo. * * NOTE: in JPG mode the width and height are coded as file size - * NOT image resolution. */ #define IMAGE_WIDTH 1024 #define IMAGE_HEIGHT 400 #define IMAGE_SIZE (IMAGE_WIDTH * IMAGE_HEIGHT) #define FILE_SIZE IMAGE_SIZE /* ***************************** MAIN *************************************** */ int main(int argc, char *argv[]) { char *imageData; int retVal; int isiFile; int outFile; printf("\n\t** CAM60 Sample Program **\n"); if (argc < 2) { printf("Output file not specified\n"); exit (1); } printf("Writing file: %s\n", argv[1]); /* Open the image sensor driver - character 81,0 in this demo */ if ((isiFile = open("/dev/cam60_isi", (O_RDONLY))) < 0) { printf("Unable to open the device: cam60_isi\n"); exit (1); } /* Reserve memory for the image */ if (!(imageData = malloc(FILE_SIZE))) { printf("Unable to allocate memory for the image buffer\n"); close (isiFile); exit (1); } /* Take a picture */ retVal = read(isiFile, imageData, (FILE_SIZE)); /* Write it to the file */ if ((outFile = open(argv[1], O_CREAT | O_RDWR)) > 0) { write (outFile, imageData, FILE_SIZE); close (outFile); } free(imageData); close (isiFile); return (0); }