~ubuntu-branches/ubuntu/trusty/gavl/trusty

« back to all changes in this revision

Viewing changes to src/fill_test.c

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2007-04-16 12:53:08 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070416125308-k8gdo9sofz72gjkf
Tags: 0.2.5-1
* New upstream release
* Adapted fpic.patch to the new version
* Fixed broken watch file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <gavl.h>
 
3
//#include "colorspace.h" // Common routines
 
4
#include <stdio.h>
 
5
#include <png.h>
 
6
 
 
7
static void
 
8
write_png(char * filename, gavl_video_format_t * format, gavl_video_frame_t * frame)
 
9
  {
 
10
  int i;
 
11
  unsigned char ** rows;
 
12
 
 
13
  int color_type;
 
14
  FILE * output;
 
15
 
 
16
  png_structp png_ptr;
 
17
  png_infop   info_ptr;
 
18
  
 
19
  gavl_video_converter_t * cnv;
 
20
    
 
21
  gavl_video_format_t format_1;
 
22
  gavl_video_frame_t * frame_1 = (gavl_video_frame_t*)0;
 
23
 
 
24
  
 
25
  if((format->pixelformat != GAVL_RGB_24) && (format->pixelformat != GAVL_RGBA_32))
 
26
    {
 
27
    cnv = gavl_video_converter_create();
 
28
    
 
29
    gavl_video_format_copy(&format_1, format);
 
30
 
 
31
    if(gavl_pixelformat_has_alpha(format->pixelformat))
 
32
      {
 
33
      format_1.pixelformat = GAVL_RGBA_32;
 
34
      color_type = PNG_COLOR_TYPE_RGBA;
 
35
      }
 
36
    else
 
37
      {
 
38
      format_1.pixelformat = GAVL_RGB_24;
 
39
      color_type = PNG_COLOR_TYPE_RGB;
 
40
      }
 
41
    frame_1 = gavl_video_frame_create(&format_1);
 
42
    
 
43
    gavl_video_converter_init(cnv, format, &format_1);
 
44
    
 
45
    gavl_video_convert(cnv, frame, frame_1);
 
46
    gavl_video_converter_destroy(cnv);
 
47
    }
 
48
  else if(format->pixelformat == GAVL_RGB_24)
 
49
    {
 
50
    color_type = PNG_COLOR_TYPE_RGB;
 
51
    }
 
52
  else
 
53
    {
 
54
    color_type = PNG_COLOR_TYPE_RGBA;
 
55
    }
 
56
  
 
57
  output = fopen(filename, "wb");
 
58
  if(!output)
 
59
    return;
 
60
 
 
61
  png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
 
62
                                         NULL, NULL);
 
63
 
 
64
  info_ptr = png_create_info_struct(png_ptr);
 
65
  setjmp(png_jmpbuf(png_ptr));
 
66
  png_init_io(png_ptr, output);
 
67
  
 
68
  png_set_IHDR(png_ptr, info_ptr,
 
69
               format->image_width,
 
70
               format->image_height,
 
71
               8, color_type, PNG_INTERLACE_NONE,
 
72
               PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
 
73
 
 
74
  rows = malloc(format->image_height * sizeof(*rows));
 
75
 
 
76
  if(frame_1)
 
77
    {
 
78
    for(i = 0; i < format->image_height; i++)
 
79
      rows[i] = frame_1->planes[0] + i * frame_1->strides[0];
 
80
    }
 
81
  else
 
82
    {
 
83
    for(i = 0; i < format->image_height; i++)
 
84
      rows[i] = frame->planes[0] + i * frame->strides[0];
 
85
    }
 
86
  
 
87
  png_set_rows(png_ptr, info_ptr, rows);
 
88
  png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
 
89
 
 
90
  png_destroy_write_struct(&png_ptr, &info_ptr);
 
91
  fclose(output);
 
92
  free(rows);
 
93
  if(frame_1)
 
94
    gavl_video_frame_destroy(frame_1);
 
95
  }
 
96
 
 
97
int main(int argc, char ** argv)
 
98
  {
 
99
  
 
100
  char filename_buffer[1024];
 
101
  int i, imax;
 
102
    
 
103
  gavl_video_format_t frame_format;
 
104
 
 
105
  gavl_video_frame_t * frame;
 
106
  float color[4] = { 0.0, 1.0, 0.0, 0.5 };
 
107
  
 
108
  memset(&frame_format,   0, sizeof(frame_format));
 
109
 
 
110
  frame_format.image_width  = 128;
 
111
  frame_format.image_height = 128;
 
112
  frame_format.frame_width  = 128;
 
113
  frame_format.frame_height = 128;
 
114
 
 
115
  frame_format.pixel_width  = 1;
 
116
  frame_format.pixel_height = 1;
 
117
  
 
118
  imax = gavl_num_pixelformats();
 
119
  
 
120
  for(i = 0; i < imax; i++)
 
121
    {
 
122
    frame_format.pixelformat = gavl_get_pixelformat(i);
 
123
    
 
124
    //    if(frame_csp != GAVL_YUVA_32)
 
125
    //      continue;
 
126
    
 
127
    //    csp = GAVL_RGB_24;
 
128
    
 
129
    frame   = gavl_video_frame_create(&frame_format);
 
130
 
 
131
    sprintf(filename_buffer, "fill_%s.png",
 
132
            gavl_pixelformat_to_string(frame_format.pixelformat));
 
133
    
 
134
    gavl_video_frame_fill(frame, &frame_format, color);
 
135
    write_png(filename_buffer, &frame_format, frame);
 
136
    gavl_video_frame_destroy(frame);
 
137
    fprintf(stderr, "Wrote %s\n", filename_buffer);
 
138
    }
 
139
  return 0;
 
140
  }