annotate libvo/spuenc.c @ 15327:8e21844c8a4c

enable rootwin
author nplourde
date Mon, 02 May 2005 18:05:59 +0000
parents c4434bdf6e51
children 401b440a6d76
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 /*
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
2 * subpic_encode.c - encodes a pixmap with RLE
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 *
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
13 * 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
14 * 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
15 * (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
16 *
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
18 * 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
19 * 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
20 * 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
21 *
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
25 *
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
26 */
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 #include <stdio.h>
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
29 #include <stdlib.h>
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
30 #include "unistd.h"
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
31 #include "spuenc.h"
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
32
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
33 static void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
34 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
35 int controlstart= ed->count;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
36 int x1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
37 int i;
6855
fb56a6c15dca fix silly shorthand that could cause trouble porting
rfelker
parents: 5491
diff changeset
38 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
39
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
40 top= 450 - pb->y/2;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
41 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
42 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
43 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
44 //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
45 bottom= top + pb->y - 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
46 right= left + pb->x - 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
47
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
48 /* 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
49 * 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
50 *
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
51 * 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
52 * 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
53 * 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
54 * 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
55 * stay on when using mplayer).
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
56 * 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
57 * new one.
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
58 * 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
59 * the durration/delay feature.
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
60 * */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
61 /* start at x0+2*/
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
62 i= controlstart;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
63 /* display duration... */
5491
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
64 // ed->data[i++]= 0x00;
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
65 // 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
66 //in 90000/1024 units
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
67
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
68 /* x1 */
5491
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
69 // x1=i+4;
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
70 // ed->data[i++]= x1 >> 8;//location of next command block
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
71 // 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
72 /* finish it */
5491
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
73 // ed->data[i++]= 0x02;//turn off command
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
74 // 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
75 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
76
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
77 /* display duration... */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
78 ed->data[i++]= 0x00;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
79 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
80 //in 90000/1024 units
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
81 /* x1 */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
82 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
83 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
84
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 /* 0x01: start displaying */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
87 ed->data[i++]= 0x01;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
88
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
89 /* 0x03: palette info */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
90 ed->data[i++]= 0x03;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
91 ed->data[i++]= 0x08;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
92 ed->data[i++]= 0x7f;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
93 /*
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
94 * 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
95 * (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
96 * 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
97 * 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
98 * */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
99 /* 0x04: transparency info (reversed) */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
100 ed->data[i++]= 0x04;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
101 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
102 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
103 //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
104 //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
105 // 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
106
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
107 /* 0x05: coordinates */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
108 ed->data[i++]= 0x05;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
109 ed->data[i++]= left >> 4;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
110 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
111 ed->data[i++]= (right&0xff);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
112 ed->data[i++]= top >> 4;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
113 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
114 ed->data[i++]= (bottom&0xff);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
115
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
116 /* 0x06: both fields' offsets */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
117 ed->data[i++]= 0x06;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
118 ed->data[i++]= 0x00;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
119 ed->data[i++]= 0x04;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
120 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
121 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
122
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
123 /* 0xFF: end sequence */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
124 ed->data[i++]= 0xFF;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
125 if(! i&1 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
126 ed->data[i++]= 0xff;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
127 }
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 /* x0 */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
130 ed->data[2]= (controlstart) >> 8;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
131 ed->data[3]= (controlstart) & 0xff;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
132
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
133 /* packet size */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
134 ed->data[0]= i >> 8;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
135 ed->data[1]= i & 0xff;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
136
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
137 ed->count= i;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
138 }
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 static void
6855
fb56a6c15dca fix silly shorthand that could cause trouble porting
rfelker
parents: 5491
diff changeset
141 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
142 if( ed->nibblewaiting ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
143 ed->data[ed->count++]|= nibble;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
144 ed->nibblewaiting= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
145 } else {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
146 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
147 ed->nibblewaiting= 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
148 }
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 static void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
152 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
153 if(number > 3) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
154 if(number > 15) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
155 encode_put_nibble( ed, 0 );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
156 if(number > 63) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
157 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
158 }
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 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
161 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
162 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
163 }
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 static void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
166 encode_eol( encodedata* ed ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
167 if( ed->nibblewaiting ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
168 ed->count++;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
169 ed->nibblewaiting= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
170 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
171 ed->data[ed->count++]= 0x00;
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 }
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 static void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
176 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
177 int i= 0;
6855
fb56a6c15dca fix silly shorthand that could cause trouble porting
rfelker
parents: 5491
diff changeset
178 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
179 int color= *pix;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
180 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
181
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
182 while( i++ < pb->x ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
183 /* 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
184 if( *pix != color || n == 255 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
185 encode_pixels( ed, color, n );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
186 color= *pix;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
187 n= 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
188 } else {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
189 n++;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
190 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
191 pix++;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
192 }
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 /* 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
195 * 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
196 if( color == 0 && n > 63 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
197 encode_eol( ed );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
198 } else {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
199 encode_pixels( ed, color, n );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
200 }
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 if( ed->nibblewaiting ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
203 ed->count++;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
204 ed->nibblewaiting= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
205 }
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 void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
210 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
211 pixbuf pb;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
212 int i, row;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
213 pb.x = w;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
214 pb.y = h;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
215
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
216 pb.pixels = inbuf;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
217 ed->count= 4;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
218 ed->nibblewaiting= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
219
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
220 row= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
221 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
222 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
223 row+= 2;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
224 if( row > pb.y ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
225 row= 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
226 ed->oddstart= ed->count;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
227 }
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 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
230 }
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 void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
234 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
235 int colors, chrs, l, n;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
236 char c[4], table[256];
6855
fb56a6c15dca fix silly shorthand that could cause trouble porting
rfelker
parents: 5491
diff changeset
237 unsigned char *b, *i;
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
238
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
239 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
240 if( colors > 4 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
241 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
242 exit (-1);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
243 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
244 if( chrs != 1 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
245 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
246 exit (-1);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
247 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
248 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
249 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
250 exit (-1);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
251 }
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 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
254 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
255 if( n < 2 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
256 /* this one is transparent */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
257 pb->rgb[l]=0xff000000;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
258 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
259 table[(int)c[l]]=l;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
260 }
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 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
263 b= pb->pixels;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
264
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
265 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
266 i= xpm[l];
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
267 while( (int)*i) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
268 *b++ = table[*i++];
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
269 }
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 void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
274 pixbuf_delete( pixbuf* pb ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
275 free( pb->pixels );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
276 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
277