static Bool
pngFileToImage (CompDisplay *d,
		const char  *path,
		const char  *name,
		int	    *width,
		int	    *height,
		int	    *stride,
		void	    **data)
{
    Bool status = FALSE;
    char *extension = pngExtension (name);
    char *file;
    int  len;

    PNG_DISPLAY (d);

    len = (path ? strlen (path) : 0) + strlen (name) + strlen (extension) + 2;

    file = malloc (len);
    if (file)
    {
	FILE *fp;

	if (path)
	    sprintf (file, "%s/%s%s", path, name, extension);
	else
	    sprintf (file, "%s%s", name, extension);

	fp = fopen (file, "r");
	if (fp)
	{
	    status = readPngFileToImage (fp,
					 width,
					 height,
					 data);
	    fclose (fp);
	}

	free (file);

	if (status)
	{
	    *stride = *width * 4;
	    return TRUE;
	}
    }

    UNWRAP (pd, d, fileToImage);
    status = (*d->fileToImage) (d, path, name, width, height, stride, data);
    WRAP (pd, d, fileToImage, pngFileToImage);

    return status;
}
Exemplo n.º 2
0
        /*!

    Returns the standard icon for the given icon /a name
    as specified in the freedesktop icon spec
    http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html

    /a fallback is an optional argument to specify the icon to be used if
    no icon is found on the platform. This is particularily useful for
    crossplatform code.

*/
        QIcon QtIconLoader::icon(const QString &name)
{
    QIcon icon;

#ifdef QTOPIA
    return QIcon(":images/" + name + ".png");
#endif

#ifdef Q_WS_X11
#if QT_VERSION < 0x040600
    QString pngExtension(QLatin1String(".png"));
    QList<int> iconSizes;
    iconSizes << 16 << 22 << 24 << 32 << 48;
    Q_FOREACH (int size, iconSizes) {
        icon.addPixmap(iconLoaderInstance()->findIcon(size, name));
    }
static Bool
pngImageToFile (CompDisplay *d,
		const char  *path,
		const char  *name,
		const char  *format,
		int	    width,
		int	    height,
		int	    stride,
		void	    *data)
{
    Bool status = FALSE;
    char *extension = pngExtension (name);
    char *file;
    FILE *fp;
    int  len;

    PNG_DISPLAY (d);

    len = (path ? strlen (path) : 0) + strlen (name) + strlen (extension) + 2;

    file = malloc (len);
    if (file)
    {
	if (path)
	    sprintf (file, "%s/%s%s", path, name, extension);
	else
	    sprintf (file, "%s%s", name, extension);
    }

    if (file && strcasecmp (format, "png") == 0)
    {
	fp = fopen (file, "wb");
	if (fp)
	{
	    status = writePng (data, stdioWriteFunc, fp, width, height, stride);
	    fclose (fp);
	}

	if (status)
	{
	    free (file);
	    return TRUE;
	}
    }

    UNWRAP (pd, d, imageToFile);
    status = (*d->imageToFile) (d, path, name, format, width, height, stride,
				data);
    WRAP (pd, d, imageToFile, pngImageToFile);

    if (!status && file)
    {
	fp = fopen (file, "wb");
	if (fp)
	{
	    status = writePng (data, stdioWriteFunc, fp, width, height, stride);
	    fclose (fp);
	}
    }

    if (file)
	free (file);

    return status;
}