예제 #1
0
static unsigned long read(FT_Stream stream, unsigned long offset,
		unsigned char *buffer, unsigned long count) {
	G_FILE *fis = (G_FILE*) stream->descriptor.pointer;
	g_fseek(fis, offset, SEEK_SET);
	if (count == 0)
		return 0;
	return g_fread(buffer, 1, count, fis);
}
예제 #2
0
size_t gaudio_WavRead(g_id id, size_t size, void *data)
{
    GGWavHandle *handle = (GGWavHandle*)id;

    size_t size2 = size / handle->sampleSize;
    size_t remain = (handle->dataSize / handle->sampleSize) - gaudio_WavTell(id);

    return g_fread(data, handle->sampleSize, std::min(size2, remain), handle->fis) * handle->sampleSize;
}
예제 #3
0
파일: gideros.cpp 프로젝트: callcc/gideros
void ApplicationManager::loadProperties()
{
	G_FILE* fis = g_fopen("properties.bin", "rb");

	g_fseek(fis, 0, SEEK_END);
	int len = g_ftell(fis);
	g_fseek(fis, 0, SEEK_SET);

	std::vector<char> buf(len);
	g_fread(&buf[0], 1, len, fis);
	g_fclose(fis);

	ByteBuffer buffer(&buf[0], buf.size());

	buffer >> properties_.scaleMode;
	buffer >> properties_.logicalWidth;
	buffer >> properties_.logicalHeight;
	
	int scaleCount;
	buffer >> scaleCount;
	properties_.imageScales.resize(scaleCount);
	for (int i = 0; i < scaleCount; ++i)
	{
		buffer >> properties_.imageScales[i].first;
		buffer >> properties_.imageScales[i].second;
	}
	
	buffer >> properties_.orientation;
	buffer >> properties_.fps;
	buffer >> properties_.retinaDisplay;
	buffer >> properties_.autorotation;
	buffer >> properties_.mouseToTouch;
	buffer >> properties_.touchToMouse;
	buffer >> properties_.mouseTouchOrder;

	
	application_->setResolution(width_, height_);
	application_->setOrientation((Orientation)properties_.orientation);
	updateHardwareOrientation();
	application_->getApplication()->setDeviceOrientation(deviceOrientation_);
	application_->setLogicalDimensions(properties_.logicalWidth, properties_.logicalHeight);
	application_->setLogicalScaleMode((LogicalScaleMode)properties_.scaleMode);
	application_->setImageScales(properties_.imageScales);

	g_setFps(properties_.fps);
	
	ginput_setMouseToTouchEnabled(properties_.mouseToTouch);
	ginput_setTouchToMouseEnabled(properties_.touchToMouse);
	ginput_setMouseTouchOrder(properties_.mouseTouchOrder);
}
예제 #4
0
파일: Shaders.cpp 프로젝트: Nlcke/gideros
void *ShaderProgram::LoadShaderFile(const char *fname, const char *ext, long *len) {
	char name[256];
	sprintf(name, "%s.%s", fname,ext);
	G_FILE *f = g_fopen(name, "r");
	if (f) {
		g_fseek(f, 0, SEEK_END);
		long sz = g_ftell(f);
		if (len)
			*len = sz;
		void *fdata = malloc(sz+1);
		((char *)fdata)[sz]=0; //NUL TERMINATE
		g_fseek(f, 0, SEEK_SET);
		g_fread(fdata, 1, sz, f);
		g_fclose(f);
		return fdata;
	}
	return NULL;
}
예제 #5
0
static ssize_t mpg123read(void* fd, void* buf, size_t size)
{
	G_FILE* file = (G_FILE*)fd;
	return g_fread(buf, size, 1, file) * size;
}
예제 #6
0
g_id gaudio_WavOpen(const char *fileName, int *numChannels, int *sampleRate, int *bitsPerSample, int *numSamples, gaudio_Error *error)
{
    G_FILE *fis = g_fopen(fileName, "rb");
    if (fis == NULL)
    {
        if (error)
            *error = GAUDIO_CANNOT_OPEN_FILE;
        return 0;
    }

    GGWaveHeader header;
    if (g_fread(&header, sizeof(GGWaveHeader), 1, fis) != 1)
    {
        g_fclose(fis);
        if (error)
            *error = GAUDIO_UNRECOGNIZED_FORMAT;
        return 0;
    }

    if (header.chunkID != 0x46464952/*RIFF*/ || header.format != 0x45564157/*WAVE*/)
    {
        g_fclose(fis);
        if (error)
            *error = GAUDIO_UNRECOGNIZED_FORMAT;
        return 0;
    }

    // read "fmt " chunk
    GGFmtChunk format = {0};
    while (true)
    {
        GGChunkHeader chunk;
        if (g_fread(&chunk, sizeof(GGChunkHeader), 1, fis) != 1)
            break;

        if (chunk.chunkId == 0x20746D66/*fmt */)
        {
            if (g_fread(&format, sizeof(GGFmtChunk), 1, fis) != 1)
            {
                if (error)
                    *error = GAUDIO_ERROR_WHILE_READING;
                g_fclose(fis);
                return 0;
            }

            break;
        }

        g_fseek(fis, chunk.chunkSize, SEEK_CUR);
    }

    g_fseek(fis, sizeof(GGWaveHeader), SEEK_SET);

    // read "data" chunk
    unsigned int dataSize = 0;
    unsigned int dataPos = 0;
    while (true)
    {
        GGChunkHeader chunk;
        if (g_fread(&chunk, sizeof(GGChunkHeader), 1, fis) != 1)
            break;

        if (chunk.chunkId == 0x61746164/*data */)
        {
            dataPos = g_ftell(fis);
            dataSize = chunk.chunkSize;
            break;
        }

        g_fseek(fis, chunk.chunkSize, SEEK_CUR);
    }

    // data chunk is missing or zero sized
    if (dataPos == 0 || dataSize == 0)
    {
        if (error)
            *error = GAUDIO_UNRECOGNIZED_FORMAT;
        g_fclose(fis);
        return 0;
    }

    // only support PCM
    if (format.audioFormat != 1)
    {
        if (error)
            *error = GAUDIO_UNSUPPORTED_FORMAT;
        g_fclose(fis);
        return 0;
    }

    // only support 8 and 16 bits per sample
    if (format.bitsPerSample != 8 && format.bitsPerSample != 16)
    {
        if (error)
            *error = GAUDIO_UNSUPPORTED_FORMAT;
        g_fclose(fis);
        return 0;
    }

    g_fseek(fis, dataPos, SEEK_SET);

    // some writers put a bad blockAlign and/or byteRate value => recalculate them.
    format.blockAlign = (format.bitsPerSample / 8) * format.numChannels;
    format.byteRate = format.blockAlign * format.sampleRate;

    if (numChannels)
        *numChannels = format.numChannels;
    if (sampleRate)
        *sampleRate = format.sampleRate;
    if (bitsPerSample)
        *bitsPerSample = format.bitsPerSample;
    if (numSamples)
        *numSamples = dataSize / format.blockAlign;
    if (error)
        *error = GAUDIO_NO_ERROR;

    GGWavHandle *handle = new GGWavHandle();
    handle->fis = fis;
    handle->sampleSize = format.blockAlign;
    handle->dataPos = dataPos;
    handle->dataSize = dataSize;

    return (g_id)handle;
}