Пример #1
0
	int canWrite(SImage& image)
	{
		// If it's the correct size and colour format, it's writable
		if (image.getType() == PALMASK &&
		        validSize(image.getWidth(), image.getHeight()))
			return WRITABLE;

		// Otherwise, it can be converted via palettising and cropping
		return CONVERTIBLE;
	}
Пример #2
0
string Components::payload() {
	stringstream ss;
	ss << "# number of components" << endl;
	ss << validSize() << endl;
	for(auto component: members) {
		if (!component->isRoot()) continue;
		ss << component->payload() << endl;
	}
	return ss.str();
}
Пример #3
0
void Transmute::WrapBox(){
	if (!validSize()) return;

	int sized = heldText.size();

	for (int i = 0; i < sized; i++){
		for (int j = 0; j < sized; j++){
			std::cout << heldText[(i + j) % sized] << ' ';
		}
		std::cout << '\n';
	}
}
Пример #4
0
void Transmute::UpperGradient(){
	if (!validSize()) return;

	int sized = heldText.size();

	for (int i = 0; i < sized; i++){
		for (int j = i; j < sized; j++){
			std::cout << heldText[j] << ' ';
		}
		std::cout << '\n';
	}

}
Пример #5
0
void Transmute::RightAngle(){ 
	if (!validSize()) return;

	// Upper row
	for (int i = 0; i < heldText.size(); i++){
		std::cout << heldText[i] << ' ';
	}
	std::cout << '\n';
	// Vertical column of text
	for (int i = 1; i < heldText.size(); i++){
		std::cout << heldText[i] << '\n';
	}
} 
Пример #6
0
	bool writeImage(SImage& image, MemChunk& data, Palette* pal, int index)
	{
		// Can't write if RGBA
		if (image.getType() == RGBA)
			return false;

		// Check size
		if (!validSize(image.getWidth(), image.getHeight()))
			return false;

		// Just dump image data to memchunk
		data.clear();
		data.write(imageData(image), image.getWidth() * image.getHeight());

		return true;
	}
Пример #7
0
uint8_t* keyHash(const uint8_t* input, 
                 const uint64_t input_length, 
                 const SkeinSize_t state_size)
{
    struct SkeinCtx skein_state;
    uint8_t* digest = NULL;

    if (input != NULL && validSize(state_size))
    {
        digest = calloc((state_size/8), sizeof(uint8_t)); //allocate the digest buffer    
        skeinCtxPrepare(&skein_state, state_size); //Tell skein what size its state is
        skeinInit(&skein_state, state_size); //Init our hash
        skeinUpdate(&skein_state, input, input_length); //Generate our hash
        skeinFinal(&skein_state, (uint8_t*)digest); //Put the results in our buffer
    }

    return digest;
}
Пример #8
0
uint8_t* skeinHash(const uint8_t* input, 
                   const uint64_t digest_length, 
                   const SkeinSize_t state_size)
{
    struct SkeinCtx skein_state; //Skein state
    uint8_t* digest = NULL;

    if (input != NULL && validSize(state_size))
    {
        //ensure digest is a null terminated string
        digest = calloc(digest_length+1, sizeof(uint8_t)); 
        skeinCtxPrepare(&skein_state, state_size); //Tell skein what size its state is
        skeinInit(&skein_state, digest_length*8); //Init our hash
        skeinUpdate(&skein_state, input, strlen((char*)input)); //Generate our hash
        skeinFinal(&skein_state, (uint8_t*)digest); //Put the results in the buffer
    }

    return digest;
}
Пример #9
0
	int canWrite(SImage& image)
	{
		// If it's the correct size and colour format, it's writable
		int width  = image.getWidth();
		int height = image.getHeight();

		// Shouldn't happen but...
		if (width < 0 || height < 0)
			return NOTWRITABLE;

		if (image.getType() == PALMASK && validSize(image.getWidth(), image.getHeight()))
			return WRITABLE;

		// Otherwise, check if it can be cropped to a valid size
		for (unsigned a = 0; a < n_valid_flat_sizes; a++)
			if (((unsigned)width >= valid_flat_size[a][0] && (unsigned)height >= valid_flat_size[a][1]
				 && valid_flat_size[a][2] == 1)
				|| gfx_extraconv)
				return CONVERTIBLE;

		return NOTWRITABLE;
	}
