Пример #1
0
int Ccps_file::extract_as_pcx(const string& name, const t_palet _palet) const
{
	t_palet palet;
	if (has_palet())
		memcpy(palet, get_palet(), sizeof(t_palet));
	else
		memcpy(palet, _palet, sizeof(t_palet));
	convert_palet_18_to_24(palet);
	byte* image = new byte[320 * 200];
	decode80(get_image(), image);
	byte* d = new byte[320 * 200 * 2];
	int cb_d = pcx_encode(image, d, 320, 200, 1);
	Cpcx_file_write f;
	int error = f.open_write(name);
	if (!error)
	{
		f.set_size(320, 200, 1);
		error = f.write_header();
	}
	if (!error)
		error = f.write_image(d, cb_d);
	if (!error)
		error = f.write_palet(palet);
	f.close();
	delete[] d;
	delete[] image;
	return error;
}
Пример #2
0
void ShpFile::decodeCnC(uint16_t fileIndex, uint8_t* imageOut)
{
    if (fileIndex >= _size)
    {
        throw(Exception(LOG_ERROR, "ShpFile", "Requested frame out of range"));
    }
    
    LOG_DEBUG("Frame %d Offset %d, format %d", fileIndex, _index.at(fileIndex).startOffset, _index.at(fileIndex).imgFormat);
    
    _stream.seekg(_index.at(fileIndex).startOffset, std::ios_base::beg);
    
    uint32_t len;
    std::vector<uint8_t> source;
    
    switch (_index.at(fileIndex).imgFormat) {
        case 0x80:
            decode80(imageOut, 0);
            break;
        case 0x40:{
            uint32_t refimage = getIndex(_index.at(fileIndex).refOffset);
            decodeCnC(refimage, imageOut);
            len = _index.at(fileIndex + 1).startOffset - _index.at(fileIndex).startOffset;
            source.resize(len);
            source.clear();
            _stream.read(reinterpret_cast<char*>(&source.front()), len);
            decode40(reinterpret_cast<uint8_t*>(&source.front()), imageOut);
            break;
        }
        case 0x20:
            decodeCnC(fileIndex - 1, imageOut);
            len = _index.at(fileIndex + 1).startOffset - _index.at(fileIndex).startOffset;
            source.resize(len);
            source.clear();
            _stream.read(reinterpret_cast<char*>(&source.front()), len);
            decode40(reinterpret_cast<uint8_t*>(&source.front()), imageOut);
            break;
        default:
            throw(Exception(LOG_ERROR, "ShpFile", "Image format not recognized"));
    }
    //return Surface(imageOut, _width, _height, 8, _palette);
}
Пример #3
0
int Cwsa_dune2_file::extract_as_pcx(const Cfname& name, const t_palet _palet) const
{
	t_palet palet;
	convert_palet_18_to_24(_palet, palet);
	int error = 0;
	const int cx = get_cx();
	const int cy = get_cy();
	const int c_frames = get_c_frames();
	byte* frame = new byte[cx * cy];
	byte* s = new byte[64 << 10];
	byte* d = new byte[cx * cy * 2];
	memset(frame, 0, cx * cy);
	for (int i = 0; i < c_frames; i++)
	{
		if (get_offset(i))
		{
			decode80(get_frame(i), s);
			decode40(s, frame);
		}
		int cb_d = pcx_encode(frame, d, cx, cy, 1);
		Cpcx_file_write f;
		Cfname t = name;
		t.set_title(name.get_ftitle() + " " + nwzl(4, i));
		error = f.open_write(t);
		if (error)
			break;
		f.set_size(cx, cy, 1);
		error = f.write_header();
		if (!error)
			error = f.write_image(d, cb_d);
		if (!error)
			error = f.write_palet(palet);
		f.close();
		if (error)
			break;
	}
	delete[] d;
	delete[] s;
	delete[] frame;
	return error;
}
Пример #4
0
SDL_Surface * LoadCPS_RW(SDL_RWops* RWop, int freesrc)
{
	if(RWop == NULL) {
		return NULL;
	}

    uint8_t* pFiledata = NULL;
    uint8_t* pImageOut = NULL;
    SDL_Surface *pic = NULL;

	try {
        Uint32 CpsFilesize = SDL_RWseek(RWop,0,SEEK_END);
        if(CpsFilesize <= 0) {
            throw std::runtime_error("LoadCPS_RW(): Cannot determine size of this *.cps-File!");
        }

        if(SDL_RWseek(RWop,0,SEEK_SET) != 0) {
            throw std::runtime_error("LoadCPS_RW(): Seeking in this *.cps-File failed!");
        }

        pFiledata = new uint8_t[CpsFilesize];

        if(SDL_RWread(RWop, pFiledata, CpsFilesize, 1) != 1) {
            throw std::runtime_error("LoadCPS_RW(): Reading this *.cps-File failed!");
        }

        uint16_t format = SDL_SwapLE16(*(uint16_t*)(pFiledata + 2));

        if(format != 0x0004) {
            throw std::runtime_error("LoadCPS_RW(): Only Format80 encoded *.cps-Files are supported!");
        }

        unsigned int SizeXTimeSizeY = SDL_SwapLE16(*((uint16_t*)(pFiledata + 4)));
        SizeXTimeSizeY += SDL_SwapLE16(*((uint16_t*)(pFiledata + 6)));

        if(SizeXTimeSizeY != SIZE_X * SIZE_Y) {
            throw std::runtime_error("LoadCPS_RW(): Images must be 320x200 pixels big!");
        }

        uint16_t PaletteSize = SDL_SwapLE16(*((uint16_t*)(pFiledata + 8)));

        pImageOut = new uint8_t[SIZE_X*SIZE_Y];
        memset(pImageOut, 0, SIZE_X*SIZE_Y);

        if(decode80(pFiledata + 10 + PaletteSize, pImageOut, 0) == -2) {
            throw std::runtime_error("LoadCPS_RW(): Decoding this *.cps-File failed!");
        }

        // create new picture surface
        if((pic = SDL_CreateRGBSurface(SDL_HWSURFACE,SIZE_X,SIZE_Y,8,0,0,0,0))== NULL) {
            throw std::runtime_error("LoadCPS_RW(): SDL_CreateRGBSurface has failed!");
        }

        palette.applyToSurface(pic);
        SDL_LockSurface(pic);

        //Now we can copy line by line
        for(int y = 0; y < SIZE_Y;y++) {
            memcpy(	((char*) (pic->pixels)) + y * pic->pitch , pImageOut + y * SIZE_X, SIZE_X);
        }

        SDL_UnlockSurface(pic);

	    delete [] pFiledata;
	    delete [] pImageOut;

        if(freesrc) {
            SDL_RWclose(RWop);
        }

        return pic;
	} catch (std::exception &e) {
		fprintf(stderr, "%s\n", e.what());

	    delete [] pFiledata;
	    delete [] pImageOut;

	    if(pic != NULL) {
            SDL_FreeSurface(pic);
	    }

        if(freesrc) {
            SDL_RWclose(RWop);
        }

        return NULL;
	}
}
Пример #5
0
Surface ShpFile::decodeDune(uint16_t fileIndex)
{
    uint8_t *imageOut,
	    slices;
    uint16_t flags,
	     fileSize,
	     imageSize,
	     imageOutSize,
	     width,
	     height;
    std::vector<uint8_t>
	palOffsets,
	decodeDestination;

    _stream.seekg(_index.at(fileIndex).startOffset, std::ios::beg);
    flags = _stream.getU16LE();

    slices = _stream.get();
    width = _stream.getU16LE();
    height = _stream.get();

    fileSize = _stream.getU16LE();
    /* size and also checksum */
    imageSize = _stream.getU16LE();

    imageOut = new uint8_t[imageOutSize = width*height];

    LOG_INFO("ShpFile", "File Nr.: %d (Size: %dx%d)",fileIndex,width,height);

    switch(flags) {
	case 0:
	    decodeDestination.resize(imageSize);
	    
	    if(decode80(&decodeDestination.front(), imageSize) == -1)
		LOG_WARNING("ShpFile","Checksum-Error in Shp-File");

	    decode2(decodeDestination, imageOut);
	    break;

	case 1:
	    decodeDestination.resize(imageSize);
	    palOffsets.resize(16);

	    _stream.read(reinterpret_cast<char*>(&palOffsets.front()), palOffsets.size());

	    if(decode80(&decodeDestination.front(), imageSize) == -1)
		LOG_WARNING("ShpFile", "Checksum-Error in Shp-File");
	    
	    decode2(decodeDestination, imageOut);

	    apply_pal_offsets(palOffsets,imageOut, imageOutSize);
	    break;

	case 2:
#if 0	//FIXME
	    decode2(_stream, imageOut, imageSize);
#else	    
	    decodeDestination.resize(imageSize);	    
	    _stream.read(reinterpret_cast<char*>(&decodeDestination.front()), imageSize);
	    decode2(decodeDestination, imageOut);
#endif
	    break;

	case 3:
	    palOffsets.resize(16);
	    _stream.read(reinterpret_cast<char*>(&palOffsets.front()), palOffsets.size());

#if 0	//FIXME
	    decode2(_stream, imageOut, imageSize);
#else	    
	    decodeDestination.resize(imageSize);	    
	    _stream.read(reinterpret_cast<char*>(&decodeDestination.front()), imageSize);
	    decode2(decodeDestination, imageOut);
#endif

	    apply_pal_offsets(palOffsets, imageOut, imageOutSize);
	    break;

	default:
	    throw(Exception(LOG_ERROR, "ShpFile", "Type %d in SHP-Files not supported!", flags));
    }

    return Surface(imageOut, width, height, 8, _palette);
}