Skip to content

Commit

Permalink
add option to output in grayscale
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.kfish.org/fastphoto/trunk@115 9c49b5d1-7df3-0310-bce2-b7278e68f44c
  • Loading branch information
conrad committed Feb 6, 2006
1 parent c36ce24 commit 46b2d2f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions fastphoto.1
Expand Up @@ -29,6 +29,9 @@ Set the height of the output image.
.TP
\fB\-s\fR, \fB\-\-scale\fR
Set the scale as a percentage
.TP
\fB\-g\fR, \fB\-\-gray\fR
Convert to grayscale

.PP
\fBMiscellaneous options\fR
Expand Down
4 changes: 2 additions & 2 deletions src/cache.c
Expand Up @@ -96,9 +96,9 @@ cache_init (fastphoto_t * params, char * path_info)
int cached;

if (params->scale) {
cachefile = alloc_snprintf ("%s%s?scale=%d", cachedir, path_info, params->scale);
cachefile = alloc_snprintf ("%s%s?scale=%d%s", cachedir, path_info, params->scale, params->gray ? "&gray" : "");
} else {
cachefile = alloc_snprintf ("%s%s?x=%d&y=%d", cachedir, path_info, params->x, params->y);
cachefile = alloc_snprintf ("%s%s?x=%d&y=%d%s", cachedir, path_info, params->x, params->y, params->gray ? "&gray" : "");
}

cached = cache_check (params, cachefile);
Expand Down
1 change: 1 addition & 0 deletions src/cgi.c
Expand Up @@ -15,6 +15,7 @@ set_param (fastphoto_t * params, char * key, char * val)
if (!strcmp ("x", key)) params->x = atoi(val);
if (!strcmp ("y", key)) params->y = atoi(val);
if (!strcmp ("scale", key)) params->scale = atoi(val);
if (!strcmp ("gray", key)) params->gray = 1;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/fastphoto.h
Expand Up @@ -15,6 +15,7 @@ struct fastphoto_s {
int x;
int y;
int scale;
int gray;
};

#endif /* __FASTPHOTO_H__ */
7 changes: 6 additions & 1 deletion src/main.c
Expand Up @@ -25,6 +25,7 @@ usage (void)
printf (" -x, --width Set the width of the output image\n");
printf (" -y, --height Set the height of the output image\n");
printf (" -s, --scale Set a percentage to scale the image by\n");
printf (" -g, --gray Output grayscale\n");
printf ("\n");
}

Expand All @@ -39,9 +40,10 @@ cmd_init (fastphoto_t * params, int argc, char * argv[])
params->x = 0;
params->y = 0;
params->scale = 0;
params->gray = 0;

while (1) {
char * optstring = "hvx:y:s:";
char * optstring = "hvx:y:s:g";

#ifdef HAVE_GETOPT_LONG
static struct option long_options[] = {
Expand All @@ -50,6 +52,7 @@ cmd_init (fastphoto_t * params, int argc, char * argv[])
{"width", required_argument, 0, 'x'},
{"height", required_argument, 0, 'y'},
{"scale", required_argument, 0, 's'},
{"gray", no_argument, 0, 'g'},
{0,0,0,0}
};

Expand Down Expand Up @@ -79,6 +82,8 @@ cmd_init (fastphoto_t * params, int argc, char * argv[])
case 's': /* scale */
params->scale = atoi (optarg);
break;
case 'g': /* gray */
params->gray = 1;
default:
break;
}
Expand Down
3 changes: 3 additions & 0 deletions src/resize.c
Expand Up @@ -30,6 +30,9 @@ resize (fastphoto_t * params)
}
epeg_decode_size_set(im, x, y);

if (params->gray)
epeg_decode_colorspace_set (im, EPEG_GRAY8);

epeg_file_output_set(im, params->outfile);
epeg_encode(im);
epeg_close(im);
Expand Down

0 comments on commit 46b2d2f

Please sign in to comment.