annotate sub/spuenc.c @ 36367:28d7bd8adf23

add binary geovision avc codec
author compn
date Fri, 11 Oct 2013 11:42:34 +0000
parents 139876e79725
children
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)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
7 *
5467
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
30561
84d86f175613 Move struct typedef pixbuf into the only .c file where it is used.
reimar
parents: 30559
diff changeset
34 typedef struct {
84d86f175613 Move struct typedef pixbuf into the only .c file where it is used.
reimar
parents: 30559
diff changeset
35 int x, y;
84d86f175613 Move struct typedef pixbuf into the only .c file where it is used.
reimar
parents: 30559
diff changeset
36 unsigned int rgb[4];
84d86f175613 Move struct typedef pixbuf into the only .c file where it is used.
reimar
parents: 30559
diff changeset
37 unsigned char* pixels;
84d86f175613 Move struct typedef pixbuf into the only .c file where it is used.
reimar
parents: 30559
diff changeset
38 } pixbuf;
84d86f175613 Move struct typedef pixbuf into the only .c file where it is used.
reimar
parents: 30559
diff changeset
39
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
40 static void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
41 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
42 int controlstart= ed->count;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
43 int x1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
44 int i;
6855
fb56a6c15dca fix silly shorthand that could cause trouble porting
rfelker
parents: 5491
diff changeset
45 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
46
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
47 top= 450 - pb->y/2;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
48 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
49 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
50 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
51 //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
52 bottom= top + pb->y - 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
53 right= left + pb->x - 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
54
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
55 /* 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
56 * http://members.aol.com/mpucoder/DVD/spu.html
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
57 *
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
58 * note I changed the layout of commands to turn off the subpic as the
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
59 * first command, and then turn on the new subpic...this is so we can
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
60 * leave the subpic on for an arbitrary ammount of time as controlled by
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
61 * 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
62 * stay on when using mplayer).
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
63 * with this layout we turn off the last subpic as we are turning on the
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
64 * new one.
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
65 * 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
66 * the durration/delay feature.
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 /* start at x0+2*/
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
69 i= controlstart;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
70 /* display duration... */
5491
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
71 // ed->data[i++]= 0x00;
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
72 // 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
73 //in 90000/1024 units
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
74
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
75 /* x1 */
5491
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
76 // x1=i+4;
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
77 // ed->data[i++]= x1 >> 8;//location of next command block
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
78 // 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
79 /* finish it */
5491
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
80 // ed->data[i++]= 0x02;//turn off command
846285e8e0b4 Removed blinking effect from spuenc
mswitch
parents: 5467
diff changeset
81 // ed->data[i++]= 0xff;//end of command block
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
82 x1= i; //marker for last command block address
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
83
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
84 /* display duration... */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
85 ed->data[i++]= 0x00;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
86 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
87 //in 90000/1024 units
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
88 /* x1 */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
89 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
90 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
91
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
92
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
93 /* 0x01: start displaying */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
94 ed->data[i++]= 0x01;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
95
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
96 /* 0x03: palette info */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
97 ed->data[i++]= 0x03;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
98 ed->data[i++]= 0x08;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
99 ed->data[i++]= 0x7f;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
100 /*
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
101 * The palette is a coded index (one of 16) 0 is black, 0xf is white
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
102 * (unless you screw with the default palette)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
103 * for what I am doing I only use white.
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
104 * 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
105 * */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
106 /* 0x04: transparency info (reversed) */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
107 ed->data[i++]= 0x04;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
108 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
109 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
110 //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
111 //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
112 // 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
113
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
114 /* 0x05: coordinates */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
115 ed->data[i++]= 0x05;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
116 ed->data[i++]= left >> 4;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
117 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
118 ed->data[i++]= (right&0xff);
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
119 ed->data[i++]= top >> 4;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
120 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
121 ed->data[i++]= (bottom&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 /* 0x06: both fields' offsets */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
124 ed->data[i++]= 0x06;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
125 ed->data[i++]= 0x00;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
126 ed->data[i++]= 0x04;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
127 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
128 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
129
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
130 /* 0xFF: end sequence */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
131 ed->data[i++]= 0xFF;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
132 if(! i&1 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
133 ed->data[i++]= 0xff;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
134 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
135
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
136 /* x0 */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
137 ed->data[2]= (controlstart) >> 8;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
138 ed->data[3]= (controlstart) & 0xff;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
139
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
140 /* packet size */
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
141 ed->data[0]= i >> 8;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
142 ed->data[1]= i & 0xff;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
143
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
144 ed->count= i;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
145 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
146
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
147 static void
6855
fb56a6c15dca fix silly shorthand that could cause trouble porting
rfelker
parents: 5491
diff changeset
148 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
149 if( ed->nibblewaiting ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
150 ed->data[ed->count++]|= nibble;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
151 ed->nibblewaiting= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
152 } else {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
153 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
154 ed->nibblewaiting= 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
155 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
156 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
157
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
158 static void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
159 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
160 if(number > 3) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
161 if(number > 15) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
162 encode_put_nibble( ed, 0 );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
163 if(number > 63) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
164 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
165 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
166 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
167 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
168 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
169 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
170 }
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 static void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
173 encode_eol( encodedata* ed ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
174 if( ed->nibblewaiting ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
175 ed->count++;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
176 ed->nibblewaiting= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
177 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
178 ed->data[ed->count++]= 0x00;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
179 ed->data[ed->count++]= 0x00;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
180 }
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 static void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
183 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
184 int i= 0;
6855
fb56a6c15dca fix silly shorthand that could cause trouble porting
rfelker
parents: 5491
diff changeset
185 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
186 int color= *pix;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
187 int n= 0; /* the number of pixels of this color */
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28924
diff changeset
188
5467
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
189 while( i++ < pb->x ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
190 /* 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
191 if( *pix != color || n == 255 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
192 encode_pixels( ed, color, n );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
193 color= *pix;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
194 n= 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
195 } else {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
196 n++;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
197 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
198 pix++;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
199 }
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 /* 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
202 * 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
203 if( color == 0 && n > 63 ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
204 encode_eol( ed );
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
205 } else {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
206 encode_pixels( ed, color, n );
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 if( ed->nibblewaiting ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
210 ed->count++;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
211 ed->nibblewaiting= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
212 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
213 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
214
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 void
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
217 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
218 pixbuf pb;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
219 int i, row;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
220 pb.x = w;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
221 pb.y = h;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
222
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
223 pb.pixels = inbuf;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
224 ed->count= 4;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
225 ed->nibblewaiting= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
226
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
227 row= 0;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
228 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
229 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
230 row+= 2;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
231 if( row > pb.y ) {
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
232 row= 1;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
233 ed->oddstart= ed->count;
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
234 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
235 }
7c2afd5b5163 Subpic encoder added (used on DXR3 and similar hardware that has a subpic channel)
mswitch
parents:
diff changeset
236 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
237 }