+#include <stdio.h> /* for FILE etc */
+#include <stdlib.h> /* for malloc */
+#include <unistd.h> /* for unlink */
+#include <limits.h> /* for PATH_MAX */
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#define __USE_GNU /* for strcasestr */
+#include <string.h> /* for making ftw.h happy */
+
+#include <fcntl.h>
#include <limits.h>
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_rotozoom.h"
+#define __USE_GNU /* for strcasestr */
+#include <unistd.h> /* for unlink */
+#include <string.h> /* for making ftw.h happy */
+
#include "pnd_pxml.h"
#include "pnd_utility.h"
#include "pnd_conf.h"
mm_cache_t *g_icon_cache = NULL;
mm_cache_t *g_preview_cache = NULL;
-unsigned char cache_preview ( pnd_disco_t *app, unsigned char maxwidth, unsigned char maxheight ) {
+unsigned char cache_preview ( pnd_disco_t *app, unsigned int maxwidth, unsigned int maxheight ) {
SDL_Surface *s;
mm_cache_t *c;
return ( 0 );
}
- pnd_log ( pndn_debug, "Image size is %u x %u (max %u x %u)\n", s -> w, s -> h, maxwidth, maxheight );
+ //pnd_log ( pndn_debug, "Image size is %u x %u (max %u x %u)\n", s -> w, s -> h, maxwidth, maxheight );
// scale
if ( s -> w < maxwidth ) {
- SDL_Surface *scaled;
- double scale = (double)maxwidth / (double)s -> w;
- pnd_log ( pndn_debug, " Upscaling; scale factor %f\n", scale );
- scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
- SDL_FreeSurface ( s );
- s = scaled;
+ // scale up?
+ if ( pnd_conf_get_as_int_d ( g_conf, "previewpic.scale_up_bool", 1 ) ) {
+ SDL_Surface *scaled;
+ double scale = (double)maxwidth / (double)s -> w;
+ //pnd_log ( pndn_debug, " Upscaling; scale factor %f\n", scale );
+ scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
+ SDL_FreeSurface ( s );
+ s = scaled;
+ }
} else if ( s -> w > maxwidth ) {
SDL_Surface *scaled;
double scale = (double)maxwidth / (double)s -> w;
- pnd_log ( pndn_debug, " Downscaling; scale factor %f\n", scale );
+ //pnd_log ( pndn_debug, " Downscaling; scale factor %f\n", scale );
scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
SDL_FreeSurface ( s );
s = scaled;
// not cached, load it up
//
-
- // pull icon into buffer
+ unsigned char *iconbuf = NULL;
unsigned int buflen = 0;
- unsigned char *iconbuf;
- iconbuf = pnd_emit_icon_to_buffer ( app, &buflen );
+
+ // same-path override?
+ char ovrfile [ PATH_MAX ];
+ char *fixpxml;
+ sprintf ( ovrfile, "%s/%s", app -> object_path, app -> object_filename );
+ fixpxml = strcasestr ( ovrfile, PND_PACKAGE_FILEEXT );
+ if ( fixpxml ) {
+ strcpy ( fixpxml, ".png" );
+ struct stat statbuf;
+ if ( stat ( ovrfile, &statbuf ) == 0 ) {
+ buflen = statbuf.st_size;
+ if ( ( iconbuf = malloc ( statbuf.st_size ) ) ) {
+ int fd = open ( ovrfile, O_RDONLY );
+ if ( fd >= 0 ) {
+ if ( read ( fd, iconbuf, statbuf.st_size ) != statbuf.st_size ) {
+ free ( iconbuf );
+ close ( fd );
+ return ( 0 );
+ }
+ close ( fd );
+ } // open
+ } // malloc
+ } // stat
+ } // ovr?
+
+ // pull icon into buffer from .pnd
+ if ( ! iconbuf ) {
+ iconbuf = pnd_emit_icon_to_buffer ( app, &buflen );
+ }
if ( ! iconbuf ) {
return ( 0 );
free ( iconbuf ); // ditch the icon from ram
- pnd_log ( pndn_debug, "Image size is %u x %u (max %u x %u)\n", s -> w, s -> h, maxwidth, maxheight );
+ //pnd_log ( pndn_debug, "Image size is %u x %u (max %u x %u)\n", s -> w, s -> h, maxwidth, maxheight );
// scale the icon?
if ( s -> w < maxwidth ) {
- SDL_Surface *scaled;
- double scale = (double)maxwidth / (double)s -> w;
- pnd_log ( pndn_debug, " Upscaling; scale factor %f\n", scale );
- scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
- SDL_FreeSurface ( s );
- s = scaled;
+ // scale up?
+ if ( pnd_conf_get_as_int_d ( g_conf, "grid.scale_up_bool", 1 ) ) {
+ SDL_Surface *scaled;
+ double scale = (double)maxwidth / (double)s -> w;
+ //pnd_log ( pndn_debug, " Upscaling; scale factor %f\n", scale );
+ scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
+ SDL_FreeSurface ( s );
+ s = scaled;
+ }
} else if ( s -> w > maxwidth ) {
SDL_Surface *scaled;
double scale = (double)maxwidth / (double)s -> w;
- pnd_log ( pndn_debug, " Downscaling; scale factor %f\n", scale );
+ //pnd_log ( pndn_debug, " Downscaling; scale factor %f\n", scale );
scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
SDL_FreeSurface ( s );
s = scaled;