Changeset 120
- Timestamp:
- 02/07/06 00:53:13 (3 years ago)
- Files:
-
- fastphoto/trunk/src/cache.c (modified) (5 diffs)
- fastphoto/trunk/src/cache.h (modified) (1 diff)
- fastphoto/trunk/src/cgi.c (modified) (2 diffs)
- fastphoto/trunk/src/fastphoto.h (modified) (2 diffs)
- fastphoto/trunk/src/main.c (modified) (4 diffs)
- fastphoto/trunk/src/resize.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fastphoto/trunk/src/cache.c
r116 r120 44 44 } 45 45 46 staticint47 file_check (char * filename, time_t * mtime )46 int 47 file_check (char * filename, time_t * mtime, off_t * size) 48 48 { 49 49 struct stat statbuf; … … 59 59 } 60 60 61 *mtime = statbuf.st_mtime; 61 if (mtime) *mtime = statbuf.st_mtime; 62 if (size) *size = statbuf.st_size; 62 63 63 64 return 1; … … 70 71 int ret; 71 72 72 if ((ret = file_check (cachefile, &cache_mtime )) != 1) {73 if ((ret = file_check (cachefile, &cache_mtime, NULL)) != 1) { 73 74 return ret; 74 75 } 75 76 76 if ((ret = file_check (params->infile, &orig_mtime )) != 1) {77 if ((ret = file_check (params->infile, &orig_mtime, NULL)) != 1) { 77 78 return ret; 78 79 } … … 87 88 88 89 return 1; 90 } 91 92 int 93 memory_init (fastphoto_t * params) 94 { 95 params->outfile = NULL; 96 97 if ((file_check (params->infile, NULL, ¶ms->infile_size)) == 1) { 98 params->data = malloc (params->infile_size); 99 params->data_size = params->infile_size; 100 } 101 102 return 0; 103 } 104 105 int 106 memory_send (fastphoto_t * params) 107 { 108 fwrite (params->data, 1, params->data_size, stdout); 89 109 } 90 110 … … 125 145 126 146 if (!mkdirs (cachefile)) { 147 fprintf (stderr, "fastphoto: Error creating cachefile %s\n", cachefile); 127 148 free (cachefile); 128 cachefile = "/tmp/cache.jpg"; 129 params->outfile = cachefile;149 150 memory_init (params); 130 151 } 131 152 } fastphoto/trunk/src/cache.h
r107 r120 4 4 int cache_init (fastphoto_t * params, char * path_info); 5 5 6 int memory_init (fastphoto_t * params); 7 int memory_send (fastphoto_t * params); 8 6 9 #endif /* __CACHE_H__ */ fastphoto/trunk/src/cgi.c
r116 r120 81 81 params->infile = path_translated; 82 82 params->outfile = NULL; 83 params->data = NULL; 84 params->data_size = 0; 83 85 params->cached = 0; 84 86 params->x = 0; 85 87 params->y = 0; 86 88 params->scale = 0; 89 params->quality = 0; /* default */ 90 params->gray = 0; 87 91 88 92 parse_query (params, query_string); … … 106 110 size_t n; 107 111 108 fd = fopen (params->outfile, "rb"); 109 while ((n = fread (buf, 1, BUFSIZE, fd)) > 0) { 110 fwrite (buf, 1, n, stdout); 112 if (params->outfile) { 113 fd = fopen (params->outfile, "rb"); 114 while ((n = fread (buf, 1, BUFSIZE, fd)) > 0) { 115 fwrite (buf, 1, n, stdout); 116 } 117 fclose (fd); 118 } else if (params->data) { 119 fprintf (stderr, "fastphoto: Sending from memory ...\n"); 120 fwrite (params->data, 1, params->data_size, stdout); 111 121 } 112 fclose (fd);113 122 114 123 return 1; fastphoto/trunk/src/fastphoto.h
r117 r120 1 1 #ifndef __FASTPHOTO_H__ 2 2 #define __FASTPHOTO_H__ 3 4 #include <sys/types.h> 3 5 4 6 #define FASTPHOTO_DEFAULT_X 128 … … 12 14 char * infile; 13 15 char * outfile; 16 17 off_t infile_size; 18 /* If outfile == NULL, write to memory */ 19 unsigned char * data; 20 int data_size; 21 14 22 int cached; 23 int info; 24 15 25 int x; 16 26 int y; 17 27 int scale; 28 int quality; 18 29 int gray; 19 int quality;20 int info;21 30 }; 22 31 fastphoto/trunk/src/main.c
r119 r120 8 8 9 9 #include "fastphoto.h" 10 #include "cache.h" 10 11 #include "cgi.h" 11 12 #include "resize.h" … … 44 45 int i; 45 46 47 params->data = NULL; 48 params->data_size = 0; 49 46 50 params->cached = 0; 51 params->info = 0; 47 52 params->x = 0; 48 53 params->y = 0; 49 54 params->scale = 0; 55 params->quality = 0; /* default */ 50 56 params->gray = 0; 51 params->quality = 0; /* default */52 params->info = 0;53 57 54 58 while (1) { … … 126 130 127 131 params->infile = argv[optind++]; 128 params->outfile = argv[optind++]; 132 133 if (optind >= argc) { 134 memory_init (params); 135 } else { 136 params->outfile = argv[optind++]; 137 } 129 138 130 139 return 1; … … 161 170 if (cgi) { 162 171 cgi_send (¶ms); 172 } else if (!params.outfile) { 173 memory_send (¶ms); 163 174 } 175 176 if (params.data) free (params.data); 164 177 165 178 return 0; fastphoto/trunk/src/resize.c
r117 r120 21 21 goto im_close; 22 22 } 23 24 if (params->outfile == NULL) goto im_close;25 23 26 24 x = params->x; … … 48 46 epeg_quality_set (im, params->quality); 49 47 50 epeg_file_output_set(im, params->outfile); 48 if (params->outfile) 49 epeg_file_output_set(im, params->outfile); 50 else if (params->data) 51 epeg_memory_output_set (im, ¶ms->data, ¶ms->data_size); 52 51 53 epeg_encode(im); 52 54 … … 54 56 epeg_close(im); 55 57 } 56
