Difference between revisions of "User:Dimitrios"

From ElphelWiki
Jump to: navigation, search
(Created page with "Some notes that could be useful: =Recording and live preview= Is there a way to record and, at the same time, watch a reduced resolution version in a cheap tablet or portable P...")
 
(Added link to tclepeg in github)
 
Line 87: Line 87:
 
   return 0;
 
   return 0;
 
  }
 
  }
 +
 +
There is also a '''tclepeg''' package allowing the use of the epeg library from TCL, for the Linux i386 platform [http://github.com/dzach/tclepeg]

Latest revision as of 07:51, 5 January 2012

Some notes that could be useful:

Recording and live preview

Is there a way to record and, at the same time, watch a reduced resolution version in a cheap tablet or portable PC / notebook?

epeg is a super-fast library for resizing jpegs. It offers an improvement of at least an order of magnitude over other known libraries like ImageMagick. I just compiled a command line version and these are the results:

$ time ./resize test.jpeg test.jpg

real    0m0.063s
user    0m0.060s
sys     0m0.000s

$ time convert -resize 426x640 test.jpeg test.jpg

real    0m1.158s
user    0m1.048s
sys     0m0.052s

The improvement in the above case 18 times faster. resize is a little C program crafted for resizing a 2592x3888 image to a 426x640 one using the epeg library. Convert is ImageMagick's convert utility. It took resize 63 msec against 1158 msec for ImageMagick.

If this functionality is included in the camera it could do jpeg resize in-memory on-the-fly and spare even more by avoiding the read/write to disk that is involved in the above test.

epeg was a stand-alone utility that is now included in Enlightenment. The Maemo sources for epeg compile without a change in Kubuntu. There is also a PHP extension for epeg.


epeg does not decode the JPEG, it only decodes the DCT coefficients needed to reconstruct an image of the size desired.

From the README:

What is Epeg?

An IMMENSELY FAST JPEG thumbnailer library API.

Why write this? It's a convenience library API to using libjpeg to load JPEG
images destined to be turned into thumbnails of the original, saving
information with these thumbnails, retrieving it and managing to load the image
ready for scaling with the minimum of fuss and CPU overhead. 

This means it's insanely fast at loading large JPEG images and scaling them
down to tiny thumbnails. It's speedup will be proportional to the size
difference between the source image and the output thumbnail size as a
count of their pixels.

It makes use of libjpeg features of being able to load an image by only
decoding the DCT coefficients needed to reconstruct an image of the size
desired. This gives a massive speedup. If you do not try and access the pixels
in a format other than YUV (or GRAY8 if the source is grascale) then it also
avoids colorspace conversions as well.

In the libepeg library, there is a function epeg_memory_open() that reads a JPEG image from memory instead of a file. Then the resize can be applied and the result can be sent out instead of the original JPEG.

The C program that does the resize is this:

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <dirent.h>

#include "Epeg.h"

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);
  }
  
  epeg_decode_size_set           (im, 426, 640);
  epeg_quality_set               (im, 75);
  epeg_thumbnail_comments_enable (im, 1);
  epeg_file_output_set           (im, argv[2]);
  epeg_encode                    (im);
  epeg_close                     (im);
  
  return 0;
}

There is also a tclepeg package allowing the use of the epeg library from TCL, for the Linux i386 platform [1]