Permalink
Browse files

Added different filters, menus, bug fixing, etc. No issues.

  • Loading branch information...
1 parent 4920184 commit b6f8c379a2e7ed2f25a9b8350e4d8bfe7d86056d @graulund graulund committed Oct 22, 2011
@@ -6,6 +6,3 @@
// Copyright 2011 Christian Zimmermann. All rights reserved.
//
-//#define path "/Users/chr/Documents/C/Grayscale/Grayscale/"
-
-//const char * thePath = "/Users/chr/Documents/C/Grayscale/Grayscale/";
@@ -6,46 +6,49 @@
#include <stdio.h>
#include <stdlib.h>
+#include "ccd.h"
#include "bmp.h"
#include "Common.h"
static IMAGE current_image;
WORD ccd_pixel_pointer;
-WORD ccd_get_height() {
+WORD ccd_get_height(void) {
return current_image.Height;
}
-WORD ccd_get_width() {
+WORD ccd_get_width(void) {
return current_image.Width;
}
-void ccd_capture_image() {
- //char buffer[50];
- //sprintf(buffer, "%s/example24.bmp", thePath);
- //printf(buffer); printf("\n");
- //if(!bmp_open(buffer, &current_image)) {
- if(!bmp_open("/Users/chr/Documents/C/Johanne.bmp", &current_image)) {
- printf("ccd_capture_image(): failed to open file\n");
+void ccd_capture_image(void) {
+ char file[100];
+ char srcPath[] = "/Users/andy/Dropbox/DTU/Semester3/Systemer/Pics/";
+ char srcFileName[] = "Johanne.bmp";
+ sprintf(file, "%s%s", srcPath, srcFileName);
+ if(bmp_open(file, &current_image)) {
+ printf("Opened file %s...\n", srcFileName);
+ } else {
+ printf("ccd_capture_image(): failed to open file %s\n", file);
exit(0);
}
}
-void ccd_reset_pointer() {
+void ccd_reset_pointer(void) {
/* reset */
ccd_pixel_pointer = 0;
}
-BYTE ccd_get_pixel() {
+BYTE ccd_get_pixel(void) {
BYTE pixel = current_image.Pixels[ccd_pixel_pointer++];
//printf("Reading pixel to be %d\n", pixel);
return pixel;
}
-WORD ccd_get_pixels() {
+WORD ccd_get_pixels(void) {
/* todo: return (four) pixels */
@@ -9,21 +9,21 @@
#include "types.h"
/* get the width of the next image to show */
-WORD ccd_get_width();
+WORD ccd_get_width(void);
/* get the width of the next image to show */
-WORD ccd_get_height();
+WORD ccd_get_height(void);
/* capture an image */
-void ccd_capture_image();
+void ccd_capture_image(void);
/* reset internal pixel pointer */
-void ccd_reset_pointer();
+void ccd_reset_pointer(void);
/* get one pixel of the captured image */
-BYTE ccd_get_pixel();
+BYTE ccd_get_pixel(void);
/* get four pixels of the captured image */
-WORD ccd_get_pixels();
+WORD ccd_get_pixels(void);
#endif /* __CCD_H */
@@ -28,17 +28,19 @@ void lcd_set_height(WORD height) {
image.Height = height;
}
-void lcd_show_image() {
- //char buffer[50];
- //if(!bmp_save(sprintf(buffer, "%soutput.bmp", thePath), &image)) {
- if(!bmp_save("/Users/chr/Documents/C/output_lulz.bmp", &image)) {
- printf("lcd_show_image(): failed to save file\n");
+void lcd_show_image(void) {
+ char file[100];
+ char dstPath[] = "/Users/andy/Dropbox/DTU/Semester3/Systemer/Pics/";
+ char dstFileName[] = "output.bmp";
+ sprintf(file, "%s%s", dstPath, dstFileName);
+ if(!bmp_save(file, &image)) {
+ printf("lcd_show_image(): failed to save file to %s\n", file);
} else {
- printf("File saved!\n");
+ printf("File saved! %s\n", dstFileName);
}
}
-void lcd_reset_pointer() {
+void lcd_reset_pointer(void) {
/* reset, ready for new image */
lcd_pixel_pointer = 0;
@@ -15,10 +15,10 @@ void lcd_set_width(WORD width);
void lcd_set_height(WORD height);
/* show the image */
-void lcd_show_image();
+void lcd_show_image(void);
/* reset the internal pixel pointer */
-void lcd_reset_pointer();
+void lcd_reset_pointer(void);
/* set the next four pixels of the image */
void lcd_set_pixel(BYTE pixel);
@@ -5,49 +5,74 @@
#include "ccd.h"
#include "lcd.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
-BOOL filter(void);
+int randcoeff(void);
+BOOL runcamera(int filterid);
+BOOL filter(int filterid);
+void go_ui(void);
+
+unsigned int iseed;
int main(int argc, char *argv[]) {
- WORD i, w, h;
-
- printf("Hello\n");
+ // Keep it simple
+ BOOL ui = TRUE;
+ if(ui){
+ go_ui();
+ } else {
+ runcamera(0);
+ }
+ return 0;
+}
+int randcoeff(void){
+ // A number between and including (max/2)-1 and -((max/2)-1)
+ float max = 20.0;
+ return (1 + (int)( max * rand() / ( RAND_MAX + 1.0 ) )) - (int)(max/2);
+}
+
+BOOL runcamera(int filterid){
+ WORD w, h;
+ printf("Hello\n");
+
/* capture image */
- printf("Capturing image\n");
+ printf("Capturing image\n");
ccd_capture_image();
-
+
/* reset ccd and lcd pointers */
- printf("Resetting pointers\n");
+ printf("Resetting pointers\n");
ccd_reset_pointer();
lcd_reset_pointer();
-
+
/* set width/height of lcd to match captured image */
- printf("Setting width and height\n");
+ printf("Setting width and height\n");
w = ccd_get_width();
h = ccd_get_height();
-
+
lcd_set_width(w);
lcd_set_height(h);
-
- // Filter that bad boy + Transfer
- filter();
-
+
+ // Filter that bad boy + Transfer
+ filter(filterid);
+
/* transfer image from ccd to lcd a pixel at a time */
- /*printf("Transfering image\n");
- for(i = 0; i < w * h; i++)
- lcd_set_pixel(ccd_get_pixel());*/
-
+ /*printf("Transfering image\n");
+ for(i = 0; i < w * h; i++)
+ lcd_set_pixel(ccd_get_pixel());*/
+
/* show image on lcd */
- printf("Showing the image on LCD\n");
+ printf("Showing the image on LCD\n");
lcd_show_image();
-
- return 0;
+
+ return TRUE;
}
-BOOL filter(void) {
+BOOL filter(int filterid) {
WORD w, h;
+ int bluricity;
w = ccd_get_width();
h = ccd_get_height();
@@ -57,13 +82,56 @@ BOOL filter(void) {
initial[i] = ccd_get_pixel();
}
- int filter[3][3] = {{1,0,-1},
- {2,0,-2},
- {1,0,-1}};
+ int f[3][3] = {{0,0,0},
+ {0,1,0},
+ {0,0,0}};
+
+ switch (filterid) {
+ case 1:
+ // Intaglio
+ f[0][0] = 1; f[0][1] = 0; f[0][2] = -1;
+ f[1][0] = 2; f[1][1] = 0; f[1][2] = -2;
+ f[2][0] = 1; f[2][1] = 0; f[2][2] = -1;
+ break;
+ case 2:
+ // Underground lair
+ f[0][0] = -6; f[0][1] = -6; f[0][2] = -6;
+ f[1][0] = 6; f[1][1] = 9; f[1][2] = -5;
+ f[2][0] = -8; f[2][1] = 10; f[2][2] = 7;
+ break;
+ case 3:
+ // Acid trip
+ f[0][0] = -5; f[0][1] = 2; f[0][2] = 5;
+ f[1][0] = 0; f[1][1] = -10; f[1][2] = 0;
+ f[2][0] = 5; f[2][1] = 2; f[2][2] = -5;
+ break;
+ case 4:
+ // Vague (blur)
+ bluricity = 10;
+ f[0][0] = bluricity; f[0][1] = bluricity; f[0][2] = bluricity;
+ f[1][0] = bluricity; f[1][1] = bluricity; f[1][2] = bluricity;
+ f[2][0] = bluricity; f[2][1] = bluricity; f[2][2] = bluricity;
+ break;
+ case 5:
+ // Random
+ iseed = (unsigned int)time(NULL);
+ srand(iseed);
+ f[0][0] = randcoeff(); f[0][1] = randcoeff(); f[0][2] = randcoeff();
+ f[1][0] = randcoeff(); f[1][1] = randcoeff(); f[1][2] = randcoeff();
+ f[2][0] = randcoeff(); f[2][1] = randcoeff(); f[2][2] = randcoeff();
+ printf(
+ "%d %d %d\n%d %d %d\n%d %d %d\n",
+ f[0][0], f[0][1], f[0][2],
+ f[1][0], f[1][1], f[1][2],
+ f[2][0], f[2][1], f[2][2]
+ );
+ break;
+ }
+
int filterSum = 0;
for (int k=0; k<3; k++) {
for (int l=0; l<3; l++) {
- filterSum += filter[k][l];
+ filterSum += f[k][l];
}
}
@@ -80,8 +148,8 @@ BOOL filter(void) {
} else {
for (i=-1; i<=1; i++) {
for (j=-1; j<=1; j++) {
- //sum += filter[j+1][i+1];
- pixel += filter[i+1][j+1] * initial[(r+i)*w+(c+j)]; // what about the edges, bro?
+ //sum += f[j+1][i+1];
+ pixel += f[i+1][j+1] * initial[(r+i)*w+(c+j)]; // what about the edges, bro?
}
}
}
@@ -102,3 +170,28 @@ BOOL filter(void) {
return TRUE;
}
+
+void go_ui(void){
+ int currentScreen = 0;
+ int selection;
+ while (currentScreen >= 0) {
+ switch (currentScreen) {
+ case 0:
+ printf("WELCOME TO THE DIGITAL CAMERA ======================\nPress 1 to capture an image, any other key to exit.\n> ");
+ scanf("%d", &selection);
+ currentScreen = selection == 1 ? 1 : -1;
+ break;
+ case 1:
+ printf("Please select a filter:\n1) Intaglio\n2) Underground lair\n3) Acid trip\n4) Vague evening\n5) Random filter\n0) No filter\n> ");
+ scanf("%d", &selection);
+ //TODO: CREATE SOME FILTERS
+ if(selection >= 0 && selection <= 5){
+ runcamera(selection);
+ currentScreen = -1;
+ } else {
+ printf("Try again.\n");
+ }
+ break;
+ }
+ }
+}

0 comments on commit b6f8c37

Please sign in to comment.