Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
video_out_pgm.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "config.h"
00025
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <inttypes.h>
00030
00031 #include "video_out.h"
00032
00033 typedef struct {
00034 vo_instance_t vo;
00035 int framenum;
00036 int width;
00037 int height;
00038 char header[1024];
00039 char filename[128];
00040 } pgm_instance_t;
00041
00042 static void internal_draw_frame (pgm_instance_t * instance,
00043 FILE * file, uint8_t * const * buf)
00044 {
00045 int i;
00046
00047 fwrite (instance->header, strlen (instance->header), 1, file);
00048 fwrite (buf[0], instance->width, instance->height, file);
00049 for (i = 0; i < instance->height >> 1; i++) {
00050 fwrite (buf[1] + i * (instance->width >> 1), instance->width >> 1, 1,
00051 file);
00052 fwrite (buf[2] + i * (instance->width >> 1), instance->width >> 1, 1,
00053 file);
00054 }
00055 }
00056
00057 static void pgm_draw_frame (vo_instance_t * _instance,
00058 uint8_t * const * buf, void * id)
00059 {
00060 pgm_instance_t * instance;
00061 FILE * file;
00062
00063 instance = (pgm_instance_t *) _instance;
00064 sprintf (instance->filename, "%d.pgm", instance->framenum++);
00065 file = fopen (instance->filename, "wb");
00066 if (!file)
00067 return;
00068 internal_draw_frame (instance, file, buf);
00069 fclose (file);
00070 }
00071
00072 static int pgm_setup (vo_instance_t * _instance, int width, int height,
00073 vo_setup_result_t * result)
00074 {
00075 pgm_instance_t * instance;
00076
00077 instance = (pgm_instance_t *) _instance;
00078
00079 instance->width = width;
00080 instance->height = height;
00081 sprintf (instance->header, "P5\n%d %d\n255\n", width, height * 3 / 2);
00082 result->convert = NULL;
00083 return 0;
00084 }
00085
00086 static vo_instance_t * internal_open (void draw (vo_instance_t *,
00087 uint8_t * const *, void *))
00088 {
00089 pgm_instance_t * instance;
00090
00091 instance = (pgm_instance_t *) malloc (sizeof (pgm_instance_t));
00092 if (instance == NULL)
00093 return NULL;
00094
00095 instance->vo.setup = pgm_setup;
00096 instance->vo.setup_fbuf = NULL;
00097 instance->vo.set_fbuf = NULL;
00098 instance->vo.start_fbuf = NULL;
00099 instance->vo.draw = draw;
00100 instance->vo.discard = NULL;
00101 instance->vo.close = NULL;
00102 instance->framenum = 0;
00103
00104 return (vo_instance_t *) instance;
00105 }
00106
00107 vo_instance_t * vo_pgm_open (void)
00108 {
00109 return internal_open (pgm_draw_frame);
00110 }
00111
00112 static void pgmpipe_draw_frame (vo_instance_t * _instance,
00113 uint8_t * const * buf, void * id)
00114 {
00115 pgm_instance_t * instance;
00116
00117 instance = (pgm_instance_t *) _instance;
00118 internal_draw_frame (instance, stdout, buf);
00119 }
00120
00121 vo_instance_t * vo_pgmpipe_open (void)
00122 {
00123 return internal_open (pgmpipe_draw_frame);
00124 }
00125
00126 static void md5_draw_frame (vo_instance_t * _instance,
00127 uint8_t * const * buf, void * id)
00128 {
00129 pgm_instance_t * instance;
00130 char command[100];
00131
00132 instance = (pgm_instance_t *) _instance;
00133 pgm_draw_frame (_instance, buf, id);
00134 sprintf (command, "md5sum -b %s", instance->filename);
00135 system (command);
00136 remove (instance->filename);
00137 }
00138
00139 vo_instance_t * vo_md5_open (void)
00140 {
00141 return internal_open (md5_draw_frame);
00142 }