Пример #1
0
/**
 * Create a thumbnail in memory
 * @param jpegData A pointer to a jpeg image in memory
 * @param outData A pointer to a pointer that will point to the created jpeg thumbnail
 * @return the size of the created thumbnail in bytes
 * */
int create_thumbnail (unsigned char* jpegData, int jpegDataSize, unsigned char** outData, int thumb_width, int thumb_height, int max_dimension, int thumb_quality) {
  Epeg_Image *im;
  if (thumb_quality <= 0) thumb_quality = 85;
  im = epeg_memory_open(jpegData, jpegDataSize);
  if (!im) return NULL;
  int w,h;
  epeg_size_get(im, &w, &h);

   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;
     }
  } else {
    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;
    }
  }

  int decoded_size;
  epeg_decode_size_set(im, thumb_width, thumb_height);
  epeg_quality_set               (im, thumb_quality);
  epeg_memory_output_set         (im, outData, &decoded_size);
  epeg_encode                    (im);
  epeg_close                     (im);
  return decoded_size;
}
Пример #2
0
int jpeg_thumbnail (byte *data, int insize, byte **destp, int *dest_sizep, cpoint *sizep)
   {
   Epeg_Image *im;
   int stride, valid;

   im = epeg_memory_open(data, insize);
   if (!im)
      return 0;

   sizep->x = im->in.w / CONFIG_preview_scale;
   sizep->y = im->in.h / CONFIG_preview_scale;
   epeg_decode_size_set           (im, sizep->x, sizep->y);
   epeg_quality_set               (im, 75, FALSE);
//   epeg_thumbnail_comments_enable (im, 1);
   epeg_memory_output_set (im, destp, dest_sizep);
//   epeg_encode                    (im);
   stride = (sizep->x * im->in.jinfo.num_components + 3) & ~3;

   epeg_raw                    (im, stride);
#if 1 // don't do this for now */
   valid = im->last_valid_row;
   if (valid != -1 && valid < im->in.h)
      {
      printf ("data short - shrink preview from %d to %d\n", sizep->y, valid / CONFIG_preview_scale);
      sizep->y = valid / CONFIG_preview_scale;    // shrink preview
      *dest_sizep = stride * sizep->y;
      }
#endif
   epeg_copy (im, sizep->x, sizep->y, stride);
   epeg_close                     (im);
   return valid;
   }
Пример #3
0
JPEG_THUMB_STATUS jpeg_thumb_file_(char* src,char* dst,JPEG_THUMB_CONFIG* config ){
	Epeg_Image * image;
	int ch;
	image = epeg_file_open(src);
	if (!image) {
		return JPEG_THUMB_STATUS_SRC_FILE_NOT_EXIST;
	}

	epeg_decode_size_set(image, config->width, config->height);
	epeg_quality_set    (image, config->quality);
	epeg_file_output_set(image, dst);
	epeg_encode(image);
	epeg_close(image);
	return JPEG_THUMB_STATUS_OK;

}
Пример #4
0
JPEG_THUMB_STATUS jpeg_thumb_file(const char* src,const char* dst,int width,int height, int quality ){
	Epeg_Image * image;
	int ch;
	image = epeg_file_open(src);
	if (!image) {
		return JPEG_THUMB_STATUS_SRC_FILE_NOT_EXIST;
	}

	epeg_decode_size_set(image, width, height);
	epeg_quality_set    (image, quality);
	epeg_file_output_set(image, dst);
	epeg_encode(image);
	epeg_close(image);
	return JPEG_THUMB_STATUS_OK;

}
Пример #5
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;
}
Пример #6
0
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;
}