source: tools/tracertstats/output_png.c @ e78e408

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since e78e408 was ee6e802, checked in by Shane Alcock <salcock@…>, 5 years ago

Updated copyright blurb on all source files

In some cases, this meant adding copyright blurbs to files that
had never had them before.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *
3 * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand.
4 * All rights reserved.
5 *
6 * This file is part of libtrace.
7 *
8 * This code has been developed by the University of Waikato WAND
9 * research group. For further information please see http://www.wand.net.nz/
10 *
11 * libtrace is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * libtrace 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 Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 *
25 */
26
27#define HAVE_LIBFREETYPE
28#define _GNU_SOURCE
29#include "output.h"
30#include <stdio.h>
31#include <stdlib.h>
32#include "gdc.h"
33#include "gdchart.h"
34#include "gdcpie.h"
35#include <inttypes.h>
36#include <lt_inttypes.h>
37#include <err.h>
38
39struct private_png_t {
40        int rows;
41        float *data;
42};
43
44static void output_png_init(struct output_data_t *out)
45{
46        out->private_format_data=malloc(sizeof(struct private_png_t));
47        ((struct private_png_t *)out->private_format_data)->rows=0;
48        ((struct private_png_t *)out->private_format_data)->data=0;
49}
50
51static void output_png_flush(struct output_data_t *out)
52{
53        int i;
54        struct private_png_t *prv=out->private_format_data;
55        prv->rows++;
56        prv->data= realloc(prv->data,prv->rows*out->columns*sizeof(float));
57        for(i=0;i<out->columns;++i) {
58                switch (out->data[i].type) {
59                        case TYPE_int:
60                                prv->data[out->columns*(prv->rows-1)+i]=out->data[i].d.d_int;
61                                break;
62                        case TYPE_str:
63                                free(out->data[i].d.d_str);
64                                break;
65                        case TYPE_float:
66                                prv->data[out->columns*(prv->rows-1)+i]=out->data[i].d.d_float;
67                                break;
68                        case TYPE_time:
69                                prv->data[out->columns*(prv->rows-1)+i]=out->data[i].d.d_time;
70                                break;
71                }
72        }
73}
74
75static void output_png_destroy(struct output_data_t *out)
76{
77        struct private_png_t *prv=out->private_format_data;
78        int i,j;
79        char *labels[prv->rows];
80        float data1[(out->columns-1)/2][prv->rows];
81        float data2[(out->columns-1)/2][prv->rows];
82        for(i=0;i<prv->rows;++i) {
83                if (asprintf(&labels[i],"%i",(int)prv->data[i*out->columns])==-1) {
84                        err(1,"Out of memory");
85                }
86                for(j=0;j<(out->columns-1)/2;++j) {
87                        data1[j][i]=prv->data[i*out->columns+j*2+1];
88                        data2[j][i]=prv->data[i*out->columns+j*2+2];
89                }
90        }
91
92        GDC_image_type = GDC_PNG;
93        GDC_title = out->title;
94        GDC_out_graph( 640, 480,
95                        stdout,
96                        GDC_COMBO_LINE_LINE,
97                        prv->rows,
98                        labels, 
99                        (out->columns-1)/2,
100                        (float*)data1,
101                        (float*)data2);
102        free(prv->data);
103        free(prv);
104}
105
106struct output_type_t output_png = {
107        .name= "png",
108        .init= output_png_init,
109        .flush= output_png_flush,
110        .destroy= output_png_destroy,
111};
Note: See TracBrowser for help on using the repository browser.