Skip to content

Commit 85fff8f

Browse files
committed
removed old scraps of code
git-svn-id: svn://svn.icculus.org/twilight/trunk/dpvideo@2075 d7cf8633-e32d-0410-b094-e92efae38249
1 parent a08f25f commit 85fff8f

File tree

1 file changed

+33
-286
lines changed

1 file changed

+33
-286
lines changed

dpvdecode.c

+33-286
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,11 @@ typedef struct dpvdecodestream_s
4242

4343
int error;
4444

45-
// table of sound delta values
46-
//int soundtable[64];
47-
4845
double info_framerate;
49-
//unsigned int info_samplespersecond;
50-
//unsigned int info_samplesperframe;
5146
unsigned int info_frames;
5247

5348
unsigned int info_imagewidth;
5449
unsigned int info_imageheight;
55-
// unsigned int info_imageblocksize;
5650
unsigned int info_imagebpp;
5751
unsigned int info_imageRloss;
5852
unsigned int info_imageRmask;
@@ -64,28 +58,14 @@ typedef struct dpvdecodestream_s
6458
unsigned int info_imageBmask;
6559
unsigned int info_imageBshift;
6660
unsigned int info_imagesize;
67-
//unsigned int info_neededsoundbufferlength;
6861

6962
// current video frame (needed because of delta compression)
7063
int videoframenum;
7164
// current video frame data (needed because of delta compression)
7265
unsigned int *videopixels;
7366

74-
//hzhuffmanreadtree_t *audiohuffmantree;
75-
7667
// wav file the sound is being read from
7768
wavefile_t *wavefile;
78-
79-
/*
80-
// how much sound data the buffer can hold (will be reallocated if too small)
81-
unsigned int soundbuffermax;
82-
// how full the sound buffer should be kept
83-
unsigned int soundbufferpreferred;
84-
// how full the sound buffer currently is
85-
unsigned int soundlength;
86-
// the sound buffer itself
87-
short *sounddata;
88-
*/
8969
}
9070
dpvdecodestream_t;
9171

@@ -156,196 +136,7 @@ static int dpvdecode_realseektoframe(dpvdecodestream_t *s, int framenum)
156136
return dpvdecode_seektoposition(s, seekentry->position);
157137
}
158138

