Exemplo n.º 1
0
// endian-swapping fread that dies if the expected amount cannot be read
size_t efread( void *buffer, size_t size, size_t num, FILE *stream )
{
	size_t num_read = fread(buffer, size, num, stream);
	
	switch (size)
	{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
		case 2:
			for (size_t i = 0; i < num; i++)
				((Uint16 *)buffer)[i] = SDL_Swap16(((Uint16 *)buffer)[i]);
			break;
		case 4:
			for (size_t i = 0; i < num; i++)
				((Uint32 *)buffer)[i] = SDL_Swap32(((Uint32 *)buffer)[i]);
			break;
		case 8:
			for (size_t i = 0; i < num; i++)
				((Uint64 *)buffer)[i] = SDL_Swap64(((Uint64 *)buffer)[i]);
			break;
#endif
		default:
			break;
	}
	
	if (num_read != num)
	{
		fprintf(stderr, "error: An unexpected problem occurred while reading from a file.\n");
		JE_tyrianHalt(1);
	}

	return num_read;
}
Exemplo n.º 2
0
/**
 *  Optimized 8 bit zoomer for resizing by a factor of 4. Doesn't flip.
 *  Used internally by _zoomSurfaceY() below.
 *  source and dest. widths must be multiples of 8 bytes for 64-bit access
 */
static int zoomSurface4X_64bit(SDL_Surface *src, SDL_Surface *dst)
{
	Uint64 dataSrc;
	Uint64 dataDst;
	Uint8 *pixelSrc = (Uint8*)src->pixels;
	Uint8 *pixelDstRow = (Uint8*)dst->pixels;
	int sx, sy;
	static bool proclaimed = false;
	
	if (!proclaimed)
	{
		proclaimed = true;
		Log(LOG_INFO) << "Using modestly fast 4X zoom routine.";
	}

	for (sy = 0; sy < src->h; ++sy, pixelDstRow += dst->pitch*4)
	{
		Uint8 *pixelDst = pixelDstRow;
	
		for (sx = 0; sx < src->w; sx += 8, pixelSrc += 8)
		{
			dataSrc = *((Uint64*) pixelSrc);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
			// boo
			SDL_Swap64(dataSrc);
#endif
			/* expanded form of of data shift:
			dataDst = (dataSrc & 0xFF) | ((dataSrc & 0xFF) << 8) | 
				((dataSrc & 0xFF) << 16 | ((datasrc & 0xFF) << 24) |
				((dataSrc & 0xFF00 ) << 24) | ((dataSrc & 0xFF00) << 32)  | 
				((dataSrc & 0xFF00 ) << 40) | ((dataSrc & 0xFF00) << 48) ;
				 */
			for (int i = 0; i < 4; ++i)
			{
				// compact form, combining terms with equal multipliers (shifts)
				dataDst = (dataSrc & 0xFF) | ((dataSrc & 0xFF) << 8) | 
					((dataSrc & 0xFF) << 16) | 
					((dataSrc & 0xFFFF ) << 24) | ((dataSrc & 0xFF00) << 32)  | 
					((dataSrc & 0xFF00 ) << 40) | ((dataSrc & 0xFF00) << 48) ;

				*((Uint64*)pixelDst) = dataDst;
				*((Uint64*)(pixelDst + dst->pitch)) = dataDst;
				*((Uint64*)(pixelDst + dst->pitch*2)) = dataDst;
				*((Uint64*)(pixelDst + dst->pitch*3)) = dataDst;
				pixelDst+=8; // forward 8 bytes!
				dataSrc >>= 16;
			}
		}
	}
	
	return 0;
}
Exemplo n.º 3
0
int64_t MessageIn::readInt64(const char *const str)
{
    int64_t value = -1;
    if (mPos + 8 <= mLength)
    {
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
        int64_t swap;
        memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int64_t));
        value = SDL_Swap64(swap);
#else
        memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int64_t));
#endif
    }
    DEBUGLOG2("readInt64:  " + toStringPrint(static_cast<unsigned int>(value)),
        mPos, str);
    mPos += 8;
    PacketCounters::incInBytes(8);
    return value;
}
Exemplo n.º 4
0
int64_t MessageIn::readInt64(const char *const str)
{
    int64_t value = -1;
    if (mPos + 8 <= mLength)
    {
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
        int64_t swap;
        memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int64_t));
        value = SDL_Swap64(swap);
#else  // SDL_BYTEORDER == SDL_BIG_ENDIAN

        memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int64_t));
#endif  // SDL_BYTEORDER == SDL_BIG_ENDIAN
    }
    DEBUGLOG2("readInt64:  " + toStringPrint(CAST_U32(value)),
        mPos, str);
    mPos += 8;
    PacketCounters::incInBytes(8);
    return value;
}
Exemplo n.º 5
0
// endian-swapping fread
size_t efread( void *buffer, size_t size, size_t num, FILE *stream )
{
	size_t f = fread(buffer, size, num, stream);
	
	switch (size)
	{
		case 2:
			for (size_t i = 0; i < num; i++)
				((Uint16 *)buffer)[i] = SDL_Swap16(((Uint16 *)buffer)[i]);
			break;
		case 4:
			for (size_t i = 0; i < num; i++)
				((Uint32 *)buffer)[i] = SDL_Swap32(((Uint32 *)buffer)[i]);
			break;
		case 8:
			for (size_t i = 0; i < num; i++)
				((Uint64 *)buffer)[i] = SDL_Swap64(((Uint64 *)buffer)[i]);
			break;
		default:
			break;
	}
	
	return f;
}