Commit c05eef2e authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Merge the new-icon-factory-branch branch to HEAD.

2002-09-18  Alexander Larsson  <alexl@redhat.com>

	Merge the new-icon-factory-branch branch to HEAD.
parent 63f09083
2002-09-18 Alexander Larsson <alexl@redhat.com>
Merge the new-icon-factory-branch branch to HEAD.
2002-09-18 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/gnome-icon-lookup.c:
* libnautilus-private/nautilus-bookmark.c:
* src/file-manager/fm-desktop-icon-view.c:
Final icon naming.
2002-09-18 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-icon-factory.c:
Compile fixes for gnome-desktop head.
2002-09-17 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/gnome-icon-lookup.c:
Also look for generic mimetypes.
2002-09-17 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/gnome-icon-lookup.c:
Clean up #defines
2002-09-17 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/gnome-icon-lookup.c (gnome_icon_lookup):
Look up mime icons before file types.
2002-09-17 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/Makefile.am:
Added SYSCONFDIR.
Removed nautilus-find-icon-image.[ch]
* libnautilus-private/gnome-icon-lookup.c:
Add gif to gdk-pixbuf supported list.
* libnautilus-private/gnome-thumbnail.c:
Add gif to gdk-pixbuf supported list.
Thumbnailing scripts
Fix failed thumbnail directory creation
* libnautilus-private/nautilus-directory-async.c:
* libnautilus-private/nautilus-file-private.h:
* libnautilus-private/nautilus-file.c:
* libnautilus-private/nautilus-file.h:
* libnautilus-private/nautilus-icon-factory.c:
custom_icon_uri -> custom_icon
* libnautilus-private/nautilus-thumbnails.c:
Write failed files on thumbnail failure.
2002-09-13 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/gnome-thumbnail.[ch]:
const cleanups
Add gnome_thumbnail_has_uri.
* libnautilus-private/nautilus-icon-container.c:
* libnautilus-private/nautilus-icon-private.h:
Clean up TODOs
* libnautilus-private/nautilus-icon-factory-private.h:
Remove nautilus_icon_factory_remove_by_uri
* libnautilus-private/nautilus-icon-factory.c:
Disable self checks by default
Fix memory management of cache and fallback_icon
Remove nautilus_icon_factory_remove_by_uri
Clean up old code leftovers
Use "loading" icon while thumbnailing.
* libnautilus-private/nautilus-thumbnails.c:
Remove some old code
Reimplement nautilus_update_thumbnail_file_renamed and
nautilus_remove_thumbnail_for_file
2002-09-12 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/gnome-thumbnail-pixbuf-utils.c:
Add fast jpeg loading code.
* libnautilus-private/gnome-icon-lookup.[ch]:
Add GNOME_ICON_LOOKUP_FLAGS_SHOW_SMALL_IMAGES_AS_THEMSELVES flag.
* libnautilus-private/gnome-thumbnail.c:
Threadsafe GnomeThumbnailFactory
Use fast jpeg loader
cleanup
Thumbnail more image formats.
* libnautilus-private/nautilus-icon-container.c:
Don't scale wide but not very tall icons
* libnautilus-private/nautilus-icon-factory.[ch]:
Better handling of scaling with unknown base_size
Frame thumbnails
Add NAUTILUS_ICON_SIZE_THUMBNAIL
* libnautilus-private/nautilus-thumbnails.c:
Don't look for old framed thumbnails.
We changed thumbnailing system anyway.
2002-09-11 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/Makefile.am:
* libnautilus-private/gnome-icon-lookup.c:
* libnautilus-private/gnome-icon-lookup.h:
* libnautilus-private/gnome-thumbnail-pixbuf-utils.c:
* libnautilus-private/gnome-thumbnail.c:
* libnautilus-private/gnome-thumbnail.h:
New files. Destined for libgnomeui eventually.
* libnautilus-private/nautilus-icon-factory.c:
* libnautilus-private/nautilus-icon-factory.h:
* libnautilus-private/nautilus-thumbnails.c:
* libnautilus-private/nautilus-thumbnails.h:
Major rewrite of icon factory and thumbnailing code.
* libnautilus-private/nautilus-bookmark.c:
* libnautilus-private/nautilus-bookmark.h:
* libnautilus-private/nautilus-file-private.h:
* libnautilus-private/nautilus-file.c:
* libnautilus-private/nautilus-file.h:
* libnautilus-private/nautilus-icon-container.c:
* libnautilus-private/nautilus-icon-container.h:
* libnautilus-private/nautilus-icon-private.h:
* src/file-manager/fm-icon-container.c:
* src/nautilus-bookmark-list.c:
* src/nautilus-bookmark-parsing.c:
* src/nautilus-sidebar-title.c:
Use the new APIs
2002-09-15 Dave Camp <dave@ximian.com>
Fixes bug #88596.
......
......@@ -8,6 +8,7 @@ INCLUDES = \
$(CORE_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS) \
-DDATADIR=\""$(datadir)"\" \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
-DNAUTILUS_DATADIR=\""$(datadir)/nautilus"\" \
$(NULL)
......@@ -38,6 +39,11 @@ libnautilus_private_la_SOURCES = \
$(nautilus_metafile_server_idl_sources) \
eggtreemultidnd.c \
eggtreemultidnd.h \
gnome-icon-lookup.c \
gnome-icon-lookup.h \
gnome-thumbnail.c \
gnome-thumbnail.h \
gnome-thumbnail-pixbuf-utils.c \
nautilus-audio-player.c \
nautilus-audio-player.h \
nautilus-authn-manager.c \
......@@ -85,8 +91,6 @@ libnautilus_private_la_SOURCES = \
nautilus-file-utilities.h \
nautilus-file.c \
nautilus-file.h \
nautilus-find-icon-image.c \
nautilus-find-icon-image.h \
nautilus-global-preferences.c \
nautilus-global-preferences.h \
nautilus-horizontal-splitter.c \
......
/*
* gnome-thumbnail-pixbuf-utils.c: Utilities for handling pixbufs when thumbnailing
*
* Copyright (C) 2002 Red Hat, Inc.
*
* This file is part of the Gnome Library.
*
* The Gnome Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The Gnome Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with the Gnome Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Alexander Larsson <alexl@redhat.com>
*/
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <libgnomevfs/gnome-vfs-ops.h>
#include "gnome-thumbnail.h"
#define LOAD_BUFFER_SIZE 65536
GdkPixbuf * _gnome_thumbnail_load_scaled_jpeg (const char *uri,
int target_width,
int target_height);
GdkPixbuf *
gnome_thumbnail_load_pixbuf (const char *uri)
{
GnomeVFSResult result;
GnomeVFSHandle *handle;
char buffer[LOAD_BUFFER_SIZE];
GnomeVFSFileSize bytes_read;
GdkPixbufLoader *loader;
GdkPixbuf *pixbuf;
g_return_val_if_fail (uri != NULL, NULL);
result = gnome_vfs_open (&handle,
uri,
GNOME_VFS_OPEN_READ);
if (result != GNOME_VFS_OK) {
return NULL;
}
loader = gdk_pixbuf_loader_new ();
while (1) {
result = gnome_vfs_read (handle,
buffer,
sizeof (buffer),
&bytes_read);
if (result != GNOME_VFS_OK) {
break;
}
if (bytes_read == 0) {
break;
}
if (!gdk_pixbuf_loader_write (loader,
buffer,
bytes_read,
NULL)) {
result = GNOME_VFS_ERROR_WRONG_FORMAT;
break;
}
}
if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF) {
gdk_pixbuf_loader_close (loader, NULL);
g_object_unref (loader);
gnome_vfs_close (handle);
return NULL;
}
gnome_vfs_close (handle);
gdk_pixbuf_loader_close (loader, NULL);
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
if (pixbuf != NULL) {
g_object_ref (pixbuf);
}
g_object_unref (loader);
return pixbuf;
}
GdkPixbuf *
gnome_thumbnail_scale_down_pixbuf (GdkPixbuf *pixbuf,
int dest_width,
int dest_height)
{
int source_width, source_height;
int s_x1, s_y1, s_x2, s_y2;
int s_xfrac, s_yfrac;
int dx, dx_frac, dy, dy_frac;
div_t ddx, ddy;
int x, y;
int r, g, b, a;
int n_pixels;
gboolean has_alpha;
guchar *dest, *src, *xsrc, *src_pixels;
GdkPixbuf *dest_pixbuf;
int pixel_stride;
int source_rowstride, dest_rowstride;
if (dest_width == 0 || dest_height == 0) {
return NULL;
}
source_width = gdk_pixbuf_get_width (pixbuf);
source_height = gdk_pixbuf_get_height (pixbuf);
g_assert (source_width >= dest_width);
g_assert (source_height >= dest_height);
ddx = div (source_width, dest_width);
dx = ddx.quot;
dx_frac = ddx.rem;
ddy = div (source_height, dest_height);
dy = ddy.quot;
dy_frac = ddy.rem;
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
source_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
src_pixels = gdk_pixbuf_get_pixels (pixbuf);
dest_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, has_alpha, 8,
dest_width, dest_height);
dest = gdk_pixbuf_get_pixels (dest_pixbuf);
dest_rowstride = gdk_pixbuf_get_rowstride (dest_pixbuf);
pixel_stride = (has_alpha)?4:3;
s_y1 = 0;
s_yfrac = -dest_height/2;
while (s_y1 < source_height) {
s_y2 = s_y1 + dy;
s_yfrac += dy_frac;
if (s_yfrac > 0) {
s_y2++;
s_yfrac -= dest_height;
}
s_x1 = 0;
s_xfrac = -dest_width/2;
while (s_x1 < source_width) {
s_x2 = s_x1 + dx;
s_xfrac += dx_frac;
if (s_xfrac > 0) {
s_x2++;
s_xfrac -= dest_width;
}
/* Average block of [x1,x2[ x [y1,y2[ and store in dest */
r = g = b = a = 0;
n_pixels = 0;
src = src_pixels + s_y1 * source_rowstride + s_x1 * pixel_stride;
for (y = s_y1; y < s_y2; y++) {
xsrc = src;
if (has_alpha) {
for (x = 0; x < s_x2-s_x1; x++) {
n_pixels++;
r += xsrc[3] * xsrc[0];
g += xsrc[3] * xsrc[1];
b += xsrc[3] * xsrc[2];
a += xsrc[3];
xsrc += 4;
}
} else {
for (x = 0; x < s_x2-s_x1; x++) {
n_pixels++;
r += *xsrc++;
g += *xsrc++;
b += *xsrc++;
}
}
src += source_rowstride;
}
if (has_alpha) {
if (a != 0) {
*dest++ = r / a;
*dest++ = g / a;
*dest++ = b / a;
*dest++ = a / n_pixels;
} else {
*dest++ = 0;
*dest++ = 0;
*dest++ = 0;
*dest++ = 0;
}
} else {
*dest++ = r / n_pixels;
*dest++ = g / n_pixels;
*dest++ = b / n_pixels;
}
s_x1 = s_x2;
}
s_y1 = s_y2;
dest += dest_rowstride - dest_width * pixel_stride;
}
return dest_pixbuf;
}
#ifdef HAVE_LIBJPEG
#include <setjmp.h>
#include <stdio.h>
/* Workaround broken libjpeg defining these that may
* collide w/ the ones in config.h
*/
#undef HAVE_STDDEF_H
#undef HAVE_STDLIB_H
#include <jpeglib.h>
#include <libgnomevfs/gnome-vfs-types.h>
#include <libgnomevfs/gnome-vfs-ops.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#define BUFFER_SIZE 16384
typedef struct {
struct jpeg_source_mgr pub; /* public fields */
GnomeVFSHandle *handle;
JOCTET buffer[BUFFER_SIZE];
} Source;
typedef struct {
struct jpeg_error_mgr pub;
jmp_buf setjmp_buffer;
} ErrorHandlerData;
static void
fatal_error_handler (j_common_ptr cinfo)
{
ErrorHandlerData *data;
data = (ErrorHandlerData *) cinfo->err;
longjmp (data->setjmp_buffer, 1);
}
static void
output_message_handler (j_common_ptr cinfo)
{
/* If we don't supply this handler, libjpeg reports errors
* directly to stderr.
*/
}
static void
init_source (j_decompress_ptr cinfo)
{
}
static gboolean
fill_input_buffer (j_decompress_ptr cinfo)
{
Source *src;
GnomeVFSFileSize nbytes;
GnomeVFSResult result;
src = (Source *) cinfo->src;
result = gnome_vfs_read (src->handle,
src->buffer,
G_N_ELEMENTS (src->buffer),
&nbytes);
if (result != GNOME_VFS_OK || nbytes == 0) {
/* return a fake EOI marker so we will eventually terminate */
src->buffer[0] = (JOCTET) 0xFF;
src->buffer[1] = (JOCTET) JPEG_EOI;
nbytes = 2;
}
src->pub.next_input_byte = src->buffer;
src->pub.bytes_in_buffer = nbytes;
return TRUE;
}
static void
skip_input_data (j_decompress_ptr cinfo, long num_bytes)
{
Source *src;
src = (Source *) cinfo->src;
if (num_bytes > 0) {
while (num_bytes > (long) src->pub.bytes_in_buffer) {
num_bytes -= (long) src->pub.bytes_in_buffer;
fill_input_buffer (cinfo);
}
src->pub.next_input_byte += (size_t) num_bytes;
src->pub.bytes_in_buffer -= (size_t) num_bytes;
}
}
static void
term_source (j_decompress_ptr cinfo)
{
}
static void
vfs_src (j_decompress_ptr cinfo, GnomeVFSHandle *handle)
{
Source *src;
if (cinfo->src == NULL) { /* first time for this JPEG object? */
cinfo->src = &(g_new (Source, 1))->pub;
}
src = (Source *) cinfo->src;
src->pub.init_source = init_source;
src->pub.fill_input_buffer = fill_input_buffer;
src->pub.skip_input_data = skip_input_data;
src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
src->pub.term_source = term_source;
src->handle = handle;
src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
src->pub.next_input_byte = NULL; /* until buffer loaded */
}
static int
calculate_divisor (int width,
int height,
int target_width,
int target_height)
{
if (width/8 > target_width && height/8 > target_height) {
return 8;
}
if (width/4 > target_width && height/4 > target_height) {
return 4;
}
if (width/2 > target_width && height/2 > target_height) {
return 2;
}
return 1;
}
static void
free_buffer (guchar *pixels, gpointer data)
{
g_free (pixels);
}
GdkPixbuf *
_gnome_thumbnail_load_scaled_jpeg (const char *uri,
int target_width,
int target_height)
{
struct jpeg_decompress_struct cinfo;
ErrorHandlerData jerr;
GnomeVFSHandle *handle;
unsigned char *lines[1];
guchar * volatile buffer;
guchar * volatile pixels;
guchar *ptr;
GnomeVFSResult result;
unsigned int i;
result = gnome_vfs_open (&handle,
uri,
GNOME_VFS_OPEN_READ);
if (result != GNOME_VFS_OK) {
return NULL;
}
cinfo.err = jpeg_std_error (&jerr.pub);
jerr.pub.error_exit = fatal_error_handler;
jerr.pub.output_message = output_message_handler;
buffer = NULL;
pixels = NULL;
if (setjmp (jerr.setjmp_buffer)) {
/* Handle a JPEG error. */
jpeg_destroy_decompress (&cinfo);
gnome_vfs_close (handle);
g_free (buffer);
g_free (pixels);
return NULL;
}
jpeg_create_decompress (&cinfo);
vfs_src (&cinfo, handle);
jpeg_read_header (&cinfo, TRUE);
cinfo.scale_num = 1;
cinfo.scale_denom = calculate_divisor (cinfo.image_width,
cinfo.image_height,
target_width,
target_height);
cinfo.dct_method = JDCT_FASTEST;
cinfo.do_fancy_upsampling = FALSE;
jpeg_start_decompress (&cinfo);
pixels = g_malloc (cinfo.output_width * cinfo.output_height * 3);
ptr = pixels;
if (cinfo.num_components == 1) {
/* Allocate extra buffer for grayscale data */
buffer = g_malloc (cinfo.output_width);
lines[0] = buffer;
} else {
lines[0] = pixels;
}
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines (&cinfo, lines, 1);
if (cinfo.num_components == 1) {
/* Convert grayscale to rgb */
for (i = 0; i < cinfo.output_width; i++) {
ptr[i*3] = buffer[i];
ptr[i*3+1] = buffer[i];
ptr[i*3+2] = buffer[i];
}
ptr += cinfo.output_width * 3;
} else {
lines[0] += cinfo.output_width * 3;
}
}
g_free (buffer);
buffer = NULL;
jpeg_finish_decompress (&cinfo);
jpeg_destroy_decompress (&cinfo);
gnome_vfs_close (handle);
return gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, FALSE, 8,
cinfo.output_width,
cinfo.output_height,
cinfo.output_width * 3,
free_buffer, NULL);
}
#endif /* HAVE_LIBJPEG */
This diff is collapsed.
/*
* gnome-thumbnail.h: Utilities for handling thumbnails
*
* Copyright (C) 2002 Red Hat, Inc.
*
* This file is part of the Gnome Library.
*
* The Gnome Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* The Gnome Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with the Gnome Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Alexander Larsson <alexl@redhat.com>
*/
#ifndef GNOME_THUMBNAIL_H
#define GNOME_THUMBNAIL_H
#include <glib.h>
#include <glib-object.h>
#include <time.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
G_BEGIN_DECLS
typedef enum {
GNOME_THUMBNAIL_SIZE_NORMAL,
GNOME_THUMBNAIL_SIZE_LARGE,
} GnomeThumbnailSize;
#define GNOME_TYPE_THUMBNAIL_FACTORY (gnome_thumbnail_factory_get_type ())
#define GNOME_THUMBNAIL_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_THUMBNAIL_FACTORY, GnomeThumbnailFactory))
#define GNOME_THUMBNAIL_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_THUMBNAIL_FACTORY, GnomeThumbnailFactoryClass))
#define GNOME_IS_THUMBNAIL_FACTORY(obj) (G_TYPE_INSTANCE_CHECK_TYPE ((obj), GNOME_TYPE_THUMBNAIL_FACTORY))
#define GNOME_IS_THUMBNAIL_FACTORY_CLASS(klass) (G_TYPE_CLASS_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_THUMBNAIL_FACTORY))
typedef struct _GnomeThumbnailFactory GnomeThumbnailFactory;
typedef struct _GnomeThumbnailFactoryClass GnomeThumbnailFactoryClass;
typedef struct _GnomeThumbnailFactoryPrivate GnomeThumbnailFactoryPrivate;
struct _GnomeThumbnailFactory {
GObject parent;
GnomeThumbnailFactoryPrivate *priv;
};
struct _GnomeThumbnailFactoryClass {
GObjectClass parent;
};
GType gnome_thumbnail_factory_get_type (void);
GnomeThumbnailFactory *gnome_thumbnail_factory_new (GnomeThumbnailSize size);
char * gnome_thumbnail_factory_lookup (GnomeThumbnailFactory *factory,
const char *uri,
time_t mtime);
gboolean gnome_thumbnail_factory_has_valid_failed_thumbnail (GnomeThumbnailFactory *factory,
const char *uri,
time_t mtime);
gboolean gnome_thumbnail_factory_can_thumbnail (GnomeThumbnailFactory *factory,
const char *uri,
const char *mime_type,
time_t mtime);
GdkPixbuf * gnome_thumbnail_factory_generate_thumbnail (GnomeThumbnailFactory *factory,
const char *uri,
const char *mime_type);
void gnome_thumbnail_factory_save_thumbnail (GnomeThumbnailFactory *factory,
GdkPixbuf *thumbnail,
const char *uri,
time_t original_mtime);
void gnome_thumbnail_factory_create_failed_thumbnail (GnomeThumbnailFactory *factory,
const char *uri,
time_t mtime);
/* Thumbnailing utils: */
gboolean gnome_thumbnail_has_uri (GdkPixbuf *pixbuf,
const char *uri);
gboolean gnome_thumbnail_is_valid (GdkPixbuf *pixbuf,
const char *uri,
time_t mtime);
char * gnome_thumbnail_md5 (const char *uri);
char * gnome_thumbnail_path_for_uri (const char *uri,