#define EXT_START_CODE 0x000001b5
#define USER_START_CODE 0x000001b2
+#define ABS(a) ((a)<0 ? -(a) : (a))
+
static void mpeg1_encode_block(MpegEncContext *s,
DCTELEM *block,
int component);
mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i];
mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i];
}
+
+ /* build unified dc encoding tables */
+ for(i=-255; i<256; i++)
+ {
+ int adiff, index;
+ int bits, code;
+ int diff=i;
+
+ adiff = ABS(diff);
+ if(diff<0) diff--;
+ index = vlc_dc_table[adiff];
+
+ bits= vlc_dc_lum_bits[index] + index;
+ code= (vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1));
+ mpeg1_lum_dc_uni[i+255]= bits + (code<<8);
+
+ bits= vlc_dc_chroma_bits[index] + index;
+ code= (vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1));
+ mpeg1_chr_dc_uni[i+255]= bits + (code<<8);
+ }
}
mpeg1_encode_sequence_header(s);
static inline void encode_dc(MpegEncContext *s, int diff, int component)
{
- int adiff, index;
-
- adiff = abs(diff);
- index = vlc_dc_table[adiff];
if (component == 0) {
- put_bits(&s->pb, vlc_dc_lum_bits[index], vlc_dc_lum_code[index]);
+ put_bits(
+ &s->pb,
+ mpeg1_lum_dc_uni[diff+255]&0xFF,
+ mpeg1_lum_dc_uni[diff+255]>>8);
} else {
- put_bits(&s->pb, vlc_dc_chroma_bits[index], vlc_dc_chroma_code[index]);
- }
- if (diff > 0) {
- put_bits(&s->pb, index, (diff & ((1 << index) - 1)));
- } else if (diff < 0) {
- put_bits(&s->pb, index, ((diff - 1) & ((1 << index) - 1)));
+ put_bits(
+ &s->pb,
+ mpeg1_chr_dc_uni[diff+255]&0xFF,
+ mpeg1_chr_dc_uni[diff+255]>>8);
}
}
2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10,
};
+/* simple include everything table for dc, first byte is bits number next 3 are code*/
+static UINT32 mpeg1_lum_dc_uni[512];
+static UINT32 mpeg1_chr_dc_uni[512];
+
static const UINT16 mpeg1_vlc[113][2] = {
{ 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 }, { 0x6, 7 },
{ 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 }, { 0x1d, 12 },