159-
/*
160-
static int dpvdecode_decompressaudio(dpvdecodestream_t *s, short *sounddata, int framesoundlength)
161-
{
162-
int mono, left, cleft, cright;
163-
short *out, *end;
164-
if (s->error)
165-
return s->error;
166-
if (hz_huffman_read_readtree(s->framedatablocks, s->audiohuffmantree))
167-
{
168-
s->error = DPVDECODEERROR_READERROR;
169-
return s->error;
170-
}
171-
out = sounddata;
172-
end = out + framesoundlength * 2;
173-
mono = 0;
174-
left = 0;
175-
while(out < end)
176-
{
177-
mono += s->soundtable[hz_huffman_read_readsymbol(s->framedatablocks, s->audiohuffmantree)];
178-
left += s->soundtable[hz_huffman_read_readsymbol(s->framedatablocks, s->audiohuffmantree)];
179-
cright = mono - left;
180-
cleft = mono + left;
181-
if (cleft < -32768 || cleft > 32767 || cright < -32768 || cright > 32767)
182-
{
183-
s->error = DPVDECODEERROR_READERROR;
184-
return s->error;
185-
}
186-
*out++ = cleft;
187-
*out++ = cright;
188-
}
189-
return s->error;
190-
}
191-
*/
192-
193-
/*
194-
static int dpvdecode_decompressimage(dpvdecodestream_t *s, void *imagedata, int imagebytesperrow)
195-
{
196-
int i, a, b, colors, g, x1, y1, bw, bh, width, height, palettebits, imagepixelsperrow;
197-
unsigned int Rloss, Rmask, Rshift, Gloss, Gmask, Gshift, Bloss, Bmask, Bshift;
198-
// g = s->info_imageblocksize;
199-
g = BLOCKSIZE;
200-
width = s->info_imagewidth;
201-
height = s->info_imageheight;
202-
Rloss = s->info_imageRloss;
203-
Rmask = s->info_imageRmask;
204-
Rshift = s->info_imageRshift;
205-
Gloss = s->info_imageGloss;
206-
Gmask = s->info_imageGmask;
207-
Gshift = s->info_imageGshift;
208-
Bloss = s->info_imageBloss;
209-
Bmask = s->info_imageBmask;
210-
Bshift = s->info_imageBshift;
211-
if (s->info_imagebpp == 4)
212-
{
213-
unsigned int palette[256], *outpixels, *outrow, *out;
214-
imagepixelsperrow = imagebytesperrow >> 2;
215-
outpixels = imagedata;
216-
for (y1 = 0;y1 < height;y1 += g)
217-
{
218-
outrow = outpixels + y1 * imagepixelsperrow;
219-
bh = g;
220-
if (y1 + bh > height)
221-
bh = height - y1;
222-
for (x1 = 0;x1 < width;x1 += g)
223-
{
224-
out = outrow + x1;
225-
bw = g;
226-
if (x1 + bw > width)
227-
bw = width - x1;
228-
palettebits = hz_bitstream_read_bits(s->framedatablocks, 3);
229-
colors = 1 << palettebits;
230-
for (i = 0;i < colors;i++)
231-
{
232-
a = hz_bitstream_read_bits(s->framedatablocks, 16);
233-
palette[i] = (((a >> Rloss) & Rmask) << Rshift) | (((a >> Gloss) & Gmask) << Gshift) | (((a >> Bloss) & Bmask) << Bshift);
234-
}
235-
if (palettebits)
236-
{
237-
for (b = 0;b < bh;b++, out += imagepixelsperrow)
238-
for (a = 0;a < bw;a++)
239-
out[a] = palette[hz_bitstream_read_bits(s->framedatablocks, palettebits)];
240-
}
241-
else
242-
{
243-
for (b = 0;b < bh;b++, out += imagepixelsperrow)
244-
for (a = 0;a < bw;a++)
245-
out[a] = palette[0];
246-
}
247-
}
248-
}
249-
}
250-
else
251-
{
252-
// 2 bytes per pixel
253-
unsigned short palette[256], *outpixels, *outrow, *out;
254-
imagepixelsperrow = imagebytesperrow >> 1;
255-
outpixels = imagedata;
256-
for (y1 = 0;y1 < height;y1 += g)
257-
{
258-
outrow = outpixels + y1 * imagepixelsperrow;
259-
bh = g;
260-
if (y1 + bh > height)
261-
bh = height - y1;
262-
for (x1 = 0;x1 < width;x1 += g)
263-
{
264-
out = outrow + x1;
265-
bw = g;
266-
if (x1 + bw > width)
267-
bw = width - x1;
268-
palettebits = hz_bitstream_read_bits(s->framedatablocks, 3);
269-
colors = 1 << palettebits;
270-
for (i = 0;i < colors;i++)
271-
{
272-
a = hz_bitstream_read_bits(s->framedatablocks, 16);
273-
palette[i] = (((a >> Rloss) & Rmask) << Rshift) | (((a >> Gloss) & Gmask) << Gshift) | (((a >> Bloss) & Bmask) << Bshift);
274-
}
275-
if (palettebits)
276-
{
277-
for (b = 0;b < bh;b++, out += imagepixelsperrow)
278-
for (a = 0;a < bw;a++)
279-
out[a] = palette[hz_bitstream_read_bits(s->framedatablocks, palettebits)];
280-
}
281-
else
282-
{
283-
for (b = 0;b < bh;b++, out += imagepixelsperrow)
284-
for (a = 0;a < bw;a++)
285-
out[a] = palette[0];
286-
}
287-
}
288-
}
289-
}
290-
return s->error;
291-
}
292-
*/
293-
294-
/*
295-
// decompress a frame at current position in bitstream
296-
static int dpvdecode_decodevideoframe(dpvdecodestream_t *s, int newframenum, void *imagedata, int imagebytesperrow)
297-
{
298-
unsigned int framedatasize, framesoundlength;
299-
char t[4];
300-
if (dpvdecode_realseektoframe(s, newframenum))
301-
return s->error;
302-
303-
s->error = DPVDECODEERROR_NONE;
304-
hz_bitstream_read_blocks_read(s->framedatablocks, s->bitstream, 8);
305-
hz_bitstream_read_bytes(s->framedatablocks, t, 4);
306-
if (t[0] != 'D' || t[1] != 'P' || t[2] != 'V' || t[3] != '0')
307-
{
308-
s->error = DPVDECODEERROR_READERROR;
309-
return s->error;
310-
}
311-
framedatasize = hz_bitstream_read_int(s->framedatablocks);
312-
hz_bitstream_read_blocks_read(s->framedatablocks, s->bitstream, framedatasize);
313-
return dpvdecode_decompressimage(s, imagedata, imagebytesperrow);
314-
}
315-
*/
316-
317-
/*
318-
static int dpvdecode_decodeaudioframe(dpvdecodestream_t *s, int newframenum, void *imagedata, int imagebytesperrow, void *sounddata, unsigned int soundbufferlength)
319-
{
320-
unsigned int framedatasize, framesoundlength;
321-
char t[4];
322-
if (dpvdecode_realseektoframe(s, newframenum))
323-
return s->error;
324-
s->error = DPVDECODEERROR_NONE;
325-
hz_bitstream_read_blocks_read(s->framedatablocks, s->bitstream, 8);
326-
hz_bitstream_read_bytes(s->framedatablocks, t, 4);
327-
if (t[0] != 'S' || t[1] != 'N' || t[2] != 'D' || t[3] != '0')
328-
{
329-
s->error = DPVDECODEERROR_READERROR;
330-
return s->error;
331-
}
332-
framedatasize = hz_bitstream_read_int(s->framedatablocks);
333-
hz_bitstream_read_blocks_read(s->framedatablocks, s->bitstream, framedatasize);
334-
framesoundlength = hz_bitstream_read_int(s->framedatablocks);
335-
if (framesoundlength > soundbufferlength)
336-
{
337-
s->error = DPVDECODEERROR_SOUNDBUFFERTOOSMALL;
338-
return s->error;
339-
}
340-
341-
if (dpvdecode_decompressimage(s, imagedata, imagebytesperrow))
342-
return s->error;
343-
344-
return dpvdecode_decompressaudio(s, sounddata, framesoundlength);
345-
}
346-
*/
347-
348-
int dpvdecode_setpixelformat(dpvdecodestream_t *s, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel)
139+
static int dpvdecode_setpixelformat(dpvdecodestream_t *s, unsigned int Rmask, unsigned int Gmask, unsigned int Bmask, unsigned int bytesperpixel)
349140
{
350141
int Rshift, Rbits, Gshift, Gbits, Bshift, Bbits;
351142
if (!Rmask)
@@ -451,18 +242,11 @@ static int dpvdecode_buildframeindex(dpvdecodestream_t *s)
451242
length = hz_bitstream_read_int(s->framedatablocks);
452243
if (length < s->info_imagewidth * s->info_imageheight * 4)
453244
{
454-
//l = hz_bitstream_read_int(s->framedatablocks);
455-
//// validate samples count
456-
//if (abs(l - s->info_samplesperframe) < 4)
457-
//{
458-
// probably a valid frame
459-
dpvdecode_addframetoseektable(s, 0, position);
460-
// seek to next frame using length from header
461-
if (hz_bitstream_read_seek(s->bitstream, position + length + 8))
462-
break;
463-
//}
464-
//else
465-
// break;
245+
// probably a valid frame
246+
dpvdecode_addframetoseektable(s, 0, position);
247+
// seek to next frame using length from header
248+
if (hz_bitstream_read_seek(s->bitstream, position + length + 8))
249+
break;
466250
}
467251
else
468252
break;
@@ -487,23 +271,6 @@ static void dpvdecode_freeframeindex(dpvdecodestream_t *s)
487271
}
488272
}
489273

