Пример #1
0
bool TGAImageDecoder::Encode( const Image* image, DataStream* ds) {
    if (!image) return false;
    if (!ds) return false;
    if (image->GetFormat()==IMAGE_FORMAT_GRAY)
        return false;
    TGAHeader header;
    header.idlength = 0;
    header.colourmaptype = 0;
    header.datatypecode = 8 + 2;
    header.colourmaporigin = 0;
    header.colourmaplength = 0;
    header.colourmapdepth = 0;
    header.x_origin = 0;
    header.y_origin = 0;
    header.width = image->GetWidth();
    header.height = image->GetHeight();
    if (image->GetFormat()==IMAGE_FORMAT_RGB) {
        header.bitsperpixel = 24;
        header.imagedescriptor = 0;
        /// @todo uniplemented
        return false;
    } else if (image->GetFormat()==IMAGE_FORMAT_RGBA) {
        header.bitsperpixel = 32;
        header.imagedescriptor = 8 | 0x20;
    }
    ds->Write(reinterpret_cast<const Byte*> (&header),sizeof(header));

    if (image->GetFormat()==IMAGE_FORMAT_RGBA) {
        //return SaveRAW32(ds,image);
        return SaveRLE32(ds,image);
    }
    return true;
}
Пример #2
0
    const Data* TGAImageDecoder::Encode( const Image* image) {
        if (!image) return 0;
        
        if (image->GetFormat()==IMAGE_FORMAT_GRAY)
            return 0;
        TGAHeader header;
        header.idlength = 0;
        header.colourmaptype = 0;
        header.datatypecode = 8 + 2;
        header.colourmaporigin = 0;
        header.colourmaplength = 0;
        header.colourmapdepth = 0;
        header.x_origin = 0;
        header.y_origin = 0;
        header.width = image->GetWidth();
        header.height = image->GetHeight();
        if (image->GetFormat()==IMAGE_FORMAT_RGB) {
            header.bitsperpixel = 24;
            header.imagedescriptor = 0;
            /// @todo uniplemented
            return 0;
        } else if (image->GetFormat()==IMAGE_FORMAT_RGBA) {
            header.bitsperpixel = 32;
            header.imagedescriptor = 8 | 0x20;
        }
        DataArrayImpl* ds = new DataArrayImpl();
        ds->append(reinterpret_cast<const Byte*> (&header),sizeof(header));

        if (image->GetFormat()==IMAGE_FORMAT_RGBA) {
            //return SaveRAW32(ds,image);
            if (!SaveRLE32(ds,image)) {
                delete ds;
                return 0;
            }
        }
        return ds;
    }