Beispiel #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;
}
Beispiel #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;
   }
Beispiel #3
0
static VALUE rb_epeg_image_from_blob(VALUE klass, VALUE blob)
{
  Epeg_Image *image = epeg_memory_open(RSTRING_PTR(blob), RSTRING_LEN(blob));

  if(!image) { rb_raise(rb_eRuntimeError, "Error: unable to read blob"); }

  VALUE image_obj = Data_Wrap_Struct(klass, NULL, rb_epeg_image_destroy, image);

  rb_obj_call_init(image_obj, 0, NULL);

  return image_obj;
}