annotate TOOLS/bmovl-test.c @ 36659:f41b65ac7e81

configure: disable internal libmpeg2 by default. While the last tests showed that it can be slightly faster in some cases, the difference should not be relevant to the majority of users. In addition, the code is of not particularly high quality, so I consider it better/safer to have it disabled by default. Removing the code after the next release is a possible future action.
author reimar
date Sun, 26 Jan 2014 18:19:31 +0000
parents 9fc9d1e788aa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30416
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
1 /* small program to test the features of vf_bmovl
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
2 *
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
3 * This program is free software; you can redistribute it and/or modify
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
4 * it under the terms of the GNU General Public License as published by
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
5 * the Free Software Foundation; either version 2 of the License, or
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
6 * (at your option) any later version.
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
7 *
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
8 * This program is distributed in the hope that it will be useful,
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
11 * GNU General Public License for more details.
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
12 *
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
13 * You should have received a copy of the GNU General Public License along
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
14 * with this program; if not, write to the Free Software Foundation, Inc.,
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
16 */
b573c7c7173b Add standard license header to C tools missing them.
diego
parents: 29263
diff changeset
17
22737
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
18
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
19 #include <unistd.h>
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
20 #include <fcntl.h>
22739
25586323a128 Include stdlib.h and string.h to fix the following warnings:
diego
parents: 22737
diff changeset
21 #include <string.h>
25586323a128 Include stdlib.h and string.h to fix the following warnings:
diego
parents: 22737
diff changeset
22 #include <stdlib.h>
22741
edaeb008ba93 Add explicit SDL include path. This should allow compilation even when
diego
parents: 22740
diff changeset
23 #include <SDL/SDL.h>
edaeb008ba93 Add explicit SDL include path. This should allow compilation even when
diego
parents: 22740
diff changeset
24 #include <SDL/SDL_image.h>
22737
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
25
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
26 #define DEBUG 0
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
27
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
28 static void
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
29 blit(int fifo, unsigned char *bitmap, int width, int height,
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
30 int xpos, int ypos, int alpha, int clear)
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
31 {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
32 char str[100];
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
33 int nbytes;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 23700
diff changeset
34
22737
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
35 sprintf(str, "RGBA32 %d %d %d %d %d %d\n",
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
36 width, height, xpos, ypos, alpha, clear);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 23700
diff changeset
37
22737
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
38 if(DEBUG) printf("Sending %s", str);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
39
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
40 write(fifo, str, strlen(str));
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
41 nbytes = write(fifo, bitmap, width*height*4);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
42
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
43 if(DEBUG) printf("Sent %d bytes of bitmap data...\n", nbytes);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
44 }
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
45
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
46 static void
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
47 set_alpha(int fifo, int width, int height, int xpos, int ypos, int alpha) {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
48 char str[100];
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
49
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
50 sprintf(str, "ALPHA %d %d %d %d %d\n",
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
51 width, height, xpos, ypos, alpha);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 23700
diff changeset
52
22737
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
53 if(DEBUG) printf("Sending %s", str);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
54
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
55 write(fifo, str, strlen(str));
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
56 }
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
57
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
58 static void
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
59 paint(unsigned char* bitmap, int size, int red, int green, int blue, int alpha) {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
60
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
61 int i;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
62
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
63 for(i=0; i < size; i+=4) {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
64 bitmap[i+0] = red;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
65 bitmap[i+1] = green;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
66 bitmap[i+2] = blue;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
67 bitmap[i+3] = alpha;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
68 }
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
69 }
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
70
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
71 int main(int argc, char **argv) {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
72
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
73 int fifo=-1;
23700
7dbca1914d9f Remove unused variables.
diego
parents: 22741
diff changeset
74 int width=0, height=0;
22737
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
75 unsigned char *bitmap;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
76 SDL_Surface *image;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
77 int i;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
78
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
79 if(argc<3) {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
80 printf("Usage: %s <bmovl fifo> <image file> <width> <height>\n", argv[0]);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
81 printf("width and height are w/h of MPlayer's screen!\n");
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
82 exit(10);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
83 }
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
84
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
85 width = atoi(argv[3]);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
86 height = atoi(argv[4]);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
87
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
88 fifo = open( argv[1], O_RDWR );
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
89 if(!fifo) {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
90 fprintf(stderr, "Error opening FIFO %s!\n", argv[1]);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
91 exit(10);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
92 }
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
93
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
94 image = IMG_Load(argv[2]);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
95 if(!image) {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
96 fprintf(stderr, "Couldn't load image %s!\n", argv[2]);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
97 exit(10);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
98 }
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
99
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
100 printf("Loaded image %s: width=%d, height=%d\n", argv[2], image->w, image->h);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
101
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
102 // Display and move image
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
103 for(i=0; (i < (width - image->w)) && (i < (height - image->h)); i += 5)
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
104 blit(fifo, image->pixels, image->w, image->h, i, i, 0, 1);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
105
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
106 // Create a 75x75 bitmap
30702
9fc9d1e788aa Do not cast the results of malloc/calloc/realloc.
diego
parents: 30416
diff changeset
107 bitmap = malloc(75 * 75 * 4);
22737
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
108
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
109 // Paint bitmap red, 50% transparent and blit at position 50,50
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
110 paint(bitmap, (75*75*4), 255, 0, 0, 128);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
111 blit(fifo, bitmap, 75, 75, 50, 50, 0, 0);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
112
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
113 // Paint bitmap green, 50% transparent and blit at position -50,50
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
114 paint(bitmap, (75*75*4), 0, 255, 0, 128);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
115 blit(fifo, bitmap, 75, 75, width-50-75, 50, 0, 0);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
116
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
117 // Paint bitmap blue, 50% transparent and blit at position -50,50
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
118 paint(bitmap, (75*75*4), 0, 0, 255, 128);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
119 blit(fifo, bitmap, 75, 75, 50, height-50-75, 0, 0);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
120
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
121 // Blit another image in the middle, completly transparent
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
122 blit(fifo, image->pixels, image->w, image->h,
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
123 (width/2)-(image->w/2), (height/2)-(image->h/2), -255, 0);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
124
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
125 // Fade in image
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
126 for(i=-255; i <= 0; i++)
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
127 set_alpha(fifo, image->w, image->h,
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
128 (width/2)-(image->w/2), (height/2)-(image->h/2), i);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 23700
diff changeset
129
22737
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
130
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
131 // Clean up
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
132 free(bitmap);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
133 SDL_FreeSurface(image);
22740
9128aa26244a Add return 0 to fix the following warning:
diego
parents: 22739
diff changeset
134
9128aa26244a Add return 0 to fix the following warning:
diego
parents: 22739
diff changeset
135 return 0;
22737
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
136 }