Пример #10
0
PrimitiveSurface * Material::getSurface( DisplayDevice * pDisplay, Image::Link pImage, int nFrame, bool bMipMap )
{
	// generate a unique key from the components
	WidgetKey nKey = pImage.key() + nFrame;
	if ( bMipMap )
		nKey += MIPMAP_KEY;

	AutoLock lock( &sm_SurfaceHashLock );
	SurfaceHash::Iterator it = sm_SurfaceHash.find( nKey );
	if ( it.valid() )
		return *it;
	lock.release();

	// surface not found, create and cache the surface
	PrimitiveSurface::Ref pSurface;
	if ( pImage.valid() && pImage->frameCount() > 0 )
	{
		// find a format for our surface first, findBestFormat() will always try to use the images current format
		// if supported by the hardware.
		ColorFormat::Format eFormat = findBestFormat( pDisplay, pImage, true );
		if ( eFormat == ColorFormat::INVALID )
		{
			TRACE( "ERROR: Failed to find a suitable surface format for texture!" );
			return NULL;
		}

		SizeInt imageSize( pImage->size() );
		SizeInt maxSize( pDisplay->textureMaxSize() );
		SizeInt minSize( pDisplay->textureMinSize() );

		// use the smaller max size
		maxSize.width = Min( sm_MaxTextureSize.width, maxSize.width );
		maxSize.height = Min( sm_MaxTextureSize.height, maxSize.height );

		// validate the texture dimensions
		SizeInt validSize( Max( Min( imageSize.width, maxSize.width ), minSize.width), 
			Max( Min( imageSize.height, maxSize.height ), minSize.height) );
		if ( pDisplay->textureP2() && !pImage->isP2() )
			validSize = SizeInt( 1 << GetLastBit( validSize.width ), 1 << GetLastBit( validSize.height) );
		if ( pDisplay->textureSquare() && validSize.width != validSize.height )
			validSize = SizeInt( Max( validSize.width, validSize.height ), Max( validSize.width, validSize.height) );

		if ( validSize != imageSize || eFormat != pImage->format() )
		{
			// image is the wrong size or format, make a copy so we don't modify the original..
			pImage = new Image( *pImage );

			if ( pImage->size() != validSize )
			{
				// image has to be resized - switch the format to an uncompressed format, DXT compression is too slow
				// to do on the fly..
				eFormat = findBestFormat( pDisplay, pImage, false );
				if ( eFormat != pImage->format() )
				{
					TRACE( CharString().format( "Image: Reformat %s -> %s", ColorFormat::formatText( pImage->format() ),
						ColorFormat::formatText( eFormat ) ) );
					if (! pImage->setFormat( eFormat ) )
						return NULL;
				}

				TRACE( CharString().format( "Image: Resize %dx%d -> %dx%d", imageSize.width, imageSize.height, 
					validSize.width, validSize.height ) );

				pImage->resample( validSize );
				if ( bMipMap && pImage->mipMap() != NULL )
					pImage->createMipMaps();
			}
			else if ( pImage->format() != eFormat )
			{
				TRACE( CharString().format( "Image: Reformat %s -> %s", ColorFormat::formatText( pImage->format() ),
					ColorFormat::formatText( eFormat ) ) );
				if (! pImage->setFormat( eFormat ) )
					return NULL;		// failed to convert to the desired format..
			}
		}

		if ( bMipMap && pImage->mipMap() == NULL )
			bMipMap = false;		// no mipmap levels in image, disable mipmaps

		// create the primitives, note having neither a diffuse or alpha texture is also a valid material
		pDisplay->create( pSurface );

		// create the surface
		SizeInt surfaceSize( pImage->size() );
		pSurface->initialize( 
			surfaceSize.width,
			surfaceSize.height, 
			eFormat,
			bMipMap );

		nFrame = nFrame % pImage->frameCount();

		Image * pMipMap = pImage;
		for(int i=0;i<pSurface->levels();++i)
		{
			if (! pMipMap )
			{
				TRACE( CharString().format("ERROR: Mipmap level %d is missing!", i ) );
				break;
			}

			void * pPixels = pSurface->lock( i );
			if (! pPixels )
			{
				TRACE( "ERROR: Failed to lock surface!" );
				break;
			}

			memcpy( pPixels, pMipMap->frame( nFrame ), pMipMap->frameSize( nFrame ) );
			pSurface->unlock();

			// next mipmap level of our image..
			pMipMap = pMipMap->mipMap();
		}
	}

	// cache the surface now
	lock.set( &sm_SurfaceHashLock );
	sm_SurfaceHash[ nKey ] = pSurface;
	return pSurface;
}
Пример #11
0
	bool isThisFormat(MemChunk& mc)
	{
		// Just check the size
		return validSize(mc.getSize());
	}