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#include <utils/time/tracker.h>
29
30#include <cstdlib>
31#include <iostream>
32
33using namespace std;
34using namespace fawkes;
35using 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
45int
46main(int argc, char **argv)
47{
48 unsigned char *yuv422planar = malloc_buffer(YUV422_PLANAR, IMAGE_WIDTH, IMAGE_HEIGHT);
49 unsigned char *compressed = (unsigned char *)malloc(DEST_BUF_SIZE);
50
51 JpegImageCompressor *jpeg = new JpegImageCompressor(JpegImageCompressor::JPEG_CI_MMAL,
52 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/// @endcond
Time tracking utility.
Definition: tracker.h:37
void print_to_stdout()
Print results to stdout.
Definition: tracker.cpp:307
void ping(unsigned int cls)
Ping class.
Definition: tracker.cpp:185
Jpeg image compressor.
virtual void compress()
Compress image.
virtual size_t compressed_size()
Get compressed size.
virtual void set_image_buffer(colorspace_t cspace, unsigned char *buffer)
Set image buffer to compress.
virtual void set_compression_destination(ImageCompressor::CompressionDestination cd)
Set compression destination.
virtual void set_destination_buffer(unsigned char *buf, unsigned int buf_size)
Set destination buffer (if compressing to memory).
virtual void set_image_dimensions(unsigned int width, unsigned int height)
Set dimensions of image to compress.
Fawkes library namespace.