Ejemplo n.º 1
0
    O3DGCErrorCode    CompressedTriangleFans::SaveUIntAC(const Vector<long> & data,
                                                         const unsigned long M,
                                                         BinaryStream & bstream) 
    {
        unsigned long start = bstream.GetSize();     
        const unsigned int NMAX = data.GetSize() * 8 + 100;
        const size_t size       = data.GetSize();
        long minValue = O3DGC_MAX_LONG;
        bstream.WriteUInt32Bin(0);
        bstream.WriteUInt32Bin(size);
        if (size > 0)
        {
    #ifdef DEBUG_VERBOSE
            printf("-----------\nsize %i, start %i\n", size, start);
            fprintf(g_fileDebugTF, "-----------\nsize %i, start %i\n", size, start);
    #endif //DEBUG_VERBOSE

            for(size_t i = 0; i < size; ++i)
            {
                if (minValue > data[i]) 
                {
                    minValue = data[i];
                }
    #ifdef DEBUG_VERBOSE
                printf("%i\t%i\n", i, data[i]);
                fprintf(g_fileDebugTF, "%i\t%i\n", i, data[i]);
    #endif //DEBUG_VERBOSE
            }
            bstream.WriteUInt32Bin(minValue);
            if ( m_sizeBufferAC < NMAX )
            {
                delete [] m_bufferAC;
                m_sizeBufferAC = NMAX;
                m_bufferAC     = new unsigned char [m_sizeBufferAC];
            }
            Arithmetic_Codec ace;
            ace.set_buffer(NMAX, m_bufferAC);
            ace.start_encoder();
            Adaptive_Data_Model mModelValues(M+1);
            for(size_t i = 0; i < size; ++i)
            {
                ace.encode(data[i]-minValue, mModelValues);
            }
            unsigned long encodedBytes = ace.stop_encoder();
            for(size_t i = 0; i < encodedBytes; ++i)
            {
                bstream.WriteUChar8Bin(m_bufferAC[i]);
            }
        }
        bstream.WriteUInt32Bin(start, bstream.GetSize() - start);
        return O3DGC_OK;
    }
Ejemplo n.º 2
0
 O3DGCErrorCode    SaveIntData(const Vector<long> & data,
                               BinaryStream & bstream) 
 {
     unsigned long start = bstream.GetSize();
     bstream.WriteUInt32ASCII(0);
     const size_t size       = data.GetSize();
     bstream.WriteUInt32ASCII(size);
     for(size_t i = 0; i < size; ++i)
     {
         bstream.WriteIntASCII(data[i]);
     }
     bstream.WriteUInt32ASCII(start, bstream.GetSize() - start);
     return O3DGC_OK;
 }
Ejemplo n.º 3
0
 O3DGCErrorCode    SaveBinData(const Vector<long> & data,
                               BinaryStream & bstream) 
 {
     unsigned long start = bstream.GetSize();
     bstream.WriteUInt32ASCII(0);
     const size_t size = data.GetSize();
     long symbol;
     bstream.WriteUInt32ASCII(size);
     for(size_t i = 0; i < size; )
     {
         symbol = 0;
         for(unsigned long h = 0; h < O3DGC_BINARY_STREAM_BITS_PER_SYMBOL0 && i < size; ++h)
         {
             symbol += (data[i] << h);
             ++i;
         }
         bstream.WriteUCharASCII((unsigned char) symbol);
     }
     bstream.WriteUInt32ASCII(start, bstream.GetSize() - start);
     return O3DGC_OK;
 }
