From 1b33bd67c484052002e3608e88df3d391aa622d8 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 2 Nov 2016 15:53:47 +1100 Subject: [PATCH] Make ComponentOrder agnostic Many color formats don't know what RGBA means. --- src/ImageSharp/Colors/Color.cs | 8 +-- src/ImageSharp/Colors/ComponentOrder.cs | 16 ++--- src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 6 +- src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 4 +- src/ImageSharp/Image/PixelAccessor.cs | 72 ++++++++++---------- src/ImageSharp/Image/PixelRow.cs | 8 +-- src/ImageSharp/PixelAccessor.cs | 8 +-- 7 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/ImageSharp/Colors/Color.cs b/src/ImageSharp/Colors/Color.cs index da0efc152..633a1c014 100644 --- a/src/ImageSharp/Colors/Color.cs +++ b/src/ImageSharp/Colors/Color.cs @@ -242,23 +242,23 @@ namespace ImageSharp { switch (componentOrder) { - case ComponentOrder.BGR: + case ComponentOrder.ZYX: bytes[startIndex] = this.B; bytes[startIndex + 1] = this.G; bytes[startIndex + 2] = this.R; break; - case ComponentOrder.BGRA: + case ComponentOrder.ZYXW: bytes[startIndex] = this.B; bytes[startIndex + 1] = this.G; bytes[startIndex + 2] = this.R; bytes[startIndex + 3] = this.A; break; - case ComponentOrder.RGB: + case ComponentOrder.XYZ: bytes[startIndex] = this.R; bytes[startIndex + 1] = this.G; bytes[startIndex + 2] = this.B; break; - case ComponentOrder.RGBA: + case ComponentOrder.XYZW: bytes[startIndex] = this.R; bytes[startIndex + 1] = this.G; bytes[startIndex + 2] = this.B; diff --git a/src/ImageSharp/Colors/ComponentOrder.cs b/src/ImageSharp/Colors/ComponentOrder.cs index aa3658c2f..7372ab9bf 100644 --- a/src/ImageSharp/Colors/ComponentOrder.cs +++ b/src/ImageSharp/Colors/ComponentOrder.cs @@ -11,23 +11,23 @@ namespace ImageSharp public enum ComponentOrder { /// - /// Blue-> Green-> Red order. + /// Z-> Y-> X order. Equivalent to B-> G-> R in /// - BGR, + ZYX, /// - /// Blue-> Green-> Red-> Alpha order. + /// Z-> Y-> X-> W order. Equivalent to B-> G-> R-> A in /// - BGRA, + ZYXW, /// - /// Red-> Green-> Blue order. + /// X-> Y-> Z order. Equivalent to R-> G-> B in /// - RGB, + XYZ, /// - /// Red-> Green-> Blue-> Alpha order. + /// X-> Y-> Z-> W order. Equivalent to R-> G-> B-> A in /// - RGBA, + XYZW, } } diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index cf4cbb812..6c390fa84 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -281,7 +281,7 @@ namespace ImageSharp.Formats const int ComponentCount = 2; TColor color = default(TColor); - using (PixelRow row = new PixelRow(width, ComponentOrder.RGB)) + using (PixelRow row = new PixelRow(width, ComponentOrder.XYZ)) { for (int y = 0; y < height; y++) { @@ -320,7 +320,7 @@ namespace ImageSharp.Formats where TPacked : struct { int padding = CalculatePadding(width, 3); - using (PixelRow row = new PixelRow(width, ComponentOrder.BGR, padding)) + using (PixelRow row = new PixelRow(width, ComponentOrder.ZYX, padding)) { for (int y = 0; y < height; y++) { @@ -346,7 +346,7 @@ namespace ImageSharp.Formats where TPacked : struct { int padding = CalculatePadding(width, 4); - using (PixelRow row = new PixelRow(width, ComponentOrder.BGRA, padding)) + using (PixelRow row = new PixelRow(width, ComponentOrder.ZYXW, padding)) { for (int y = 0; y < height; y++) { diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 1c1c71b33..8dab460d9 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -155,7 +155,7 @@ namespace ImageSharp.Formats where TColor : struct, IPackedPixel where TPacked : struct { - using (PixelRow row = new PixelRow(pixels.Width, ComponentOrder.BGRA, this.padding)) + using (PixelRow row = new PixelRow(pixels.Width, ComponentOrder.ZYXW, this.padding)) { for (int y = pixels.Height - 1; y >= 0; y--) { @@ -176,7 +176,7 @@ namespace ImageSharp.Formats where TColor : struct, IPackedPixel where TPacked : struct { - using (PixelRow row = new PixelRow(pixels.Width, ComponentOrder.BGR, this.padding)) + using (PixelRow row = new PixelRow(pixels.Width, ComponentOrder.ZYX, this.padding)) { for (int y = pixels.Height - 1; y >= 0; y--) { diff --git a/src/ImageSharp/Image/PixelAccessor.cs b/src/ImageSharp/Image/PixelAccessor.cs index dbdb82800..eec9b8cb2 100644 --- a/src/ImageSharp/Image/PixelAccessor.cs +++ b/src/ImageSharp/Image/PixelAccessor.cs @@ -148,17 +148,17 @@ namespace ImageSharp { switch (row.ComponentOrder) { - case ComponentOrder.BGR: - this.CopyFromBGR(row, targetY, Math.Min(row.Width, this.Width)); + case ComponentOrder.ZYX: + this.CopyFromZYX(row, targetY, Math.Min(row.Width, this.Width)); break; - case ComponentOrder.BGRA: - this.CopyFromBGRA(row, targetY, Math.Min(row.Width, this.Width)); + case ComponentOrder.ZYXW: + this.CopyFromZYXW(row, targetY, Math.Min(row.Width, this.Width)); break; - case ComponentOrder.RGB: - this.CopyFromRGB(row, targetY, Math.Min(row.Width, this.Width)); + case ComponentOrder.XYZ: + this.CopyFromXYZ(row, targetY, Math.Min(row.Width, this.Width)); break; - case ComponentOrder.RGBA: - this.CopyFromRGBA(row, targetY, Math.Min(row.Width, this.Width)); + case ComponentOrder.XYZW: + this.CopyFromXYZW(row, targetY, Math.Min(row.Width, this.Width)); break; default: throw new NotSupportedException(); @@ -177,17 +177,17 @@ namespace ImageSharp { switch (row.ComponentOrder) { - case ComponentOrder.BGR: - this.CopyToBGR(row, sourceY, Math.Min(row.Width, this.Width)); + case ComponentOrder.ZYX: + this.CopyToZYX(row, sourceY, Math.Min(row.Width, this.Width)); break; - case ComponentOrder.BGRA: - this.CopyToBGRA(row, sourceY, Math.Min(row.Width, this.Width)); + case ComponentOrder.ZYXW: + this.CopyToZYXW(row, sourceY, Math.Min(row.Width, this.Width)); break; - case ComponentOrder.RGB: - this.CopyToRGB(row, sourceY, Math.Min(row.Width, this.Width)); + case ComponentOrder.XYZ: + this.CopyToXYZ(row, sourceY, Math.Min(row.Width, this.Width)); break; - case ComponentOrder.RGBA: - this.CopyToRGBA(row, sourceY, Math.Min(row.Width, this.Width)); + case ComponentOrder.XYZW: + this.CopyToXYZW(row, sourceY, Math.Min(row.Width, this.Width)); break; default: throw new NotSupportedException(); @@ -224,12 +224,12 @@ namespace ImageSharp } /// - /// Copies from a row in format. + /// Copies from a row in format. /// /// The row. /// The target row index. /// The width. - protected virtual void CopyFromBGR(PixelRow row, int targetY, int width) + protected virtual void CopyFromZYX(PixelRow row, int targetY, int width) { byte* source = row.DataPointer; byte* destination = this.GetRowPointer(targetY); @@ -248,12 +248,12 @@ namespace ImageSharp } /// - /// Copies from a row in format. + /// Copies from a row in format. /// /// The row. /// The target row index. /// The width. - protected virtual void CopyFromBGRA(PixelRow row, int targetY, int width) + protected virtual void CopyFromZYXW(PixelRow row, int targetY, int width) { byte* source = row.DataPointer; byte* destination = this.GetRowPointer(targetY); @@ -272,12 +272,12 @@ namespace ImageSharp } /// - /// Copies from a row in format. + /// Copies from a row in format. /// /// The row. /// The target row index. /// The width. - protected virtual void CopyFromRGB(PixelRow row, int targetY, int width) + protected virtual void CopyFromXYZ(PixelRow row, int targetY, int width) { byte* source = row.DataPointer; byte* destination = this.GetRowPointer(targetY); @@ -296,12 +296,12 @@ namespace ImageSharp } /// - /// Copies from a row in format. + /// Copies from a row in format. /// /// The row. /// The target row index. /// The width. - protected virtual void CopyFromRGBA(PixelRow row, int targetY, int width) + protected virtual void CopyFromXYZW(PixelRow row, int targetY, int width) { byte* source = row.DataPointer; byte* destination = this.GetRowPointer(targetY); @@ -320,65 +320,65 @@ namespace ImageSharp } /// - /// Copies to a row in format. + /// Copies to a row in format. /// /// The row. /// The target row index. /// The width. - protected virtual void CopyToBGR(PixelRow row, int sourceY, int width) + protected virtual void CopyToZYX(PixelRow row, int sourceY, int width) { int offset = 0; for (int x = 0; x < width; x++) { - this[x, sourceY].ToBytes(row.Data, offset, ComponentOrder.BGR); + this[x, sourceY].ToBytes(row.Data, offset, ComponentOrder.ZYX); offset += 3; } } /// - /// Copies to a row in format. + /// Copies to a row in format. /// /// The row. /// The target row index. /// The width. - protected virtual void CopyToBGRA(PixelRow row, int sourceY, int width) + protected virtual void CopyToZYXW(PixelRow row, int sourceY, int width) { int offset = 0; for (int x = 0; x < width; x++) { - this[x, sourceY].ToBytes(row.Data, offset, ComponentOrder.BGRA); + this[x, sourceY].ToBytes(row.Data, offset, ComponentOrder.ZYXW); offset += 4; } } /// - /// Copies to a row in format. + /// Copies to a row in format. /// /// The row. /// The target row index. /// The width. - protected virtual void CopyToRGB(PixelRow row, int sourceY, int width) + protected virtual void CopyToXYZ(PixelRow row, int sourceY, int width) { int offset = 0; for (int x = 0; x < width; x++) { - this[x, sourceY].ToBytes(row.Data, offset, ComponentOrder.RGB); + this[x, sourceY].ToBytes(row.Data, offset, ComponentOrder.XYZ); offset += 3; } } /// - /// Copies to a row in format. + /// Copies to a row in format. /// /// The row. /// The target row index. /// The width. - protected virtual void CopyToRGBA(PixelRow row, int sourceY, int width) + protected virtual void CopyToXYZW(PixelRow row, int sourceY, int width) { int offset = 0; for (int x = 0; x < width; x++) { - this[x, sourceY].ToBytes(row.Data, offset, ComponentOrder.RGBA); + this[x, sourceY].ToBytes(row.Data, offset, ComponentOrder.XYZW); offset += 4; } } diff --git a/src/ImageSharp/Image/PixelRow.cs b/src/ImageSharp/Image/PixelRow.cs index 0eadfe090..fd5e14d4e 100644 --- a/src/ImageSharp/Image/PixelRow.cs +++ b/src/ImageSharp/Image/PixelRow.cs @@ -71,11 +71,11 @@ namespace ImageSharp { switch (componentOrder) { - case ComponentOrder.BGR: - case ComponentOrder.RGB: + case ComponentOrder.ZYX: + case ComponentOrder.XYZ: return 3; - case ComponentOrder.BGRA: - case ComponentOrder.RGBA: + case ComponentOrder.ZYXW: + case ComponentOrder.XYZW: return 4; } diff --git a/src/ImageSharp/PixelAccessor.cs b/src/ImageSharp/PixelAccessor.cs index f6e34b598..762bf3f43 100644 --- a/src/ImageSharp/PixelAccessor.cs +++ b/src/ImageSharp/PixelAccessor.cs @@ -23,7 +23,7 @@ namespace ImageSharp } /// - protected override void CopyFromBGR(PixelRow row, int targetY, int width) + protected override void CopyFromZYX(PixelRow row, int targetY, int width) { byte* source = row.DataPointer; byte* destination = this.GetRowPointer(targetY); @@ -38,7 +38,7 @@ namespace ImageSharp } /// - protected override void CopyFromBGRA(PixelRow row, int targetY, int width) + protected override void CopyFromZYXW(PixelRow row, int targetY, int width) { byte* source = row.DataPointer; byte* destination = this.GetRowPointer(targetY); @@ -53,7 +53,7 @@ namespace ImageSharp } /// - protected override void CopyToBGR(PixelRow row, int sourceY, int width) + protected override void CopyToZYX(PixelRow row, int sourceY, int width) { byte* source = this.GetRowPointer(sourceY); byte* destination = row.DataPointer; @@ -79,7 +79,7 @@ namespace ImageSharp } /// - protected override void CopyToBGRA(PixelRow row, int sourceY, int width) + protected override void CopyToZYXW(PixelRow row, int sourceY, int width) { byte* source = this.GetRowPointer(sourceY); byte* destination = row.DataPointer;