annotate libvo/spuenc.c @ 29245:294522d3c22e

Move preprocessor condition before variable declaration, fixes the warning: libswscale/swscale.c:1795: warning: unused variable 'flags'
author diego
date Sun, 10 May 2009 11:37:04 +0000
parents d5d66bff938a
children 0f1b5b68af32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
1 /*
28924
d5d66bff938a cosmetics: Remove file names from file header, it only causes trouble.
diego
parents: 26739
diff changeset
2 * encode a pixmap with RLE
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
3 *
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
4 * Copyright (C) 2000 Alejandro J. Cura <alecu@protocultura.net>
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
5 *
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
6 * (modified a bit to work with the dxr3 driver...4/2/2002 cg)
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
7 *
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
8 * Based on the hard work of:
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
9 *
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
10 * Samuel Hocevar <sam@via.ecp.fr> and Michel Lespinasse <walken@via.ecp.fr>
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
11 *
26739
2a34d9fa52ab Use standard license headers with standard formatting.
diego
parents: 17367
diff changeset
12 * This file is part of MPlayer.
2a34d9fa52ab Use standard license headers with standard formatting.
diego
parents: 17367
diff changeset
13 *
2a34d9fa52ab Use standard license headers with standard formatting.
diego
parents: 17367
diff changeset
14 * MPlayer is free software; you can redistribute it and/or modify
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
15 * it under the terms of the GNU General Public License as published by
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
16 * the Free Software Foundation; either version 2 of the License, or
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
17 * (at your option) any later version.
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
18 *
26739
2a34d9fa52ab Use standard license headers with standard formatting.
diego
parents: 17367
diff changeset
19 * MPlayer is distributed in the hope that it will be useful,
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
22 * GNU General Public License for more details.
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
23 *
26739
2a34d9fa52ab Use standard license headers with standard formatting.
diego
parents: 17367
diff changeset
24 * You should have received a copy of the GNU General Public License along
2a34d9fa52ab Use standard license headers with standard formatting.
diego
parents: 17367
diff changeset
25 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
2a34d9fa52ab Use standard license headers with standard formatting.
diego
parents: 17367
diff changeset
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
27 */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
28
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
29 #include <stdio.h>
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
30 #include <stdlib.h>
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
31 #include "unistd.h"
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
32 #include "spuenc.h"
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
33
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
34 static void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
35 encode_do_control(int x,int y, encodedata* ed, pixbuf* pb) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
36 int controlstart= ed->count;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
37 int x1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
38 int i;
6855
fb56a6c15dca fix silly shorthand that could cause trouble porting
rfelker
parents: 5491
diff changeset
39 unsigned int top, left, bottom, right;
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
40
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
41 top= 450 - pb->y/2;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
42 left=(720 / 2) - (pb->x / 2);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
43 top= 32;//this forces the first bit to be visible on a TV
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
44 left= 32;//you could actually pass in x/y and do some nice
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
45 //calculations for making it look right...
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
46 bottom= top + pb->y - 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
47 right= left + pb->x - 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
48
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
49 /* the format of this is well described by a page:
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
50 * http://members.aol.com/mpucoder/DVD/spu.html
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
51 *
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
52 * note I changed the layout of commands to turn off the subpic as the
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
53 * first command, and then turn on the new subpic...this is so we can
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
54 * leave the subpic on for an arbitrary ammount of time as controlled by
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
55 * mplayer (ie when we turn on the subpic we don't know how long it should
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
56 * stay on when using mplayer).
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
57 * with this layout we turn off the last subpic as we are turning on the
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
58 * new one.
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
59 * The original hd it turn on the subpic, and delay the turn off command using
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
60 * the durration/delay feature.
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
61 * */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
62 /* start at x0+2*/
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
63 i= controlstart;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
64 /* display duration... */
5491
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
65 // ed->data[i++]= 0x00;
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
66 // ed->data[i++]= 0x00; //durration before turn off command occurs
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
67 //in 90000/1024 units
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
68
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
69 /* x1 */
5491
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
70 // x1=i+4;
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
71 // ed->data[i++]= x1 >> 8;//location of next command block
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
72 // ed->data[i++]= x1 & 0xff;
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
73 /* finish it */
5491
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
74 // ed->data[i++]= 0x02;//turn off command
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
75 // ed->data[i++]= 0xff;//end of command block
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
76 x1= i; //marker for last command block address
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
77
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
78 /* display duration... */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
79 ed->data[i++]= 0x00;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
80 ed->data[i++]= 0x00; //durration before turn on command occurs
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
81 //in 90000/1024 units
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
82 /* x1 */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
83 ed->data[i++]= x1 >> 8; //since this is the last command block, this
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
84 ed->data[i++]= x1 & 0xff;//points back to itself
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
85
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
86
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
87 /* 0x01: start displaying */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
88 ed->data[i++]= 0x01;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
89
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
90 /* 0x03: palette info */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
91 ed->data[i++]= 0x03;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
92 ed->data[i++]= 0x08;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
93 ed->data[i++]= 0x7f;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
94 /*
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
95 * The palette is a coded index (one of 16) 0 is black, 0xf is white
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
96 * (unless you screw with the default palette)
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
97 * for what I am doing I only use white.
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
98 * 7 is lt grey, and 8 is dk grey...
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
99 * */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
100 /* 0x04: transparency info (reversed) */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
101 ed->data[i++]= 0x04;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
102 ed->data[i++]= 0xFF;//change the opacity values of the color entries
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
103 ed->data[i++]= 0xF0;//say if you wanted white text on a black backround
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
104 //note you will have to work harder, by finding the
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
105 //bounding box of the text, and use a non transparent black palette
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
106 // entry to fill the backround with, (say color 1 instead of 0)
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
107
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
108 /* 0x05: coordinates */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
109 ed->data[i++]= 0x05;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
110 ed->data[i++]= left >> 4;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
111 ed->data[i++]= ((left&0xf)<<4)+(right>>8);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
112 ed->data[i++]= (right&0xff);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
113 ed->data[i++]= top >> 4;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
114 ed->data[i++]= ((top&0xf)<<4)+(bottom>>8);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
115 ed->data[i++]= (bottom&0xff);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
116
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
117 /* 0x06: both fields' offsets */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
118 ed->data[i++]= 0x06;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
119 ed->data[i++]= 0x00;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
120 ed->data[i++]= 0x04;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
121 ed->data[i++]= ed->oddstart >> 8;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
122 ed->data[i++]= ed->oddstart & 0xff;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
123
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
124 /* 0xFF: end sequence */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
125 ed->data[i++]= 0xFF;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
126 if(! i&1 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
127 ed->data[i++]= 0xff;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
128 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
129
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
130 /* x0 */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
131 ed->data[2]= (controlstart) >> 8;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
132 ed->data[3]= (controlstart) & 0xff;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
133
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
134 /* packet size */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
135 ed->data[0]= i >> 8;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
136 ed->data[1]= i & 0xff;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
137
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
138 ed->count= i;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
139 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
140
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
141 static void
6855
fb56a6c15dca fix silly shorthand that could cause trouble porting
rfelker
parents: 5491
diff changeset
142 encode_put_nibble( encodedata* ed, unsigned char nibble ) {
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
143 if( ed->nibblewaiting ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
144 ed->data[ed->count++]|= nibble;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
145 ed->nibblewaiting= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
146 } else {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
147 ed->data[ed->count]= nibble<<4;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
148 ed->nibblewaiting= 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
149 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
150 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
151
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
152 static void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
153 encode_pixels( encodedata* ed, int color, int number ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
154 if(number > 3) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
155 if(number > 15) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
156 encode_put_nibble( ed, 0 );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
157 if(number > 63) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
158 encode_put_nibble( ed, (number & 0xC0)>>6 );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
159 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
160 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
161 encode_put_nibble( ed, (number & 0x3C)>>2 );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
162 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
163 encode_put_nibble( ed, ((number & 0xF)<<2) | color);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
164 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
165
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
166 static void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
167 encode_eol( encodedata* ed ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
168 if( ed->nibblewaiting ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
169 ed->count++;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
170 ed->nibblewaiting= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
171 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
172 ed->data[ed->count++]= 0x00;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
173 ed->data[ed->count++]= 0x00;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
174 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
175
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
176 static void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
177 encode_do_row( encodedata* ed, pixbuf* pb, int row ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
178 int i= 0;
6855
fb56a6c15dca fix silly shorthand that could cause trouble porting
rfelker
parents: 5491
diff changeset
179 unsigned char* pix= pb->pixels + row * pb->x;
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
180 int color= *pix;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
181 int n= 0; /* the number of pixels of this color */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
182
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
183 while( i++ < pb->x ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
184 /* FIXME: watch this space for EOL */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
185 if( *pix != color || n == 255 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
186 encode_pixels( ed, color, n );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
187 color= *pix;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
188 n= 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
189 } else {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
190 n++;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
191 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
192 pix++;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
193 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
194
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
195 /* this small optimization: (n>63) can save up to two bytes per line
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
196 * I wonder if this is compatible with all the hardware... */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
197 if( color == 0 && n > 63 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
198 encode_eol( ed );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
199 } else {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
200 encode_pixels( ed, color, n );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
201 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
202
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
203 if( ed->nibblewaiting ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
204 ed->count++;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
205 ed->nibblewaiting= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
206 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
207 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
208
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
209
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
210 void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
211 pixbuf_encode_rle(int x, int y, int w, int h, char *inbuf, int stride,encodedata *ed){
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
212 pixbuf pb;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
213 int i, row;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
214 pb.x = w;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
215 pb.y = h;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
216
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
217 pb.pixels = inbuf;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
218 ed->count= 4;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
219 ed->nibblewaiting= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
220
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
221 row= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
222 for( i= 0; i < pb.y; i++ ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
223 encode_do_row(ed, &pb, row);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
224 row+= 2;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
225 if( row > pb.y ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
226 row= 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
227 ed->oddstart= ed->count;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
228 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
229 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
230 encode_do_control(x,y, ed, &pb);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
231 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
232
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
233
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
234 void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
235 pixbuf_load_xpm( pixbuf* pb, char* xpm[] ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
236 int colors, chrs, l, n;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
237 char c[4], table[256];
6855
fb56a6c15dca fix silly shorthand that could cause trouble porting
rfelker
parents: 5491
diff changeset
238 unsigned char *b, *i;
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
239
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
240 sscanf( xpm[0], "%d %d %d %d", &pb->x, &pb->y, &colors, &chrs);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
241 if( colors > 4 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
242 fprintf( stderr, "the pixmap MUST be 4 colors or less\n");
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
243 exit (-1);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
244 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
245 if( chrs != 1 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
246 fprintf( stderr, "the XPM format MUST be 1 char per pixel\n");
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
247 exit (-1);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
248 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
249 if( pb->x > 0xFFF || pb->y > 0xFFF ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
250 fprintf( stderr, "the size is excesive\n");
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
251 exit (-1);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
252 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
253
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
254 for( l=0; l<colors; l++ ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
255 n= sscanf( xpm[l+1], "%c c #%x", &c[l], &pb->rgb[l]);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
256 if( n < 2 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
257 /* this one is transparent */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
258 pb->rgb[l]=0xff000000;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
259 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
260 table[(int)c[l]]=l;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
261 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
262
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
263 pb->pixels= malloc( pb->x * pb->y );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
264 b= pb->pixels;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
265
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
266 for( l= colors+1; l <= pb->y + colors; l++ ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
267 i= xpm[l];
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
268 while( (int)*i) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
269 *b++ = table[*i++];
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
270 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
271 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
272 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
273
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
274 void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
275 pixbuf_delete( pixbuf* pb ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
276 free( pb->pixels );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
277 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
278