Ejemplo n.º 4
0
bool GameBoyLoader::IsCompatible(BinaryStream const& rBinStrm)
{
  if (rBinStrm.GetSize() < GAMEBOY_HEADER_OFFSET + sizeof m_GameBoyRom)
    return false;

  if (!rBinStrm.Read(GAMEBOY_HEADER_OFFSET, reinterpret_cast<u8*>(&m_GameBoyRom), sizeof m_GameBoyRom))
    return false;

  if (memcmp(m_GameBoyRom.NintendoLogo, s_NintendoLogo, NINTENDO_LOGO_LEN))
    return false;

  return true;
}
Ejemplo n.º 5
0
int testDecode(std::string & fileName)
{
    std::string folder;
    long found = (long)fileName.find_last_of(PATH_SEP);
    if (found != -1)
    {
        folder = fileName.substr(0,found);
    }
    if (folder == "")
    {
        folder = ".";
    }
    std::string file(fileName.substr(found+1));
    std::string outFileName = folder + PATH_SEP + file.substr(0, file.find_last_of(".")) + "_dec.obj";


    std::vector< Vec3<Real> > points;
    std::vector< Vec3<Real> > normals;
    std::vector< Vec2<Real> > colors;
    std::vector< Vec2<Real> > texCoords;
    std::vector< Vec3<Index> > triangles;
    std::vector< unsigned long > matIDs;
    std::vector< Material > materials;
    std::string materialLib;

    std::string matFileName = folder + PATH_SEP + file.substr(0, file.find_last_of(".")) + ".mat";
    bool ret = LoadMaterials(matFileName.c_str(), materials, materialLib);
    if (ret)
    {
        const size_t numMaterials = materials.size();
        unsigned long n, shift = 0;
        for(size_t i = 0; i < numMaterials; ++i)
        {
            n = materials[i].m_numTriangles + shift;
            matIDs.resize(n, materials[i].m_id);
            shift = n;
        }
    }
    

    BinaryStream bstream;
    IndexedFaceSet<Index> ifs;


    FILE * fin = fopen(fileName.c_str(), "rb");
    if (!fin)
    {
        return -1;
    }
    fseek(fin, 0, SEEK_END);
    unsigned long size = ftell(fin);
    bstream.Allocate(size);
    rewind(fin);
    unsigned long nread = (unsigned long)fread((void *) bstream.GetBuffer(), 1, size, fin);
    bstream.SetSize(size);
    if (nread != size)
    {
        return -1;
    }
    fclose(fin);
    std::cout << "Bitstream size (bytes) " << bstream.GetSize() << std::endl;

    SC3DMCDecoder<Index> decoder;
    // load header
    Timer timer;
    timer.Tic();
    decoder.DecodeHeader(ifs, bstream);
    timer.Toc();
    std::cout << "DecodeHeader time (ms) " << timer.GetElapsedTime() << std::endl;

    // allocate memory
    triangles.resize(ifs.GetNCoordIndex());
    ifs.SetCoordIndex((Index * const ) &(triangles[0]));    

    points.resize(ifs.GetNCoord());
    ifs.SetCoord((Real * const ) &(points[0]));    

    if (ifs.GetNNormal() > 0)
    {
        normals.resize(ifs.GetNNormal());
        ifs.SetNormal((Real * const ) &(normals[0]));  
    }
    if (ifs.GetNColor() > 0)
    {
        colors.resize(ifs.GetNColor());
        ifs.SetColor((Real * const ) &(colors[0]));  
    }
    if (ifs.GetNTexCoord() > 0)
    {
        texCoords.resize(ifs.GetNTexCoord());
        ifs.SetTexCoord((Real * const ) &(texCoords[0]));
    }

    std::cout << "Mesh info "<< std::endl;
    std::cout << "\t# coords    " << ifs.GetNCoord() << std::endl;
    std::cout << "\t# normals   " << ifs.GetNNormal() << std::endl;
    std::cout << "\t# texcoords " << ifs.GetNTexCoord() << std::endl;
    std::cout << "\t# triangles " << ifs.GetNCoordIndex() << std::endl;

    // decode mesh
    timer.Tic();
    decoder.DecodePlayload(ifs, bstream);
    timer.Toc();
    std::cout << "DecodePlayload time (ms) " << timer.GetElapsedTime() << std::endl;

    std::cout << "Details" << std::endl;
    const SC3DMCStats & stats = decoder.GetStats();
    std::cout << "\t CoordIndex         " << stats.m_timeCoordIndex     << " ms, " << stats.m_streamSizeCoordIndex     <<" bytes (" << 8.0*stats.m_streamSizeCoordIndex     / ifs.GetNCoord() <<" bpv)" <<std::endl;
    std::cout << "\t Coord              " << stats.m_timeCoord          << " ms, " << stats.m_streamSizeCoord          <<" bytes (" << 8.0*stats.m_streamSizeCoord          / ifs.GetNCoord() <<" bpv)" <<std::endl;
    std::cout << "\t Normal             " << stats.m_timeNormal         << " ms, " << stats.m_streamSizeNormal         <<" bytes (" << 8.0*stats.m_streamSizeNormal         / ifs.GetNCoord() <<" bpv)" <<std::endl;
    std::cout << "\t TexCoord           " << stats.m_timeTexCoord       << " ms, " << stats.m_streamSizeTexCoord       <<" bytes (" << 8.0*stats.m_streamSizeTexCoord       / ifs.GetNCoord() <<" bpv)" <<std::endl;
    std::cout << "\t Color              " << stats.m_timeColor          << " ms, " << stats.m_streamSizeColor          <<" bytes (" << 8.0*stats.m_streamSizeColor          / ifs.GetNCoord() <<" bpv)" <<std::endl;
    std::cout << "\t Float Attributes   " << stats.m_timeFloatAttribute << " ms, " << stats.m_streamSizeFloatAttribute <<" bytes (" << 8.0*stats.m_streamSizeFloatAttribute / ifs.GetNCoord() <<" bpv)" <<std::endl;
    std::cout << "\t Integer Attributes " << stats.m_timeFloatAttribute << " ms, " << stats.m_streamSizeFloatAttribute <<" bytes (" << 8.0*stats.m_streamSizeFloatAttribute / ifs.GetNCoord() <<" bpv)" <<std::endl;
    std::cout << "\t Reorder            " << stats.m_timeReorder        << " ms,  " << 0 <<" bytes (" << 0.0 <<" bpv)" <<std::endl;

    std::cout << "Saving " << outFileName << " ..." << std::endl;

    ret = SaveOBJ(outFileName.c_str(), points, texCoords, normals, triangles, materials, matIDs, materialLib);
    if (!ret)
    {
        std::cout << "Error: SaveOBJ()\n" << std::endl;
        return -1;
    }
    std::cout << "Done." << std::endl;
    return 0;
}