490-
/*
491-
static void dpvdecode_buildsoundtable(dpvdecodestream_t *s)
492-
{
493-
int i, k;
494-
double f;
495-
for (i = 0;i < 64;i++)
496-
{
497-
k = i;
498-
if (k >= 32)
499-
k = 32 - (k - 32);
500-
f = fabs(k * (1.0 / 32.0));
501-
s->soundtable[i] = (int) (pow(f, 2) * 32768.0 * (i >= 32 ? -1.0 : 1.0));
502-
}
503-
}
504-
*/
505-
506-
507274
// opening and closing streams
508275

509276
static void StripExtension(char *in, char *out)
@@ -558,54 +325,42 @@ void *dpvdecode_open(char *filename, char **errorstring)
558325
hz_bitstream_read_blocks_read(s->framedatablocks, s->bitstream, 12);
559326
s->info_imagewidth = hz_bitstream_read_short(s->framedatablocks);
560327
s->info_imageheight = hz_bitstream_read_short(s->framedatablocks);
561-
//s->info_imageblocksize = hz_bitstream_read_short(s->framedatablocks);
562328
s->info_framerate = (double) hz_bitstream_read_int(s->framedatablocks) * (1.0 / 65536.0);
563-
//s->info_samplespersecond = hz_bitstream_read_int(s->framedatablocks);
564-
//s->info_samplesperframe = s->info_samplespersecond / s->info_framerate;
565-
//s->info_neededsoundbufferlength = s->info_samplesperframe + 4;
566329

