예제 #1
0
/*
 * call-seq:
 *  intialize()
 *
 * See Epeg::Image.open
 */
static VALUE rb_epeg_image_initialize(VALUE self)
{
  Epeg_Image *image;
  Data_Get_Struct(self, Epeg_Image, image);

  VALUE q = rb_cv_get(CLASS_OF(self), "@@quality");
  epeg_quality_set(image, NUM2UINT(q));
  rb_iv_set(self, "@quality", q);

  epeg_comment_set(image, (char *)NULL);

  int w, h;
  epeg_size_get(image, &w, &h);

  rb_iv_set(self, "@width",     INT2NUM(w));
  rb_iv_set(self, "@height",    INT2NUM(h));

  rb_iv_set(self, "epeg_file_closed", Qfalse);
  rb_iv_set(self, "epeg_trimmed",     Qfalse);

  return self;
}
예제 #2
0
/* main function: */
int main(int argc, char **argv)
{
   Epeg_Image *im;

   if (argc != 3) {
	   printf("Usage: %s input.jpg thumb.jpg\n", argv[0]);
	   exit(0);
   }
   im = epeg_file_open(argv[1]);
   if (!im) {
	   printf("cannot open %s\n", argv[1]);
	   exit(-1);
   } else { /* (the "else" is new, but it should work the same) */
	   const char *com;
	   Epeg_Thumbnail_Info info;
	   int w, h;

	   com = epeg_comment_get(im);
	   if (com) {
		   printf("Comment: %s\n", com);
	   }
	   epeg_thumbnail_comments_get(im, &info);
	   if (info.mimetype) {
		   printf("Thumb Mimetype: %s\n", info.mimetype);
		   if (info.uri) {
			   printf("Thumb URI: %s\n", info.uri);
		   }
		   printf("Thumb Mtime: %llu\n", info.mtime);
		   printf("Thumb Width: %i\n", info.w);
		   printf("Thumb Height: %i\n", info.h);
	   }
	   epeg_size_get(im, &w, &h);
	   printf("Image size: %ix%i\n", w, h);
   }

   epeg_decode_size_set(im, 128, 96);

#if 0
   if (0) {
	   unsigned int *pixels;

# if 0
	   epeg_decode_colorspace_set(im, EPEG_ARGB32);
# endif /* 0 */
	   pixels = epeg_pixels_get(im, 0, 0, 128, 96);
	   if (pixels) {
		   int x, y;
		   unsigned int *p;

# if defined(DEBUG) && DEBUG
		   printf("Image pixels:\n");
# endif /* DEBUG */
		   p = pixels;
		   for ((y = 0); (y < 96); y++) {
			   for ((x = 0); (x < 128); x++) {
# if defined(DEBUG) && DEBUG
				   printf("%08x ", p[0]);
# endif /* DEBUG */
				   p++;
			   }
# if defined(DEBUG) && DEBUG
			   printf("\n");
# endif /* DEBUG */
		   }
		   epeg_pixels_free(im, pixels);
	   }
   }
#endif /* 0 */

   epeg_quality_set(im, 80);
   epeg_thumbnail_comments_enable(im, 1);
   epeg_comment_set(im, "Smelly pants!");
   epeg_file_output_set(im, argv[2]);
   epeg_encode(im);
   epeg_close(im);
   return 0;
}
예제 #3
0
파일: epeg_main.c 프로젝트: anjn/epeg
int
main(int argc, char **argv)
{
    Epeg_Image *im;
    int c;
    int option_index = 0;
    char *input_file = NULL, *output_file = NULL;
    char *p;

    while ((c = getopt_long(argc, argv, "w:h:vc:m:", long_options, &option_index)) != -1) {
        switch (c) {
        case 0:
            usage(argv[0]);
            break;
        case 'v':
            verbose_flag = 1;
            break;
        case 'w':
            thumb_width = strtol(optarg, NULL, 10);
            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 == 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);
            break;
        case '?':
            usage(argv[0]);
            break;
        default:
            abort();
        }
    }

    if (optind < argc) {
        if (optind < (argc-1)) {
            input_file = argv[optind++];
            if (verbose_flag) printf("input_file = %s\n", input_file);
            output_file = argv[optind];
            if (verbose_flag) printf("output_file = %s\n", output_file);
        } else {
            usage(argv[0]);
        }
    }

    if (!input_file || !output_file) usage(argv[0]);

    if (!thumb_comment) thumb_comment = "Smelly pants!";

    im = epeg_file_open(input_file);
    if (!im) {
        fprintf(stderr, "%s: cannot open %s\n", argv[0], input_file);
        exit(-1);
    }

    {
        const char *com;
        Epeg_Thumbnail_Info info;
        int w, h;

        com = epeg_comment_get(im);
        if (verbose_flag) if (com) printf("Comment: %s\n", com);
        epeg_thumbnail_comments_get(im, &info);
        if (info.mimetype) {
            if (verbose_flag) printf("Thumb Mimetype: %s\n", info.mimetype);
            if (verbose_flag) if (info.uri) printf("Thumb URI: %s\n", info.uri);
            if (verbose_flag) printf("Thumb Mtime: %llu\n", info.mtime);
            if (verbose_flag) printf("Thumb Width: %i\n", info.w);
            if (verbose_flag) printf("Thumb Height: %i\n", info.h);
        }
        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) {
            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);
    epeg_decode_size_set(im, thumb_width, thumb_height);
    epeg_quality_set               (im, 80);
    epeg_thumbnail_comments_enable (im, 1);
    epeg_comment_set               (im, thumb_comment);
    epeg_file_output_set           (im, output_file);
    epeg_encode                    (im);
    epeg_close                     (im);
    return 0;
}