Skip to content

Commit 833c99a

Browse files
committed
Fix Black thumbnail when adding cover via scraping.
The `ThumbnailImage.CreateFrom` used when adding thumbnail via `AddCustomThumbnail` that the plugins uses. It would only work with the `ThumbnailResampling = FastBilinear`. These custom thumbnail are the only that support transparency and are saved in PNG format. The code that forced creating the alpha channel was moved out of the general resize code and inside only Billinear. So only that resampling would create a proper 32bit image.
1 parent 75d7f81 commit 833c99a

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

ComicRack.Engine/IO/ThumbnailImage.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ public static ThumbnailImage CreateFrom(Bitmap image, Size originalSize, bool su
151151
ThumbnailImage thumbnailImage;
152152
using (Image image2 = Scale(image, new Size(0, MaxHeight)))
153153
{
154-
thumbnailImage = ((!supportTransparent) ? new ThumbnailImage(image2.ImageToJpegBytes(ThumbnailQuality), image2.Size, originalSize) : new ThumbnailImage(image2.ImageToBytes(ImageFormat.Png), image2.Size, originalSize));
154+
thumbnailImage = supportTransparent
155+
? new ThumbnailImage(image2.ImageToBytes(ImageFormat.Png), image2.Size, originalSize)
156+
: new ThumbnailImage(image2.ImageToJpegBytes(ThumbnailQuality), image2.Size, originalSize);
155157
}
156158
if (lastRequestHeight != 0)
157159
{

cYo.Common/Drawing/ImageProcessing.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,11 @@ public unsafe static Bitmap ResizeFast(Bitmap source, int newWidth, int newHeigh
948948
byte* orgsrc = (byte*)srcData.Scan0.ToPointer();
949949
byte* orgdst = (byte*)dstData.Scan0.ToPointer();
950950

951-
switch (method)
951+
//Image has 4 bytesPerPixel (32 bit), so Add Alpha Channel
952+
if (dstPixelSize == 4)
953+
InitializeAlpha32(orgdst, newWidth, newHeight, dstStride);
954+
955+
switch (method)
952956
{
953957
case ResizeFastInterpolation.NearestNeighbor:
954958
// for each line
@@ -973,10 +977,6 @@ public unsafe static Bitmap ResizeFast(Bitmap source, int newWidth, int newHeigh
973977
break;
974978
case ResizeFastInterpolation.Bilinear:
975979
{
976-
//Image has 4 bytesPerPixel (32 bit), so Add Alpha Channel
977-
if (dstPixelSize == 4)
978-
InitializeAlpha32(orgdst, newWidth, newHeight, dstStride);
979-
980980
// Ref: https://github.com/andrewkirillov/AForge.NET/blob/master/Sources/Imaging/Filters/Transform/ResizeBilinear.cs#L78
981981
// width and height decreased by 1
982982
int ymax = height - 1;
@@ -1027,14 +1027,9 @@ public unsafe static Bitmap ResizeFast(Bitmap source, int newWidth, int newHeigh
10271027
}
10281028
case ResizeFastInterpolation.Bicubic:
10291029
{
1030-
// Zero-initialize entire buffer for accumulation
1031-
byte* initDst = orgdst;
1032-
for (int i = 0; i < newHeight * dstStride; i++)
1033-
*initDst++ = 0;
1034-
1035-
// Ref: https://github.com/andrewkirillov/AForge.NET/blob/master/Sources/Imaging/Filters/Transform/ResizeBicubic.cs#L79
1036-
// width and height decreased by 1
1037-
int ymax = height - 1;
1030+
// Ref: https://github.com/andrewkirillov/AForge.NET/blob/master/Sources/Imaging/Filters/Transform/ResizeBicubic.cs#L79
1031+
// width and height decreased by 1
1032+
int ymax = height - 1;
10381033
int xmax = width - 1;
10391034

10401035
Parallel.For(0, newHeight, (int y) =>

0 commit comments

Comments
 (0)