From 18c4a7fef050d81df501b1dec3ac6b3081eb7e2f Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 14 Aug 2018 10:40:33 +0100 Subject: [PATCH] Fix 1 bit bmp decoding and add extra test images. --- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 4 +--- .../Formats/Bmp/BmpDecoderTests.cs | 5 +---- tests/ImageSharp.Tests/TestImages.cs | 20 +++++++++++++++++- tests/Images/Input/Bmp/pal1.bmp | Bin 0 -> 1086 bytes tests/Images/Input/Bmp/pal1p1.bmp | Bin 0 -> 1082 bytes tests/Images/Input/Bmp/pal4.bmp | Bin 0 -> 4198 bytes 6 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 tests/Images/Input/Bmp/pal1.bmp create mode 100644 tests/Images/Input/Bmp/pal1p1.bmp create mode 100644 tests/Images/Input/Bmp/pal4.bmp diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 128ae08542..d67beb0368 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -373,11 +373,9 @@ private void ReadRgbPalette(Buffer2D pixels, byte[] colors, int for (int x = 0; x < arrayWidth; x++) { int colOffset = x * ppb; - - for (int shift = 0; shift < ppb && (x + shift) < width; shift++) + for (int shift = 0, newX = colOffset; shift < ppb && newX < width; shift++, newX++) { int colorIndex = ((rowSpan[offset] >> (8 - bits - (shift * bits))) & mask) * 4; - int newX = colOffset + shift; // Stored in b-> g-> r order. rgba.Bgr = Unsafe.As(ref colors[colorIndex]); diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs index 09c3d1545f..5f2de9f51e 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs @@ -17,10 +17,7 @@ public class BmpDecoderTests { public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector; - public static readonly string[] AllBmpFiles = - { - Car, F, NegHeight, CoreHeader, V5Header, RLE, RLEInverted, Bit8, Bit8Inverted, Bit16, Bit16Inverted - }; + public static readonly string[] AllBmpFiles = All; public static readonly TheoryData RatioFiles = new TheoryData diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 142b923ed1..5eb70117e3 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -165,12 +165,30 @@ public static class Bmp public const string V5Header = "Bmp/BITMAPV5HEADER.bmp"; public const string RLE = "Bmp/RunLengthEncoded.bmp"; public const string RLEInverted = "Bmp/RunLengthEncoded-inverted.bmp"; + public const string Bit1 = "Bmp/pal1.bmp"; + public const string Bit1Pal1 = "Bmp/pal1p1.bmp"; + public const string Bit4 = "Bmp/pal4.bmp"; public const string Bit8 = "Bmp/test8.bmp"; public const string Bit8Inverted = "Bmp/test8-inverted.bmp"; public const string Bit16 = "Bmp/test16.bmp"; public const string Bit16Inverted = "Bmp/test16-inverted.bmp"; - public static readonly string[] All = { Car, F, NegHeight, CoreHeader, V5Header, RLE, RLEInverted, Bit8, Bit8Inverted, Bit16, Bit16Inverted }; + public static readonly string[] All + = { + Car, + F, + NegHeight, + CoreHeader, + V5Header, RLE, + RLEInverted, + Bit1, + Bit1Pal1, + Bit4, + Bit8, + Bit8Inverted, + Bit16, + Bit16Inverted + }; } public static class Gif diff --git a/tests/Images/Input/Bmp/pal1.bmp b/tests/Images/Input/Bmp/pal1.bmp new file mode 100644 index 0000000000000000000000000000000000000000..4776f827786ad054037baa9ae27e211332a5c596 GIT binary patch literal 1086 zcmbW0&uZI15XQ%nY(#59jS;9P7a2;cQ+vxPm{dOI(8H2bsB4<%ka{V?PvD+hY$#?8 z$piEv3I)GFjzW2Y)VJi2vi)XON=yGx=$PGs{ruZ+XLfaXbl{Q10p=$dDaHt+g`WiU z{(U7$a`h=w#_+oKc7*q&vL|{`AAd5{BjBY#PVJx z8GM%I8od5H@96*bkNEu7e~I|jAJ#g{|Kab%;;#{P{pg^r-_LbMl*QybP5rh!s{0q| zg}E8V^m)2jT7F<|U5|=4Qa}9XwCBdzcG~bEb=(#euT$B`(Q~I``P%;>bnvIrfB4Vy zcW&(e;92k8@e%g#uHZkRd)7askok#hkJ1-rw|bgwQ**gquW^3^vvd1Jk(wR`Xdf>RPZjsmLkTaT+rag2 zuq^LSGL5SwQ6(Xd5a1D;r4-me zc-;AK{_3JM><>J_^K1A!e|4Nfw>;S}!KnMmvd0}n{hKex!cL1pv1*0J_8UiCV1OO{s1F--A literal 0 HcmV?d00001 diff --git a/tests/Images/Input/Bmp/pal4.bmp b/tests/Images/Input/Bmp/pal4.bmp new file mode 100644 index 0000000000000000000000000000000000000000..7fd36303caea2b0aaf12469efee44ecd3cdbb5fa GIT binary patch literal 4198 zcmbW2u}|Yj6vhX00z$4x#6Mu!Alak|pe<0ERg?~0gOrLURYXaLsLt8~g{3iB2{uZz zqJ$HVAUE<4^TaA4ENfxqR^1Hi-8htmG78Olips)9W;Oll3{}cj?yzhV7>i0dT(&Y6f za-)oZU4LR|8nWIsZMU5f==T-gl29V@ekBli+ra1ikxv22`h9N;_&)H^ExN3B3;5ex zyFQ0MIkEb4_`^fhAC)SwfUoLT_>z9#dtZM8eK7yrsuaw`B_2Tab{9kx4qXPc7{cq!c41t6V`20q{9E3Lc-Q9!@I4}FJLHI(H`fYNqIO7yfG02;&G*kOPRl-f3~il7uG9&ZIa=?r$4~5SN>=CqV^a13-6@{ zf}a^6`qx#T;D_j+OeT`H`rr4zf&MnzZ;bv@{Y^Y(*_d50Q2)^{Zz7y=ISTz~5&d?K zz-tvNfa-rf$?%(H z6O*P)Q2lv|A0+c|8;wSrK!38(4}Zl+weU_&w9ubQu82ZE_zV54P<-z8ucV)Mt8!5< z{x{kU^eX|t*1KNUOT<6XU!TQr$i+jz z>bLNse;s(wW8fqvNBff@RK=(sOVoZOJ>>ez0eEo{+E{dZ#1ym>WJFTOB2zUr^){Fg*BH~%`fzJqJ z`XONR^Le4%)?lIE4_mFv`}@rzTCLV}I#vA;2mYLe;C&c6`&Pych}_8vDOu(5&qJ@iAM zw`tqK=0PiMrPCnb=lyHg+0U?W^{;@k8>E zq|d!>ulrM4A}xIy4$cSH(RK8F{Fpo@>6`s8_)1`Z5C2Q}2feEPixK{#KRbXyi25*a zn-JIm{u}TQ5a>am2mDXq>F^(%p9B9L_(upNYJ`}jz0i;U75xfd(vSad^#|y0?liA< ju67>20smn6|LoB;q<-ha>+|dL$M3*DrfIqOjN^X*G&$+8 literal 0 HcmV?d00001