[gdk-pixbuf] ico: Prefer entries with the largest dimensions
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdk-pixbuf] ico: Prefer entries with the largest dimensions
- Date: Wed, 14 Dec 2016 19:17:34 +0000 (UTC)
commit 91e2d7c80ebd21bce3a0f21741c8075eccc52235
Author: Bastien Nocera <hadess hadess net>
Date: Wed Dec 14 15:30:56 2016 +0100
ico: Prefer entries with the largest dimensions
Not the largest data size.
gdk-pixbuf/io-ico.c | 24 +++++++++++++++++-------
1 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/gdk-pixbuf/io-ico.c b/gdk-pixbuf/io-ico.c
index f5b0c6f..09087e9 100644
--- a/gdk-pixbuf/io-ico.c
+++ b/gdk-pixbuf/io-ico.c
@@ -209,9 +209,9 @@ static void DecodeHeader(guchar *Data, gint Bytes,
GError **error)
{
/* For ICO's we have to be very clever. There are multiple images possible
- in an .ICO. As a simple heuristic, we select the image which occupies the
- largest number of bytes.
- */
+ in an .ICO. As a simple heuristic, we select the image which is the largest
+ in pixels.
+ */
struct ico_direntry_data *entry;
gint IconCount = 0; /* The number of icon-versions in the file */
guchar *BIH; /* The DIB for the used icon */
@@ -275,29 +275,39 @@ static void DecodeHeader(guchar *Data, gint Bytes,
for (I=0;I<IconCount;I++) {
int width;
int height;
+ int depth;
int x_hot;
int y_hot;
- int data_size;
+ int data_size G_GNUC_UNUSED;
int data_offset;
width = Ptr[0];
height = Ptr[1];
+ depth = Ptr[2];
x_hot = (Ptr[5] << 8) + Ptr[4];
y_hot = (Ptr[7] << 8) + Ptr[6];
data_size = (Ptr[11] << 24) + (Ptr[10] << 16) + (Ptr[9] << 8) + (Ptr[8]);
data_offset = (Ptr[15] << 24) + (Ptr[14] << 16) + (Ptr[13] << 8) + (Ptr[12]);
- DEBUG(g_print ("Image %d: %d x %d\n\tPalette: %d\n", I, width, height, Ptr[2]);
+ DEBUG(g_print ("Image %d: %d x %d\n\tDepth: %d\n", I, width, height, depth);
if (imgtype == 2)
g_print ("\tHotspot: %d x %d\n", x_hot, y_hot);
else
g_print ("\tColor planes: %d\n\tBits per pixel: %d\n", x_hot, y_hot);
g_print ("\tSize: %d\n\tOffset: %d\n", data_size, data_offset);)
- entry = g_new0 (struct ico_direntry_data, 1);
- entry->ImageScore = data_size;
+ if (depth == 0)
+ depth = 32;
+ else if (depth <= 2)
+ depth = 1;
+ else if (depth <= 16)
+ depth = 4;
+ else if (depth <= 256)
+ depth = 8;
+ entry = g_new0 (struct ico_direntry_data, 1);
entry->width = width ? width : 256;
entry->height = height ? height : 256;
+ entry->ImageScore = entry->width * entry->height * depth;
entry->x_hot = x_hot;
entry->y_hot = y_hot;
entry->DIBoffset = data_offset;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]