Fawkes API  Fawkes Development Version
qa_jpegbm.cpp
1 
2 /***************************************************************************
3  * qa_jpegbm.h - QA for benchmarking jpeg compression
4  *
5  * Created: Fri Jul 20 13:22:51 2007
6  * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 /// @cond QA
25 
26 #include <fvutils/color/colorspaces.h>
27 #include <fvutils/compression/jpeg_compressor.h>
28 
29 #include <utils/time/tracker.h>
30 #include <iostream>
31 #include <cstdlib>
32 
33 using namespace std;
34 using namespace fawkes;
35 using namespace firevision;
36 
37 #define IMAGE_WIDTH 500
38 #define IMAGE_HEIGHT 500
39 
40 #define NUM_CYCLES 100
41 
42 // ~ 500 KB should be enough
43 #define DEST_BUF_SIZE 500000
44 
45 int
46 main(int argc, char **argv)
47 {
48 
49  unsigned char *yuv422planar = malloc_buffer(YUV422_PLANAR, IMAGE_WIDTH, IMAGE_HEIGHT);
50  unsigned char *compressed = (unsigned char *)malloc(DEST_BUF_SIZE);
51 
52  JpegImageCompressor *jpeg = new JpegImageCompressor(JpegImageCompressor::JPEG_CI_MMAL, 40,
53  JpegImageCompressor::JPEG_CS_RGB);
54  //jpeg->set_filename("test.jpg");
55  jpeg->set_image_dimensions(IMAGE_WIDTH, IMAGE_HEIGHT);
56  jpeg->set_image_buffer(YUV422_PLANAR, yuv422planar);
57  jpeg->set_destination_buffer(compressed, DEST_BUF_SIZE);
58  jpeg->set_compression_destination(ImageCompressor::COMP_DEST_MEM);
59 
60  TimeTracker *tracker = new TimeTracker(true);
61 
62  for ( unsigned int i = 0; i < NUM_CYCLES; ++i) {
63  printf("Compress %u\n", i);
64  jpeg->compress();
65  printf("Ping\n");
66  tracker->ping(0);
67  printf("Done %u with %zu bytes\n", i, jpeg->compressed_size());
68  }
69 
70  tracker->print_to_stdout();
71 
72  delete tracker;
73  delete jpeg;
74  free(compressed);
75  free(yuv422planar);
76 
77  return 0;
78 }
79 
80 
81 
82 /// @endcond
void ping(unsigned int cls)
Ping class.
Definition: tracker.cpp:194
virtual void set_compression_destination(ImageCompressor::CompressionDestination cd)
Set compression destination.
Fawkes library namespace.
virtual size_t compressed_size()
Get compressed size.
virtual void compress()
Compress image.
STL namespace.
Jpeg image compressor.
virtual void set_image_buffer(colorspace_t cspace, unsigned char *buffer)
Set image buffer to compress.
Time tracking utility.
Definition: tracker.h:38
virtual void set_image_dimensions(unsigned int width, unsigned int height)
Set dimensions of image to compress.
virtual void set_destination_buffer(unsigned char *buf, unsigned int buf_size)
Set destination buffer (if compressing to memory).
void print_to_stdout()
Print results to stdout.
Definition: tracker.cpp:317