Skip to content

Commit 200a78a

Browse files
committed
Fix reading composite image with alpha channel
1 parent 12ba451 commit 200a78a

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

PsdThumbnailProvider/GetThumbnail.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ UINT ReadUInt32(IStream *pStream) {
2323
return b[0] << 24 | b[1] << 16 | b[2] << 8 | b[3];
2424
}
2525

26+
SHORT ReadInt16(IStream *pStream) {
27+
BYTE b[2];
28+
ReadData(pStream, b, 2);
29+
return b[0] << 8 | b[1];
30+
}
31+
2632
USHORT ReadUInt16(IStream *pStream) {
2733
BYTE b[2];
2834
ReadData(pStream, b, 2);
@@ -104,8 +110,8 @@ HBITMAP GetPSDThumbnail(IStream* stream) {
104110
UINT layerAndMastInfoOffset = Tell(stream);
105111

106112
UINT layerInfoLength = ReadUInt32(stream);
107-
USHORT layerCount = ReadUInt16(stream);
108-
bool globalAlpha = layerAndMaskInfoLength < 0;
113+
SHORT layerCount = ReadInt16(stream);
114+
bool globalAlpha = layerCount < 0;
109115

110116
Seek(stream, layerAndMastInfoOffset + layerAndMaskInfoLength, STREAM_SEEK_SET);
111117

@@ -168,13 +174,13 @@ HBITMAP GetPSDThumbnail(IStream* stream) {
168174

169175
for (int j = 0; j <= header; j++) {
170176
data[p] = value;
171-
p = (p + step);
177+
p += step;
172178
}
173179
}
174180
else { // header < 128
175181
for (int j = 0; j <= header; j++) {
176182
data[p] = buffer[++i];
177-
p = (p + step);
183+
p += step;
178184
}
179185
}
180186
}
@@ -188,11 +194,11 @@ HBITMAP GetPSDThumbnail(IStream* stream) {
188194

189195
if (width > height) {
190196
thumbWidth = 256;
191-
thumbHeight = floor(height * thumbWidth / width);
197+
thumbHeight = height * thumbWidth / width;
192198
}
193199
else {
194200
thumbHeight = 256;
195-
thumbWidth = floor(width * thumbHeight / height);
201+
thumbWidth = width * thumbHeight / height;
196202
}
197203

198204
BLENDFUNCTION fnc;

Test/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LRESULT CALLBACK windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
99
switch (message) {
1010
case WM_CREATE: {
1111
IStream* stream;
12-
SHCreateStreamOnFileEx(L"test3.psd", STGM_READ, FILE_ATTRIBUTE_NORMAL, false, NULL, &stream);
12+
SHCreateStreamOnFileEx(L"test4.psd", STGM_READ, FILE_ATTRIBUTE_NORMAL, false, NULL, &stream);
1313
bitmap = GetPSDThumbnail(stream);
1414
BITMAP bm = {};
1515
GetObject(bitmap, sizeof(bm), &bm);

0 commit comments

Comments
 (0)