Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

codec37.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2002 Xavier Trochu
00003 
00004 This software is provided 'as-is', without any express or implied warranty. In no event
00005 will the authors be held liable for any damages arising from the use of this software.
00006 
00007 Permission is granted to anyone to use this software for any purpose, including commercial
00008 applications, and to alter it and redistribute it freely, subject to the following
00009 restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you
00012    wrote the original software. If you use this software in a product, an acknowledgment
00013    in the product documentation would be appreciated but is not required.
00014 
00015 2. Altered source versions must be plainly marked as such, and must not be misrepresented 
00016    as being the original software.
00017 
00018 3. This notice may not be removed or altered from any source distribution.
00019 */
00020 #include <stdexcept>
00021 #include <cstring>
00022 #include <sstream>
00023 
00024 #include "codec37.h"
00025 #include "chunck.h"
00026 #include "blitter.h"
00027 
00028 #ifdef DEBUG_CODEC37
00029 #include <iostream>
00030 #endif
00031 
00032 //~ #define USE_COLOR_CODE_FOR_BLOCK
00033 
00034 using namespace std;
00035 
00036 bool codec37_decoder::init_size(const point & p, const rect & r) throw(exception) {
00037     if(r.width() != get_rect().width() && r.height() != get_rect().height()) {
00038         if(
00039             (r.width() != 320 || r.height() != 200) && 
00040             (r.width() != 384 || r.height() != 242) && 
00041             (r.width() != 640 || r.height() != 480)
00042             )
00043             return false;
00044         decoder::init_size(p, r);
00045         clean();
00046         int frame_size = get_rect().width() * get_rect().height();
00047         _deltaSize = frame_size * 2 + DELTA_ADD * 4;
00048         _deltaBuf = new  unsigned char[_deltaSize];
00049         if(_deltaBuf == 0) throw runtime_error("unable to allocate decoder buffer");
00050         _deltaBufs[0] = _deltaBuf + DELTA_ADD;
00051         _deltaBufs[1] = _deltaBuf + frame_size + DELTA_ADD * 3;
00052         _offset_table = new short[255];
00053         if(_offset_table == 0) throw runtime_error("unable to allocate decoder offset table");
00054         _table_last_pitch = -1;
00055         _table_last_index = -1;
00056         return true; 
00057     }
00058     return false;
00059 }
00060 
00061 codec37_decoder::codec37_decoder() throw() {
00062     _deltaSize = 0;
00063     _deltaBuf = 0;
00064     _deltaBufs[0] = 0;
00065     _deltaBufs[1] = 0;
00066     _curtable = 0;
00067     _offset_table = 0;
00068     _table_last_pitch = -1;
00069     _table_last_index = -1;
00070     _prev_seq_nb = 32768; // Some invalid number
00071 }
00072 
00073 void codec37_decoder::clean() throw() {
00074     if(_offset_table) {
00075         delete []_offset_table;
00076         _offset_table = 0;
00077         _table_last_pitch = -1;
00078         _table_last_index = -1;
00079     }
00080     if(_deltaBuf) {
00081         delete []_deltaBuf;
00082         _deltaSize = 0;
00083         _deltaBuf = 0;
00084         _deltaBufs[0] = 0;
00085         _deltaBufs[1] = 0;
00086     }
00087 }
00088 
00089 codec37_decoder::~codec37_decoder() throw() {
00090     clean();
00091 }
00092 
00093 void codec37_decoder::maketable(int pitch, int index) {
00094     static const char maketable_bytes[] = {
00095         0, 0, 1, 0, 2, 0, 3, 0, 5, 0, 8, 0, 13, 0, 21, 0,
00096         -1, 0, -2, 0, -3, 0, -5, 0, -8, 0, -13, 0, -17, 0, -21, 0,
00097         0, 1, 1, 1, 2, 1, 3, 1, 5, 1, 8, 1, 13, 1, 21, 1,
00098         -1, 1, -2, 1, -3, 1, -5, 1, -8, 1, -13, 1, -17, 1, -21, 1,
00099         0, 2, 1, 2, 2, 2, 3, 2, 5, 2, 8, 2, 13, 2, 21, 2,
00100         -1, 2, -2, 2, -3, 2, -5, 2, -8, 2, -13, 2, -17, 2, -21, 2,
00101         0, 3, 1, 3, 2, 3, 3, 3, 5, 3, 8, 3, 13, 3, 21, 3,
00102         -1, 3, -2, 3, -3, 3, -5, 3, -8, 3, -13, 3, -17, 3, -21, 3,
00103         0, 5, 1, 5, 2, 5, 3, 5, 5, 5, 8, 5, 13, 5, 21, 5,
00104         -1, 5, -2, 5, -3, 5, -5, 5, -8, 5, -13, 5, -17, 5, -21, 5,
00105         0, 8, 1, 8, 2, 8, 3, 8, 5, 8, 8, 8, 13, 8, 21, 8,
00106         -1, 8, -2, 8, -3, 8, -5, 8, -8, 8, -13, 8, -17, 8, -21, 8,
00107         0, 13, 1, 13, 2, 13, 3, 13, 5, 13, 8, 13, 13, 13, 21, 13,
00108         -1, 13, -2, 13, -3, 13, -5, 13, -8, 13, -13, 13, -17, 13, -21, 13,
00109         0, 21, 1, 21, 2, 21, 3, 21, 5, 21, 8, 21, 13, 21, 21, 21,
00110         -1, 21, -2, 21, -3, 21, -5, 21, -8, 21, -13, 21, -17, 21, -21, 21,
00111         0, -1, 1, -1, 2, -1, 3, -1, 5, -1, 8, -1, 13, -1, 21, -1,
00112         -1, -1, -2, -1, -3, -1, -5, -1, -8, -1, -13, -1, -17, -1, -21, -1,
00113         0, -2, 1, -2, 2, -2, 3, -2, 5, -2, 8, -2, 13, -2, 21, -2,
00114         -1, -2, -2, -2, -3, -2, -5, -2, -8, -2, -13, -2, -17, -2, -21, -2,
00115         0, -3, 1, -3, 2, -3, 3, -3, 5, -3, 8, -3, 13, -3, 21, -3,
00116         -1, -3, -2, -3, -3, -3, -5, -3, -8, -3, -13, -3, -17, -3, -21, -3,
00117         0, -5, 1, -5, 2, -5, 3, -5, 5, -5, 8, -5, 13, -5, 21, -5,
00118         -1, -5, -2, -5, -3, -5, -5, -5, -8, -5, -13, -5, -17, -5, -21, -5,
00119         0, -8, 1, -8, 2, -8, 3, -8, 5, -8, 8, -8, 13, -8, 21, -8,
00120         -1, -8, -2, -8, -3, -8, -5, -8, -8, -8, -13, -8, -17, -8, -21, -8,
00121         0, -13, 1, -13, 2, -13, 3, -13, 5, -13, 8, -13, 13, -13, 21, -13,
00122         -1, -13, -2, -13, -3, -13, -5, -13, -8, -13, -13, -13, -17, -13, -21, -13,
00123         0, -17, 1, -17, 2, -17, 3, -17, 5, -17, 8, -17, 13, -17, 21, -17,
00124         -1, -17, -2, -17, -3, -17, -5, -17, -8, -17, -13, -17, -17, -17, -21, -17,
00125         0, -21, 1, -21, 2, -21, 3, -21, 5, -21, 8, -21, 13, -21, 21, -21,
00126         -1, -21, -2, -21, -3, -21, -5, -21, -8, -21, -13, -21, -17, -21, 0, 0,
00127         -8, -29, 8, -29, -18, -25, 17, -25, 0, -23, -6, -22, 6, -22, -13, -19,
00128         12, -19, 0, -18, 25, -18, -25, -17, -5, -17, 5, -17, -10, -15, 10, -15,
00129         0, -14, -4, -13, 4, -13, 19, -13, -19, -12, -8, -11, -2, -11, 0, -11,
00130         2, -11, 8, -11, -15, -10, -4, -10, 4, -10, 15, -10, -6, -9, -1, -9,
00131         1, -9, 6, -9, -29, -8, -11, -8, -8, -8, -3, -8, 3, -8, 8, -8,
00132         11, -8, 29, -8, -5, -7, -2, -7, 0, -7, 2, -7, 5, -7, -22, -6,
00133         -9, -6, -6, -6, -3, -6, -1, -6, 1, -6, 3, -6, 6, -6, 9, -6,
00134         22, -6, -17, -5, -7, -5, -4, -5, -2, -5, 0, -5, 2, -5, 4, -5,
00135         7, -5, 17, -5, -13, -4, -10, -4, -5, -4, -3, -4, -1, -4, 0, -4,
00136         1, -4, 3, -4, 5, -4, 10, -4, 13, -4, -8, -3, -6, -3, -4, -3,
00137         -3, -3, -2, -3, -1, -3, 0, -3, 1, -3, 2, -3, 4, -3, 6, -3,
00138         8, -3, -11, -2, -7, -2, -5, -2, -3, -2, -2, -2, -1, -2, 0, -2,
00139         1, -2, 2, -2, 3, -2, 5, -2, 7, -2, 11, -2, -9, -1, -6, -1,
00140         -4, -1, -3, -1, -2, -1, -1, -1, 0, -1, 1, -1, 2, -1, 3, -1,
00141         4, -1, 6, -1, 9, -1, -31, 0, -23, 0, -18, 0, -14, 0, -11, 0,
00142         -7, 0, -5, 0, -4, 0, -3, 0, -2, 0, -1, 0, 0, -31, 1, 0,
00143         2, 0, 3, 0, 4, 0, 5, 0, 7, 0, 11, 0, 14, 0, 18, 0,
00144         23, 0, 31, 0, -9, 1, -6, 1, -4, 1, -3, 1, -2, 1, -1, 1,
00145         0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 6, 1, 9, 1, -11, 2,
00146         -7, 2, -5, 2, -3, 2, -2, 2, -1, 2, 0, 2, 1, 2, 2, 2,
00147         3, 2, 5, 2, 7, 2, 11, 2, -8, 3, -6, 3, -4, 3, -2, 3,
00148         -1, 3, 0, 3, 1, 3, 2, 3, 3, 3, 4, 3, 6, 3, 8, 3,
00149         -13, 4, -10, 4, -5, 4, -3, 4, -1, 4, 0, 4, 1, 4, 3, 4,
00150         5, 4, 10, 4, 13, 4, -17, 5, -7, 5, -4, 5, -2, 5, 0, 5,
00151         2, 5, 4, 5, 7, 5, 17, 5, -22, 6, -9, 6, -6, 6, -3, 6,
00152         -1, 6, 1, 6, 3, 6, 6, 6, 9, 6, 22, 6, -5, 7, -2, 7,
00153         0, 7, 2, 7, 5, 7, -29, 8, -11, 8, -8, 8, -3, 8, 3, 8,
00154         8, 8, 11, 8, 29, 8, -6, 9, -1, 9, 1, 9, 6, 9, -15, 10,
00155         -4, 10, 4, 10, 15, 10, -8, 11, -2, 11, 0, 11, 2, 11, 8, 11,
00156         19, 12, -19, 13, -4, 13, 4, 13, 0, 14, -10, 15, 10, 15, -5, 17,
00157         5, 17, 25, 17, -25, 18, 0, 18, -12, 19, 13, 19, -6, 22, 6, 22,
00158         0, 23, -17, 25, 18, 25, -8, 29, 8, 29, 0, 31, 0, 0, -6, -22,
00159         6, -22, -13, -19, 12, -19, 0, -18, -5, -17, 5, -17, -10, -15, 10, -15,
00160         0, -14, -4, -13, 4, -13, 19, -13, -19, -12, -8, -11, -2, -11, 0, -11,
00161         2, -11, 8, -11, -15, -10, -4, -10, 4, -10, 15, -10, -6, -9, -1, -9,
00162         1, -9, 6, -9, -11, -8, -8, -8, -3, -8, 0, -8, 3, -8, 8, -8,
00163         11, -8, -5, -7, -2, -7, 0, -7, 2, -7, 5, -7, -22, -6, -9, -6,
00164         -6, -6, -3, -6, -1, -6, 1, -6, 3, -6, 6, -6, 9, -6, 22, -6,
00165         -17, -5, -7, -5, -4, -5, -2, -5, -1, -5, 0, -5, 1, -5, 2, -5,
00166         4, -5, 7, -5, 17, -5, -13, -4, -10, -4, -5, -4, -3, -4, -2, -4,
00167         -1, -4, 0, -4, 1, -4, 2, -4, 3, -4, 5, -4, 10, -4, 13, -4,
00168         -8, -3, -6, -3, -4, -3, -3, -3, -2, -3, -1, -3, 0, -3, 1, -3,
00169         2, -3, 3, -3, 4, -3, 6, -3, 8, -3, -11, -2, -7, -2, -5, -2,
00170         -4, -2, -3, -2, -2, -2, -1, -2, 0, -2, 1, -2, 2, -2, 3, -2,
00171         4, -2, 5, -2, 7, -2, 11, -2, -9, -1, -6, -1, -5, -1, -4, -1,
00172         -3, -1, -2, -1, -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, -1,
00173         5, -1, 6, -1, 9, -1, -23, 0, -18, 0, -14, 0, -11, 0, -7, 0,
00174         -5, 0, -4, 0, -3, 0, -2, 0, -1, 0, 0, -23, 1, 0, 2, 0,
00175         3, 0, 4, 0, 5, 0, 7, 0, 11, 0, 14, 0, 18, 0, 23, 0,
00176         -9, 1, -6, 1, -5, 1, -4, 1, -3, 1, -2, 1, -1, 1, 0, 1,
00177         1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 9, 1, -11, 2,
00178         -7, 2, -5, 2, -4, 2, -3, 2, -2, 2, -1, 2, 0, 2, 1, 2,
00179         2, 2, 3, 2, 4, 2, 5, 2, 7, 2, 11, 2, -8, 3, -6, 3,
00180         -4, 3, -3, 3, -2, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3, 3,
00181         4, 3, 6, 3, 8, 3, -13, 4, -10, 4, -5, 4, -3, 4, -2, 4,
00182         -1, 4, 0, 4, 1, 4, 2, 4, 3, 4, 5, 4, 10, 4, 13, 4,
00183         -17, 5, -7, 5, -4, 5, -2, 5, -1, 5, 0, 5, 1, 5, 2, 5,
00184         4, 5, 7, 5, 17, 5, -22, 6, -9, 6, -6, 6, -3, 6, -1, 6,
00185         1, 6, 3, 6, 6, 6, 9, 6, 22, 6, -5, 7, -2, 7, 0, 7,
00186         2, 7, 5, 7, -11, 8, -8, 8, -3, 8, 0, 8, 3, 8, 8, 8,
00187         11, 8, -6, 9, -1, 9, 1, 9, 6, 9, -15, 10, -4, 10, 4, 10,
00188         15, 10, -8, 11, -2, 11, 0, 11, 2, 11, 8, 11, 19, 12, -19, 13,
00189         -4, 13, 4, 13, 0, 14, -10, 15, 10, 15, -5, 17, 5, 17, 0, 18,
00190         -12, 19, 13, 19, -6, 22, 6, 22, 0, 23,
00191     };
00192 
00193     if (_table_last_pitch == pitch && _table_last_index == index)
00194         return;
00195 #ifdef DEBUG
00196     cout << "codec37::maketable(" << pitch << ", " << index << ") called" << endl;
00197     if(index != 1) {
00198         cerr << "codec37::maketable(" << pitch << ", " << index << ") called" << endl;
00199     }
00200 #endif
00201     _table_last_pitch = pitch;
00202     _table_last_index = index;
00203     index *= 255;
00204     assert(index + 254 < (int)(sizeof(maketable_bytes) / 2));
00205 
00206     for (int i = 0; i < 255; i++) {
00207         int j = (i + index) << 1; // * 2
00208         _offset_table[i] = maketable_bytes[j + 1] * pitch + maketable_bytes[j];
00209     }       
00210 }
00211 
00212 void codec37_decoder::proc1(blitter & dst, chunck & src, int next_offs, int bw, int bh, int size) {
00213     unsigned char * decoded = new unsigned char[size];
00214     int w = 0;
00215     while(!src.eof()) {
00216         int code = src.get_byte();
00217         int length = (code >> 1) + 1;
00218         if (code & 1) {
00219             unsigned char val = src.get_byte();
00220             while(length--)
00221                 decoded[w++] = val;
00222         } else {
00223             while(length--) {
00224                 decoded[w++] = src.get_byte();
00225             }
00226         }
00227     }
00228     assert(w == size);
00229     w = 0;
00230     // Now we have our stream ready...
00231     for(int i = 0; i < size; i++) {
00232         if(decoded[i] == 0xFF) {
00233             dst.put_block(decoded + i + 1);
00234             i += 16;
00235         } else {
00236             dst.block_copy(_offset_table[decoded[i]] + next_offs);
00237         }
00238         if(++w == bw) {
00239             w = 0;
00240             dst.advance(0, 3);
00241         }
00242     }
00243     delete []decoded;
00244 }
00245 
00246 void codec37_decoder::proc2(blitter & dst, chunck & src, int size) { // This is codec1 like...
00247 #ifdef DEBUG_CODEC37_PROC2
00248     int decoded_size = 0;
00249     int coded_size = 0;
00250 #endif
00251     do {
00252         int code = src.get_byte();
00253         int length = (code >> 1) + 1;
00254         size -= length;
00255 #ifdef DEBUG_CODEC37_PROC2
00256         decoded_size += length;
00257         coded_size += 1 + ((code & 1) ? 1 : length);
00258         cout << "proc2() : code == " << code 
00259             << " : length == " << length 
00260             << " : decoded_size == " << decoded_size 
00261             <<  " : coded_size == " << coded_size 
00262             <<  " : seek - header == " << src.tell() - 31
00263             <<  " : size == " << size + decoded_size
00264             << endl;
00265 #endif
00266         if (code & 1)
00267             dst.put(src.get_char(), length);
00268         else
00269             // while(length--) dst.put(src.get_char());
00270             dst.blit(src, length);
00271     } while (size);
00272 }
00273 
00274 void codec37_decoder::proc3_with_fdfe(blitter & dst, chunck & src, int next_offs, int bw, int bh) {
00275 #ifdef DEBUG_CODEC37_PROC3
00276     int b_nb = 0;
00277 #endif
00278     do {
00279         int i = bw;
00280         do {
00281             int code = src.get_byte();
00282             if (code == 0xFD) {
00283 #ifdef DEBUG_CODEC37_PROC3
00284                 cout << "sbb3 : nb == " << b_nb << endl;
00285                 b_nb++;
00286 #endif
00287 #ifdef USE_COLOR_CODE_FOR_BLOCK
00288                 dst.put_block(expand(1));
00289 #else
00290                 dst.put_block(expand(src.get_byte()));
00291 #endif
00292             } else if (code == 0xFE) {
00293 #ifdef DEBUG_CODEC37_PROC3
00294                 cout << "sdb3 : nb == " << b_nb << endl;
00295                 b_nb++;
00296 #endif
00297 #ifdef USE_COLOR_CODE_FOR_BLOCK
00298                 dst.put_block(expand(2));
00299 #else
00300                 dst.put_block(expand(src.get_byte()), expand(src.get_byte()), expand(src.get_byte()), expand(src.get_byte()));
00301 #endif
00302             } else if (code == 0xFF) {
00303 #ifdef DEBUG_CODEC37_PROC3
00304                 cout << "mdb3 : nb == " << b_nb << endl;
00305                 b_nb++;
00306 #endif
00307 #ifdef USE_COLOR_CODE_FOR_BLOCK
00308                 dst.put_block(expand(3));
00309 #else
00310                 dst.put_block(src);
00311                 //~ dst.put_block(src.get_dword(), src.get_dword(), src.get_dword(), src.get_dword());
00312 #endif
00313             } else {
00314 #ifdef DEBUG_CODEC37_PROC3
00315                 cout << "sbc3 : nb == " << b_nb << endl;
00316                 b_nb++;
00317 #endif
00318 #ifdef USE_COLOR_CODE_FOR_BLOCK
00319                 dst.put_block(expand(4));
00320 #else
00321                 dst.block_copy(_offset_table[code] + next_offs); // copy from an offset !
00322 #endif
00323             }
00324         } while (--i);
00325         dst.advance(0, 3); // advance 3 lines
00326     } while (--bh);
00327 }
00328 
00329 void codec37_decoder::proc3_without_fdfe(blitter & dst, chunck & src, int next_offs, int bw, int bh) {
00330 #ifdef DEBUG_CODEC37_PROC3
00331     int b_nb = 0;
00332 #endif
00333     do {
00334         int i = bw;
00335         do {
00336             int code = src.get_byte();
00337             if (code == 0xFF) {
00338 #ifdef DEBUG_CODEC37_PROC3
00339                 cout << "mdb3 : nb == " << b_nb << endl;
00340                 b_nb++;
00341 #endif
00342 #ifdef USE_COLOR_CODE_FOR_BLOCK
00343                 dst.put_block(expand(5));
00344 #else
00345                 //~ unsigned char bytes[4*4];
00346                 //~ src.read(bytes, 4*4);
00347                 dst.put_block(src);
00348                 //~ dst.put_block(src.get_dword(), src.get_dword(), src.get_dword(), src.get_dword());
00349 #endif
00350             } else {
00351 #ifdef DEBUG_CODEC37_PROC3
00352                 cout << "sbc3 : nb == " << b_nb << endl;
00353                 b_nb++;
00354 #endif
00355 #ifdef USE_COLOR_CODE_FOR_BLOCK
00356                 dst.put_block(expand(6));
00357 #else
00358                 dst.block_copy(_offset_table[code] + next_offs); // copy from an offset !
00359 #endif
00360             }
00361         } while (--i);
00362         dst.advance(0, 3); // advance 3 lines
00363     } while (--bh);
00364 }
00365 
00366 void codec37_decoder::proc4(blitter & dst, chunck & src, int next_offs, int bw, int bh) {
00367 #ifdef DEBUG_CODEC37_PROC4
00368     int b_nb = 0;
00369 #endif
00370     do {
00371         int i = bw;
00372         do {
00373             int code = src.get_byte();
00374             //~ cout << code << " ";
00375             if (code == 0xFD) {
00376 #ifdef DEBUG_CODEC37_PROC4
00377                 cout << "sbb4 : nb == " << b_nb << endl;
00378                 b_nb++;
00379 #endif
00380 #ifdef USE_COLOR_CODE_FOR_BLOCK
00381                 dst.put_block(expand(7));
00382 #else                   
00383                 dst.put_block(expand(src.get_byte()));
00384 #endif
00385             } else if (code == 0xFE) {
00386 #ifdef DEBUG_CODEC37_PROC4
00387                 cout << "sdb4 : nb == " << b_nb << endl;
00388                 b_nb++;
00389 #endif
00390 #ifdef USE_COLOR_CODE_FOR_BLOCK
00391                 dst.put_block(expand(8));
00392 #else                   
00393                 dst.put_block(expand(src.get_byte()), expand(src.get_byte()), expand(src.get_byte()), expand(src.get_byte()));
00394 #endif
00395             } else if (code == 0xFF) {
00396 #ifdef DEBUG_CODEC37_PROC4
00397                 cout << "mdb4 : nb == " << b_nb << endl;
00398                 b_nb++;
00399 #endif
00400 #ifdef USE_COLOR_CODE_FOR_BLOCK
00401                 dst.put_block(expand(9));
00402 #else                   
00403                 dst.put_block(src);
00404                 //~ dst.put_block(src.get_dword(), src.get_dword(), src.get_dword(), src.get_dword());
00405 #endif
00406             } else if (code == 0x00) {
00407                 int length = src.get_byte() + 1;
00408 #ifdef DEBUG_CODEC37_PROC4
00409                 cout << "mbc4 : nb == " << b_nb << " : length == " << length << endl;
00410                 b_nb+=length;
00411 #endif
00412                 for (int l = 0; l < length; l++) {
00413 #ifdef USE_COLOR_CODE_FOR_BLOCK
00414                     dst.put_block(expand(10));
00415 #else                   
00416                     dst.block_copy(next_offs);
00417 #endif
00418                     i--;
00419                     if (i == 0) {
00420                         dst.advance(0, 3); // advance 3 lines
00421                         bh--;
00422                         i = bw;
00423                     }
00424                 }
00425                 if(bh == 0) return;
00426                 i++;
00427             } else {
00428 #ifdef DEBUG_CODEC37_PROC4
00429                 cout << "sbc4 : nb == " << b_nb << endl;
00430                 b_nb++;
00431 #endif
00432 #ifdef USE_COLOR_CODE_FOR_BLOCK
00433                 dst.put_block(expand(11));
00434 #else                   
00435                 dst.block_copy(_offset_table[code] + next_offs); // copy from an offset !
00436 #endif
00437             }
00438         } while (--i);
00439         dst.advance(0, 3); // advance 3 lines
00440     } while (--bh);
00441     //~ cout << endl;
00442 }
00443 
00444 bool codec37_decoder::decode(blitter & dst, chunck & src) throw(exception) {
00445     int width = get_rect().width();
00446     int height = get_rect().height();
00447     //~ bool result = false;
00448     //~ bool changed = true;
00449     int bw = (width + 3) >> 2, bh = (height + 3) >> 2;
00450     int pitch = bw << 2;
00451 #ifdef DEBUG_CODEC37
00452     cout << "codec37::decode() : width == " << width
00453         << " : height == " << height
00454         << " : pitch == " << pitch 
00455         << " : _prev_seq_nb == " << _prev_seq_nb 
00456         << endl;
00457 #endif
00458     int code                = src.get_byte();   // 0 -> 1   (1)
00459     int index               = src.get_byte();   // 1 -> 2   (1)
00460     unsigned short seq_nb   = src.get_word();   // 2 -> 4   (2)
00461     unsigned int decoded_size   = src.get_dword();  // 4 -> 8   (4)
00462 #ifdef DEBUG_CODEC37
00463     unsigned int coded_size = src.get_dword();  // 8 -> 12  (4)
00464 #else
00465     src.seek(4);
00466 #endif
00467     unsigned int mask_flag  = src.get_dword();  // 12 -> 16 (4)
00468 #ifdef DEBUG_CODEC37
00469     cout << "codec37::decode() : code == " << code
00470         << " : index == " << index
00471         << " : seq_nb == " << seq_nb
00472         << " : decoded_size == " << decoded_size
00473         << " : coded_size == " << coded_size
00474         << " : mask_flag == " << mask_flag << endl;
00475 #endif
00476     maketable(pitch, index);
00477     if(code == 3 || code == 4 || code == 1) {
00478         assert(seq_nb && _prev_seq_nb + 1 == seq_nb);
00479         if (seq_nb & 1 || !(mask_flag & 1)) _curtable ^= 1;
00480     }
00481     blitter blit(reinterpret_cast<char *>(_deltaBufs[_curtable]), point(width, height), rect(0, 0, width, height));
00482     try {
00483         switch(code) {
00484         case 0:
00485             memset(_deltaBuf, 0, _deltaBufs[_curtable] - _deltaBuf);
00486             memset(_deltaBufs[_curtable] + decoded_size, 0, _deltaBuf + _deltaSize - _deltaBufs[_curtable] - decoded_size);
00487             blit.blit(src, decoded_size);
00488             break;
00489         case 1:
00490             proc1(blit, src, _deltaBufs[_curtable ^ 1] - _deltaBufs[_curtable], bw, bh, decoded_size);
00491             break;
00492         case 2:
00493             memset(_deltaBuf, 0, _deltaBufs[_curtable] - _deltaBuf);
00494             memset(_deltaBufs[_curtable] + decoded_size, 0, _deltaBuf + _deltaSize - _deltaBufs[_curtable] - decoded_size);
00495             proc2(blit, src, decoded_size);
00496             break;
00497         case 3:
00498             if(mask_flag & 1)
00499                 proc3_with_fdfe(blit, src, _deltaBufs[_curtable ^ 1] - _deltaBufs[_curtable], bw, bh);
00500             else
00501                 proc3_without_fdfe(blit, src, _deltaBufs[_curtable ^ 1] - _deltaBufs[_curtable], bw, bh);
00502             break;
00503         case 4:
00504             proc4(blit, src, _deltaBufs[_curtable ^ 1] - _deltaBufs[_curtable], bw, bh);
00505             break;
00506         default:
00507 //~ #ifdef DEBUG_CODEC37
00508             ostringstream oss;
00509             oss << "codec37::decode() received an invalid code : " << code;
00510             throw runtime_error(oss.str());
00511 //~ #endif
00512             break;
00513         }
00514     } catch(const exception & e) {
00515 #ifdef DEBUG
00516         cerr << "exception in codec37::decode() : " << e.what() << endl;
00517 #endif
00518     }
00519     dst.blit(reinterpret_cast<char*>(_deltaBufs[_curtable]), width * height);
00520     _prev_seq_nb = seq_nb;
00521     return true;
00522 }
00523 

Generated on Fri Aug 9 22:54:29 2002 for san_player by doxygen1.2.16