@@ -134,15 +134,15 @@ HBITMAP GetPSDThumbnail(IStream* stream) {
134134 int dataLength = width * height * 4 ;
135135 BYTE * data = new BYTE [dataLength];
136136
137+ for (int i = 0 ; i < dataLength; i++) {
138+ data[i] = 0xff ;
139+ }
140+
137141 if (compression == 1 ) {
138142 USHORT * lengths = new USHORT [channelCount * height];
139143 int step = 4 ;
140144 int maxLength = 0 ;
141145
142- for (int i = 0 ; i < dataLength; i++) {
143- data[i] = 0xff ;
144- }
145-
146146 for (int o = 0 , li = 0 ; o < channelCount; o++) {
147147 for (int y = 0 ; y < height; y++, li++) {
148148 lengths[li] = ReadUInt16 (stream);
@@ -191,7 +191,6 @@ HBITMAP GetPSDThumbnail(IStream* stream) {
191191 delete lengths;
192192 delete buffer;
193193 } else {
194- memset (data, 0xff , width * height * 4 );
195194 int pixels = width * height;
196195 BYTE * buffer = new BYTE [pixels];
197196 if (channelCount > 4 ) channelCount = 4 ;
@@ -208,45 +207,56 @@ HBITMAP GetPSDThumbnail(IStream* stream) {
208207 delete buffer;
209208 }
210209
211- if (width > 256 || height > 256 ) {
212- HBITMAP fullBitmap = CreateBitmap (width, height, 1 , 32 , data);
213- int thumbWidth, thumbHeight;
210+ bool allWhite = true ;
211+
212+ for (int i = 0 ; i < dataLength; i++) {
213+ if (data[i] != 0xff ) {
214+ allWhite = false ;
215+ break ;
216+ }
217+ }
218+
219+ if (!allWhite) {
220+ if (width > 256 || height > 256 ) {
221+ HBITMAP fullBitmap = CreateBitmap (width, height, 1 , 32 , data);
222+ int thumbWidth, thumbHeight;
214223
215- if (width > height) {
216- thumbWidth = 256 ;
217- thumbHeight = height * thumbWidth / width;
224+ if (width > height) {
225+ thumbWidth = 256 ;
226+ thumbHeight = height * thumbWidth / width;
227+ }
228+ else {
229+ thumbHeight = 256 ;
230+ thumbWidth = width * thumbHeight / height;
231+ }
232+
233+ BLENDFUNCTION fnc;
234+ fnc.BlendOp = AC_SRC_OVER ;
235+ fnc.BlendFlags = 0 ;
236+ fnc.SourceConstantAlpha = 0xFF ;
237+ fnc.AlphaFormat = AC_SRC_ALPHA ;
238+
239+ HDC dc = GetDC (NULL );
240+ HDC srcDC = CreateCompatibleDC (dc);
241+ HDC memDC = CreateCompatibleDC (dc);
242+ result = CreateCompatibleBitmap (dc, thumbWidth, thumbHeight);
243+ SelectObject (memDC, result);
244+ SelectObject (srcDC, fullBitmap);
245+
246+ RECT rect = {};
247+ rect.right = thumbWidth;
248+ rect.bottom = thumbHeight;
249+ FillRect (memDC, &rect, (HBRUSH )GetStockObject (NULL_BRUSH ));
250+ AlphaBlend (memDC, 0 , 0 , thumbWidth, thumbHeight, srcDC, 0 , 0 , width, height, fnc);
251+
252+ DeleteObject (fullBitmap);
253+ DeleteDC (srcDC);
254+ DeleteDC (memDC);
255+ ReleaseDC (NULL , dc);
218256 }
219257 else {
220- thumbHeight = 256 ;
221- thumbWidth = width * thumbHeight / height;
258+ result = CreateBitmap (width, height, 1 , 32 , data);
222259 }
223-
224- BLENDFUNCTION fnc;
225- fnc.BlendOp = AC_SRC_OVER ;
226- fnc.BlendFlags = 0 ;
227- fnc.SourceConstantAlpha = 0xFF ;
228- fnc.AlphaFormat = AC_SRC_ALPHA ;
229-
230- HDC dc = GetDC (NULL );
231- HDC srcDC = CreateCompatibleDC (dc);
232- HDC memDC = CreateCompatibleDC (dc);
233- result = CreateCompatibleBitmap (dc, thumbWidth, thumbHeight);
234- SelectObject (memDC, result);
235- SelectObject (srcDC, fullBitmap);
236-
237- RECT rect = {};
238- rect.right = thumbWidth;
239- rect.bottom = thumbHeight;
240- FillRect (memDC, &rect, (HBRUSH )GetStockObject (NULL_BRUSH ));
241- AlphaBlend (memDC, 0 , 0 , thumbWidth, thumbHeight, srcDC, 0 , 0 , width, height, fnc);
242-
243- DeleteObject (fullBitmap);
244- DeleteDC (srcDC);
245- DeleteDC (memDC);
246- ReleaseDC (NULL , dc);
247- }
248- else {
249- result = CreateBitmap (width, height, 1 , 32 , data);
250260 }
251261
252262 delete data;
0 commit comments