annotate libvo/vo_gif89a.c @ 6106:f107ccf43d26

-lavcopts ... inserted since lavc is default encoder now
author gabucino
date Fri, 17 May 2002 04:09:37 +0000
parents 4a9c7041141d
children a59795bd14d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
1 /*
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
2 * vo_gif89a.c Generate gif89a output in file out.gif
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
3 *
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
4 * Originally based on vo_png.c
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
5 *
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
6 * Stolen (C) 2002 by GifWhore <joey@yunamusic.com>
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
7 *
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
8 */
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
9
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
10 #include <stdio.h>
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
11 #include <stdlib.h>
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
12 #include <string.h>
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
13 #include <errno.h>
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
14
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
15 #include "config.h"
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
16 #include "video_out.h"
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
17 #include "video_out_internal.h"
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
18
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
19 #include "../postproc/rgb2rgb.h"
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
20
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
21 #include <gif_lib.h>
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
22
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
23 #define GIFWHORE_version 0.90
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
24
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
25 LIBVO_EXTERN (gif89a)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
26
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
27 static vo_info_t vo_info =
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
28 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
29 "GIF89a (out.gif)",
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
30 "gif89a",
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
31 "GifWhore <joey@yunamusic.com>",
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
32 ""
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
33 };
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
34
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
35 extern int verbose;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
36 extern int vo_config_count;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
37
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
38 static int image_width;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
39 static int image_height;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
40 static int image_format;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
41 static uint8_t *image_data=NULL;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
42
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
43 static int reverse_map = 0;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
44 static unsigned char framenum = 0;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
45 static int gif_frameskip;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
46 static int gif_framedelay;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
47 static int target_fps = 0;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
48
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
49 GifFileType *newgif=NULL;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
50
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
51 static uint32_t config
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
52 (uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height,
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
53 uint32_t fullscreen, char *title, uint32_t format, const vo_tune_info_t *info) {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
54 char filename[] = "out.gif";
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
55 ColorMapObject *Cmap;
6078
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
56 #ifdef HAVE_GIF_4
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
57 char LB[] = {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
58 'N','E','T','S',
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
59 'C','A','P','E',
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
60 '2','.','0' };
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
61 char LB2[] = { 1, 0x00, 0x00 };
6078
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
62 #endif
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
63
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
64 if (target_fps == 0) target_fps = 5;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
65 gif_frameskip = (vo_fps + 0.25) / target_fps;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
66 gif_framedelay = 100 / target_fps;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
67
6078
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
68 image_width = width;
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
69 image_height = height;
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
70 image_format = format;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
71
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
72 Cmap = MakeMapObject(256, NULL);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
73
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
74 switch(format) {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
75 case IMGFMT_BGR24:
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
76 reverse_map = 1;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
77 break;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
78 case IMGFMT_RGB24:
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
79 break;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
80 case IMGFMT_YV12:
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
81 yuv2rgb_init(24, MODE_RGB);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
82 image_data = malloc(image_width*image_height*3);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
83 break;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
84 default:
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
85 return 1;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
86 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
87
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
88 if (vo_config_count > 0)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
89 return 0;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
90
6078
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
91 // this line causes crashes in certain earlier versions of libungif.
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
92 // i don't know exactly which, but certainly all those before v4.
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
93 // if you have problems, you need to upgrade your gif library.
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
94 #ifdef HAVE_GIF_4
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
95 EGifSetGifVersion("89a");
6078
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
96 #else
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
97 fprintf(stderr, "vo_gif89a: Your version of libgif/libungif needs to be upgraded.\n");
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
98 fprintf(stderr, "vo_gif89a: Some functionality has been disabled.\n");
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
99 #endif
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
100 newgif = EGifOpenFileName(filename, 0);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
101 if (newgif == NULL)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
102 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
103 fprintf(stderr, "error opening file for output.\n");
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
104 return(1);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
105 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
106 EGifPutScreenDesc(newgif, image_width, image_height, 256, 0, Cmap);
6078
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
107 #ifdef HAVE_GIF_4
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
108 // version 3 of libgif/libungif does not support multiple control blocks.
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
109 // for this version, looping will be disabled.
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
110 EGifPutExtensionFirst(newgif, 0xFF, 11, LB);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
111 EGifPutExtensionLast(newgif, 0, 3, LB2);
6078
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
112 #endif
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
113
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
114 return 0;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
115 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
116
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
117 static const vo_info_t* get_info(void)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
118 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
119 return &vo_info;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
120 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
121
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
122 static uint32_t draw_frame(uint8_t * src[])
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
123 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
124 uint8_t *use_data;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
125 ColorMapObject *Cmap;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
126 uint8_t Colors[256 * 3];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
127 int z;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
128 char CB[] = { (char)(gif_framedelay >> 8), (char)(gif_framedelay & 0xff), 0, 0};
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
129
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
130 if ((framenum++ % gif_frameskip)) return(0);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
131
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
132 Cmap = MakeMapObject(256, NULL);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
133 use_data = (uint8_t *)malloc(image_width * image_height);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
134 if (gif_reduce(image_width, image_height, src[0], use_data, Colors)) return(0);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
135
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
136 if (reverse_map)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
137 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
138 for (z = 0; z < 256; z++) {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
139 Cmap->Colors[z].Blue = Colors[(z * 3) + 0];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
140 Cmap->Colors[z].Green = Colors[(z * 3) + 1];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
141 Cmap->Colors[z].Red = Colors[(z * 3) + 2];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
142 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
143 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
144 else
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
145 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
146 for (z = 0; z < 256; z++) {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
147 Cmap->Colors[z].Red = Colors[(z * 3) + 0];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
148 Cmap->Colors[z].Green = Colors[(z * 3) + 1];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
149 Cmap->Colors[z].Blue = Colors[(z * 3) + 2];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
150 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
151 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
152
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
153 EGifPutExtension(newgif, 0xF9, 0x04, CB);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
154 EGifPutImageDesc(newgif, 0, 0, image_width, image_height, 0, Cmap);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
155 EGifPutLine(newgif, use_data, image_width * image_height);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
156 FreeMapObject(Cmap);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
157 free(use_data);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
158
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
159 return (0);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
160 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
161
6078
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
162 #ifdef USE_OSD
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
163 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride)
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
164 {
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
165 vo_draw_alpha_rgb24(w, h, src, srca, stride, image_data + 3 * (y0 * image_width + x0), 3 * image_width);
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
166 }
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
167 #endif
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
168
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
169 static void draw_osd(void)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
170 {
6078
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
171 #ifdef USE_OSD
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
172 vo_draw_text(image_width, image_height, draw_alpha);
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
173 #endif
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
174 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
175
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
176 static void flip_page (void)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
177 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
178 uint8_t *use_data;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
179 ColorMapObject *Cmap;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
180 uint8_t Colors[256 * 3];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
181 int z;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
182 char CB[] = { (char)(gif_framedelay >> 8), (char)(gif_framedelay & 0xff), 0, 0};
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
183
6078
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
184 if (image_format == IMGFMT_YV12) {
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
185
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
186 if ((framenum++ % gif_frameskip)) return;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
187
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
188 Cmap = MakeMapObject(256, NULL);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
189 use_data = (uint8_t *)malloc(image_width * image_height);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
190 if (gif_reduce(image_width, image_height, image_data, use_data, Colors)) return;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
191
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
192 if (reverse_map)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
193 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
194 for (z = 0; z < 256; z++) {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
195 Cmap->Colors[z].Blue = Colors[(z * 3) + 0];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
196 Cmap->Colors[z].Green = Colors[(z * 3) + 1];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
197 Cmap->Colors[z].Red = Colors[(z * 3) + 2];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
198 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
199 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
200 else
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
201 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
202 for (z = 0; z < 256; z++) {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
203 Cmap->Colors[z].Red = Colors[(z * 3) + 0];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
204 Cmap->Colors[z].Green = Colors[(z * 3) + 1];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
205 Cmap->Colors[z].Blue = Colors[(z * 3) + 2];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
206 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
207 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
208
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
209 EGifPutExtension(newgif, 0xF9, 0x04, CB);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
210 EGifPutImageDesc(newgif, 0, 0, image_width, image_height, 0, Cmap);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
211 EGifPutLine(newgif, use_data, image_width * image_height);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
212 FreeMapObject(Cmap);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
213 free(use_data);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
214 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
215 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
216
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
217 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y )
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
218 {
6078
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
219 uint8_t *dst = image_data + (image_width * y + x) * 3;
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
220 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*3,stride[0],stride[1]);
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
221 return 0;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
222 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
223
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
224 static uint32_t
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
225 query_format(uint32_t format)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
226 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
227 switch(format){
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
228 case IMGFMT_YV12:
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
229 case IMGFMT_RGB|24:
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
230 case IMGFMT_BGR|24:
6078
4a9c7041141d cleanups, removed swscaler, osd support - by Joey Parrish <joey@yunamusic.com>
arpi
parents: 6053
diff changeset
231 return 1 | VFCAP_TIMER | VFCAP_ACCEPT_STRIDE;
6053
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
232 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
233 return 0;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
234 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
235
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
236 static void
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
237 uninit(void)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
238 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
239 char temp[256];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
240
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
241 if (image_data) { free(image_data); image_data=NULL; }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
242
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
243 if (vo_config_count > 0) {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
244 sprintf(temp, "gifwhore v%2.2f (c) %s\r\n",
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
245 GIFWHORE_version, "joey@yunamusic.com");
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
246 EGifPutComment(newgif, temp);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
247 EGifCloseFile(newgif);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
248 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
249 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
250
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
251
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
252 static void check_events(void)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
253 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
254 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
255
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
256 int gif_reduce(int width, int height,
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
257 unsigned char *source,
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
258 unsigned char *destination,
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
259 unsigned char *palette)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
260 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
261 GifColorType cmap[256];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
262 unsigned char Ra[width * height];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
263 unsigned char Ga[width * height];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
264 unsigned char Ba[width * height];
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
265 unsigned char *R, *G, *B;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
266 int Size = 256;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
267 int i;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
268
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
269 R = Ra; G = Ga; B = Ba;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
270 for (i = 0; i < width * height; i++)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
271 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
272 *R++ = *source++;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
273 *G++ = *source++;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
274 *B++ = *source++;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
275 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
276
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
277 R = Ra; G = Ga; B = Ba;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
278 if (QuantizeBuffer(width, height, &Size,
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
279 R, G, B,
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
280 destination, cmap) == GIF_ERROR)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
281 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
282 fprintf(stderr, "vo_gif89a: Quantize failed!\n");
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
283 return(-1);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
284 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
285
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
286 for (i = 0; i < Size; i++)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
287 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
288 *palette++ = cmap[i].Red;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
289 *palette++ = cmap[i].Green;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
290 *palette++ = cmap[i].Blue;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
291 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
292
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
293 return(0);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
294 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
295
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
296 static uint32_t preinit(const char *arg)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
297 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
298 int i = 0;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
299 if (arg) i = atoi(arg);
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
300 if (i > vo_fps) i = vo_fps;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
301 if (i < 1) i = 5;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
302 target_fps = i;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
303 return 0;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
304 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
305
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
306 static uint32_t control(uint32_t request, void *data, ...)
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
307 {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
308 switch (request) {
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
309 case VOCTRL_QUERY_FORMAT:
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
310 return query_format(*((uint32_t*)data));
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
311 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
312 return VO_NOTIMPL;
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
313 }
759c5a3314a2 -vo gif - by Joey Parrish <joey@yunamusic.com>
arpi
parents:
diff changeset
314