567-
if (s->info_framerate > 0.0/* && s->info_imageblocksize >= 1 && !(s->info_imageblocksize & (s->info_imageblocksize - 1))*/)
330+
if (s->info_framerate > 0.0)
568331
{
569-
//s->audiohuffmantree = hz_huffman_read_newtree(64);
570-
//if (s->audiohuffmantree != NULL)
571-
//{
572-
// dpvdecode_buildsoundtable(s);
573-
s->videopixels = malloc(s->info_imagewidth * s->info_imageheight * sizeof(*s->videopixels));
574-
if (s->videopixels != NULL)
332+
s->videopixels = malloc(s->info_imagewidth * s->info_imageheight * sizeof(*s->videopixels));
333+
if (s->videopixels != NULL)
334+
{
335+
if (!dpvdecode_buildframeindex(s))
575336
{
576-
if (!dpvdecode_buildframeindex(s))
337+
wavename = malloc(strlen(filename) + 10);
338+
if (wavename)
577339
{
578-
wavename = malloc(strlen(filename) + 10);
579-
if (wavename)
580-
{
581-
StripExtension(filename, wavename);
582-
strcat(wavename, ".wav");
583-
s->wavefile = waveopen(wavename, NULL);
584-
free(wavename);
585-
}
586-
if (!dpvdecode_realseektoframe(s, 0))
587-
{
588-
// all is well...
589-
s->videoframenum = -10000;
590-
return s;
591-
}
592-
else if (errorstring != NULL)
593-
*errorstring = "error seeking to first frame";
594-
// error occurred, close down
595-
if (s->wavefile)
596-
waveclose(s->wavefile);
597-
dpvdecode_freeframeindex(s);
340+
StripExtension(filename, wavename);
341+
strcat(wavename, ".wav");
342+
s->wavefile = waveopen(wavename, NULL);
343+
free(wavename);
344+
}
345+
if (!dpvdecode_realseektoframe(s, 0))
346+
{
347+
// all is well...
348+
s->videoframenum = -10000;
349+
return s;
598350
}
599351
else if (errorstring != NULL)
600-
*errorstring = "error reading frames to build index table";
601-
free(s->videopixels);
352+
*errorstring = "error seeking to first frame";
353+
// error occurred, close down
354+
if (s->wavefile)
355+
waveclose(s->wavefile);
356+
dpvdecode_freeframeindex(s);
602357
}
603358
else if (errorstring != NULL)
604-
*errorstring = "unable to allocate video image buffer";
605-
// hz_huffman_read_freetree(s->audiohuffmantree);
606-
//}
607-
//else if (errorstring != NULL)
608-
// *errorstring = "unable to allocate huffman tree for decoding audio";
359+
*errorstring = "error reading frames to build index table";
360+
free(s->videopixels);
361+
}
362+
else if (errorstring != NULL)
363+
*errorstring = "unable to allocate video image buffer";
609364
}
610365
else if (errorstring != NULL)
611366
*errorstring = "error in video info chunk";
@@ -637,7 +392,6 @@ void dpvdecode_close(void *stream)
637392
if (s == NULL)
638393
return;
639394
dpvdecode_freeframeindex(s);
640-
//hz_huffman_read_freetree(s->audiohuffmantree);
641395
if (s->videopixels)
642396
free(s->videopixels);
643397
if (s->wavefile)
@@ -933,12 +687,5 @@ int dpvdecode_audio(void *stream, int firstsample, short *soundbuffer, int reque
933687
startsamples += samples;
934688
if (startsamples < requestedlength)
935689
memset(soundbuffer + startsamples * 2, 0, (requestedlength - startsamples) * sizeof(short[2]));
936-
937-
//printf("read %i - %i (%i : %i) ", sample1, sample2, sample2 - sample1, samples);
938-
sample2 = 0;
939-
for (sample1 = 0;sample1 < requestedlength * 2;sample1++)
940-
sample2 += soundbuffer[sample1];
941-
//printf("avg: %i\n", sample2 / (requestedlength * 2));
942-
943690
return s->error;
944691
}

0 commit comments

Comments
 (0)