Fix reading of icon dir entries

This commit is contained in:
Kovid Goyal 2020-10-14 07:21:15 +05:30
parent 603991b2c0
commit d829a221db
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 4 deletions

View File

@ -13,7 +13,7 @@ from calibre.gui2 import must_use_qt
from calibre.utils.winreg.default_programs import split_commandline
from polyglot.builtins import filter
ICON_SIZE = 64
ICON_SIZE = 256
winutil = plugins['winutil'][0]
@ -61,7 +61,7 @@ def load_icon_resource_as_pixmap(icon_resource, size=ICON_SIZE):
q = size * size
for pmap in pixmaps:
if area(pmap) >= q:
if area(pmap) == size:
if area(pmap) == q:
return pmap
return pmap.scaled(size, size, aspectRatioMode=Qt.KeepAspectRatio, transformMode=Qt.SmoothTransformation)
return pixmaps[-1].scaled(size, size, aspectRatioMode=Qt.KeepAspectRatio, transformMode=Qt.SmoothTransformation)
@ -97,9 +97,10 @@ def display_image(png_data):
m = 1 if data else 0
cmd['m'] = m
sys.stdout.buffer.write(serialize_gr_command(cmd, chunk))
sys.stdout.flush()
sys.stdout.buffer.flush()
cmd.clear()
sys.stdout.flush()
write_chunked({'a': 'T', 'f': 100}, png_data)

View File

@ -781,10 +781,13 @@ load_library(PyObject *self, PyObject *args) {
return (PyObject*)Handle_create(h, ModuleHandle, PyTuple_GET_ITEM(args, 0));
}
#pragma pack( push )
#pragma pack( 2 )
typedef struct {
int count;
const wchar_t *resource_id;
} ResourceData;
#pragma pack( pop )
BOOL CALLBACK
@ -802,6 +805,8 @@ get_resource_id_for_index(HMODULE handle, const int index, LPCWSTR type = RT_GRO
return data.resource_id;
}
#pragma pack( push )
#pragma pack( 2 )
struct GRPICONDIRENTRY {
BYTE bWidth;
BYTE bHeight;
@ -812,6 +817,7 @@ struct GRPICONDIRENTRY {
DWORD dwBytesInRes;
WORD nID;
};
#pragma pack( pop )
static PyObject*
load_icon(PyObject *args, HMODULE handle, GRPICONDIRENTRY *entry) {
@ -827,7 +833,7 @@ load_icon(PyObject *args, HMODULE handle, GRPICONDIRENTRY *entry) {
if (!data) return NULL;
DWORD sz = SizeofResource(handle, res);
if (!sz) return NULL;
HICON icon = CreateIconFromResourceEx(data, sz, TRUE, 0x00030000, entry->bWidth, entry->bHeight, LR_DEFAULTCOLOR);
HICON icon = CreateIconFromResourceEx(data, sz, TRUE, 0x00030000, 0, 0, LR_DEFAULTCOLOR);
return Py_BuildValue("y#N", data, sz, Handle_create(icon, IconHandle));
}