Enlightenment CVS committal
Author : raster
Project : e17
Module : libs/epeg
Dir : e17/libs/epeg/src/bin
Modified Files:
epeg_main.c
Log Message:
new epeg patch from michel
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/epeg/src/bin/epeg_main.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- epeg_main.c 26 Jul 2005 11:30:55 -0000 1.6
+++ epeg_main.c 27 Jul 2005 00:29:50 -0000 1.7
@@ -5,14 +5,16 @@
#include <string.h>
static int verbose_flag = 0;
-static int thumb_width = 0;
-static int thumb_height = 0;
+static int thumb_width = 0; // < 0 means % of input
+static int thumb_height = 0; // < 0 means % of input
+static int max_dimension = 0; // > 0 means we reduce max(w,h) to
max_dimension, with aspect preserved
static char *thumb_comment = NULL;
static struct option long_options[] =
{
{"verbose", no_argument, 0, 'v'},
{"width", required_argument, 0, 'w'},
{"height", required_argument, 0, 'h'},
+ {"max", required_argument, 0, 'm'},
{"comment", required_argument, 0, 'c'},
{0, 0, 0, 0}
};
@@ -22,8 +24,9 @@
{
printf("Usage: %s [options] input.jpg thumb.jpg\n"
" -v, --verbose\n"
- " -w, --width=<width> set thumbnail width\n"
- " -h, --height=<heigth> set thumbnail heigth\n"
+ " -w, --width=<width>[%] set thumbnail width [% of input]\n"
+ " -h, --height=<heigth>[%] set thumbnail heigth [% of input]\n"
+ " -m, --max=<maximum> reduce max(w,h) to maximum, with aspect
preserved\n"
" -c, --comment=<comment> put a comment in thumbnail\n", myname);
exit(0);
}
@@ -35,8 +38,9 @@
int c;
int option_index = 0;
char *input_file = NULL, *output_file = NULL;
+ char *p;
- while ((c = getopt_long(argc, argv, "w:h:vc:", long_options,
&option_index)) != -1) {
+ while ((c = getopt_long(argc, argv, "w:h:vc:m:", long_options,
&option_index)) != -1) {
switch (c) {
case 0:
usage(argv[0]);
@@ -46,20 +50,30 @@
break;
case 'w':
thumb_width = strtol(optarg, NULL, 10);
- if (thumb_width < 1) {
+ if (thumb_width == 0) {
fprintf(stderr, "setting thumb_width to a default minimum of
64\n");
thumb_width = 64;
+ } else {
+ // If optarg="NUMBER%" store -NUMBER (see below)
+ if ((p = strstr(optarg, "%"))) thumb_width = -thumb_width;
}
if (verbose_flag) printf("thumb_width = %d\n", thumb_width);
break;
case 'h':
thumb_height = strtol(optarg, NULL, 10);
- if (thumb_height < 1) {
+ if (thumb_height == 0) {
fprintf(stderr, "setting thumb_height to a default minimum of
64\n");
thumb_height = 64;
+ } else {
+ // If optarg="NUMBER%" store -NUMBER (see below)
+ if ((p = strstr(optarg, "%"))) thumb_height = -thumb_height;
}
if (verbose_flag) printf("thumb_height = %d\n", thumb_height);
break;
+ case 'm':
+ max_dimension = strtol(optarg, NULL, 10);
+ if (verbose_flag) printf("max_dimension = %d\n", max_dimension);
+ break;
case 'c':
thumb_comment = strdup(optarg);
if (verbose_flag) printf("thumb_comment = %s\n", thumb_comment);
@@ -110,6 +124,26 @@
}
epeg_size_get(im, &w, &h);
if (verbose_flag) printf("Image size: %ix%i\n", w, h);
+
+ if (thumb_width < 0) {
+ // This means we want %thumb_width of w
+ thumb_width = w * (-thumb_width) / 100;
+ }
+ if (thumb_height < 0) {
+ // This means we want %thumb_height of h
+ thumb_height = h * (-thumb_height) / 100;
+ }
+
+ if (max_dimension > 0) {
+ int m;
+ if (w > h) {
+ thumb_width = max_dimension;
+ thumb_height = max_dimension * h / w;
+ } else {
+ thumb_height = max_dimension;
+ thumb_width = max_dimension * w / h;
+ }
+ }
}
if (verbose_flag) printf("Thumb size: %dx%d\n", thumb_width, thumb_height);
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs