2 * producer_ppm.c -- simple ppm test case
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "producer_ppm.h"
22 #include <framework/mlt_frame.h>
26 static int producer_get_frame( mlt_producer producer
, mlt_frame_ptr frame
, int index
);
27 static void producer_close( mlt_producer parent
);
29 mlt_producer
producer_ppm_init( void *command
)
31 producer_ppm
this = calloc( sizeof( struct producer_ppm_s
), 1 );
32 if ( this != NULL
&& mlt_producer_init( &this->parent
, this ) == 0 )
34 mlt_producer producer
= &this->parent
;
36 producer
->get_frame
= producer_get_frame
;
37 producer
->close
= producer_close
;
39 if ( command
== NULL
)
40 this->command
= strdup( "image2raw -n -a -r 3 -ppm /usr/share/pixmaps/*.png" );
42 this->command
= strdup( command
);
44 this->pipe
= popen( this->command
, "r" );
52 static int producer_get_image( mlt_frame
this, uint8_t **buffer
, mlt_image_format
*format
, int *width
, int *height
, int writable
)
54 // Get the frames properties
55 mlt_properties properties
= mlt_frame_properties( this );
58 uint8_t *rgb
= mlt_properties_get_data( properties
, "image", NULL
);
60 // Get width and height
61 *width
= mlt_properties_get_int( properties
, "width" );
62 *height
= mlt_properties_get_int( properties
, "height" );
64 // Convert to requested format
65 if ( *format
== mlt_image_yuv422
)
67 uint8_t *image
= malloc( *width
* *height
* 2 );
68 mlt_convert_rgb24_to_yuv422( rgb
, *width
, *height
, *width
* 3, image
);
69 mlt_properties_set_data( properties
, "image", image
, *width
* *height
* 2, free
, NULL
);
72 else if ( *format
== mlt_image_rgb24
)
80 static int producer_get_frame( mlt_producer producer
, mlt_frame_ptr frame
, int index
)
82 producer_ppm
this = producer
->child
;
86 // Construct a test frame
87 *frame
= mlt_frame_init( );
90 if ( fscanf( this->pipe
, "P6\n%d %d\n255\n", &width
, &height
) == 2 )
92 // Get the frames properties
93 mlt_properties properties
= mlt_frame_properties( *frame
);
96 uint8_t *image
= malloc( width
* height
* 3 );
99 fread( image
, width
* height
* 3, 1, this->pipe
);
101 // Pass the data on the frame properties
102 mlt_properties_set_data( properties
, "image", image
, width
* height
* 3, free
, NULL
);
103 mlt_properties_set_int( properties
, "width", width
);
104 mlt_properties_set_int( properties
, "height", height
);
106 // Push the image callback
107 mlt_frame_push_get_image( *frame
, producer_get_image
);
110 // Update timecode on the frame we're creating
111 mlt_frame_set_timecode( *frame
, mlt_producer_position( producer
) );
113 // Calculate the next timecode
114 mlt_producer_prepare_next( producer
);
119 static void producer_close( mlt_producer parent
)
121 producer_ppm
this = parent
->child
;
122 pclose( this->pipe
);
123 free( this->command
);
124 parent
->close
= NULL
;
125 mlt_producer_close( parent
);