예제 #1
0
void GImage::loadPng(const char* szFilename)
{
	size_t nSize;
	std::ifstream s;
	char* pBuf;
	s.exceptions(std::ios::badbit);
	try
	{
		// NB: we double copy the content of the file!
		// Once in a std::string and then to final destination
		// We do this so it will work with named pipes, which
		// do not permit seeking to the end of the file to determine
		// the file length.
		s.open(szFilename, std::ios::binary);
		std::stringstream buffer;
		buffer << s.rdbuf();
		std::string content = buffer.str();
		nSize = content.size();
		pBuf = new char[nSize];
		memcpy(pBuf, content.data(), nSize);
		s.close();
	}
	catch(const std::exception&)
	{
		throw Ex("Error while trying to open the file, ", szFilename, ". ", strerror(errno));
	}
	readPng(this, (const unsigned char*)pBuf, nSize);
	delete[] pBuf;
}
예제 #2
0
bool
PngScreen::fileToImage (CompString &name,
			CompSize   &size,
			int        &stride,
			void       *&data)
{
    bool          status = false;
    std::ifstream file;
    CompString    fileName = fileNameWithExtension (name);

    file.open (fileName.c_str ());
    if (file.is_open ())
    {
	status = readPng (file, size, data);
	file.close ();
    }

    if (status)
    {
	stride = size.width () * 4;
	return true;
    }

    return screen->fileToImage (name, size, stride, data);
}
예제 #3
0
static bool runPngTest(const char *const romfile, const bool forceDmg, const char *const pngfile) {
    gambatte::uint_least32_t framebuf[160 * 144];
    runTestRom(framebuf, romfile, forceDmg);

    gambatte::uint_least32_t pngbuf[160 * 144];
    readPng(pngbuf, pngfile);

    if (!frameBufsEqual(framebuf, pngbuf)) {
        std::printf("\nFAILED: %s %s\n", romfile, pngfile);
        return false;
    }

    return true;
}
예제 #4
0
    Texture2D::Texture2D(const string& relativePath){
        // 根据后缀判断
        auto postfix = GetPostfix(relativePath);
        transform(postfix.begin(),postfix.end(),postfix.begin(),tolower);
        auto fullpath = FileUtil::getInstacne()->getFullPath(relativePath);
      //  printf("fullpath:%s\n",fullpath.c_str());
        
        if (postfix == "png") {
            readPng(fullpath);
        }else if (postfix == "jpg" || postfix == "jpeg"){
            readJpeg(fullpath);
        }else{
            printf("can not support image formatter : %s\n",postfix.c_str());
        }

    }
Bool
readImageToTexture (CompScreen   *screen,
		    CompTexture  *texture,
		    char	 *imageFileName,
		    unsigned int *returnWidth,
		    unsigned int *returnHeight)
{
    char	 *data, *image;
    unsigned int width, height;
    int		 i;

    if (!readPng (imageFileName, &image, &width, &height))
    {
	fprintf (stderr, "%s: Failed to load image: %s\n",
		 programName, imageFileName);
	return FALSE;
    }

    data = malloc (4 * width * height);
    if (!data)
    {
	free (image);
	return FALSE;
    }

    for (i = 0; i < height; i++)
	memcpy (&data[i * width * 4],
		&image[(height - i - 1) * width * 4],
		width * 4);

    free (image);

    releasePixmapFromTexture (screen, texture);

    if (screen->textureNonPowerOfTwo ||
	(POWER_OF_TWO (width) && POWER_OF_TWO (height)))
    {
	texture->target = GL_TEXTURE_2D;
	texture->matrix.xx = 1.0f / width;
	texture->matrix.yy = -1.0f / height;
	texture->matrix.y0 = 1.0f;
    }
    else
    {
	texture->target = GL_TEXTURE_RECTANGLE_NV;
	texture->matrix.xx = 1.0f;
	texture->matrix.yy = -1.0f;
	texture->matrix.y0 = height;
    }

    if (!texture->name)
	glGenTextures (1, &texture->name);

    glBindTexture (texture->target, texture->name);

    glTexImage2D (texture->target, 0, GL_RGB, width, height, 0, GL_BGRA,

#if IMAGE_BYTE_ORDER == MSBFirst
		  GL_UNSIGNED_INT_8_8_8_8_REV,
#else
		  GL_UNSIGNED_BYTE,
#endif

		  data);

    texture->filter = COMP_TEXTURE_FILTER_FAST;

    glTexParameteri (texture->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri (texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    glTexParameteri (texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri (texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP);

    glBindTexture (texture->target, 0);

    free (data);

    *returnWidth = width;
    *returnHeight = height;

    return TRUE;
}