From 8189e8673335d2d4aa36bb21bb370fc136dd93b2 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 15 Mar 2016 21:30:13 +1100 Subject: [PATCH] Fix file encoding Former-commit-id: 94200cfe9279e3d20b99a9d9fa1a564547cdb801 Former-commit-id: 157766beec509e0122c5eceb61d564fda693e0ec Former-commit-id: 10b1c0e30d28d822905fa00e4127c07c9ad6ee04 --- src/ImageProcessorCore/Formats/Jpg/Block.cs | 2 +- src/ImageProcessorCore/Formats/Jpg/FDCT.cs | 2 +- src/ImageProcessorCore/Formats/Jpg/IDCT.cs | 2 +- .../Formats/Jpg/JpegDecoder.cs | 26 ++++++++----------- .../Formats/Jpg/JpegEncoderCore.cs | 2 +- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/ImageProcessorCore/Formats/Jpg/Block.cs b/src/ImageProcessorCore/Formats/Jpg/Block.cs index d70674779..655471a07 100644 --- a/src/ImageProcessorCore/Formats/Jpg/Block.cs +++ b/src/ImageProcessorCore/Formats/Jpg/Block.cs @@ -1,4 +1,4 @@ -namespace ImageProcessorCore.Formats +namespace ImageProcessorCore.Formats { internal class Block { diff --git a/src/ImageProcessorCore/Formats/Jpg/FDCT.cs b/src/ImageProcessorCore/Formats/Jpg/FDCT.cs index cc06f532c..a6073f9c7 100644 --- a/src/ImageProcessorCore/Formats/Jpg/FDCT.cs +++ b/src/ImageProcessorCore/Formats/Jpg/FDCT.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/src/ImageProcessorCore/Formats/Jpg/IDCT.cs b/src/ImageProcessorCore/Formats/Jpg/IDCT.cs index bf54bd71c..7542f4d38 100644 --- a/src/ImageProcessorCore/Formats/Jpg/IDCT.cs +++ b/src/ImageProcessorCore/Formats/Jpg/IDCT.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/src/ImageProcessorCore/Formats/Jpg/JpegDecoder.cs b/src/ImageProcessorCore/Formats/Jpg/JpegDecoder.cs index bfdcd2338..34e0932dc 100644 --- a/src/ImageProcessorCore/Formats/Jpg/JpegDecoder.cs +++ b/src/ImageProcessorCore/Formats/Jpg/JpegDecoder.cs @@ -97,13 +97,15 @@ namespace ImageProcessorCore.Formats JpegDecoderCore decoder = new JpegDecoderCore(); decoder.Decode(stream, image, false); - int pixelWidth = decoder.width; - int pixelHeight = decoder.height; - - float[] pixels = new float[pixelWidth * pixelHeight * 4]; - + // TODO: When nComp is 3 we set the ImageBase pixels internally, Eventually we should + // do the same here if (decoder.nComp == 1) { + int pixelWidth = decoder.width; + int pixelHeight = decoder.height; + + float[] pixels = new float[pixelWidth * pixelHeight * 4]; + Parallel.For( 0, pixelHeight, @@ -123,16 +125,10 @@ namespace ImageProcessorCore.Formats image.SetPixels(pixelWidth, pixelHeight, pixels); } - else if (decoder.nComp == 3) - { - // pixels = decoder.imgrgb.pixels; - } - else + else if (decoder.nComp != 3) { throw new NotSupportedException("JpegDecoder only supports RGB and Grayscale color spaces."); } - - //image.SetPixels(pixelWidth, pixelHeight, pixels); } /// @@ -161,9 +157,9 @@ namespace ImageProcessorCore.Formats { bool isExif = header[6] == 0x45 && // E - header[7] == 0x78 && // x - header[8] == 0x69 && // i - header[9] == 0x66 && // f + header[7] == 0x78 && // X + header[8] == 0x69 && // I + header[9] == 0x66 && // F header[10] == 0x00; return isExif; diff --git a/src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs b/src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs index fb04711d0..fa2d52152 100644 --- a/src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs +++ b/src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs @@ -1,4 +1,4 @@ -namespace ImageProcessorCore.Formats +namespace ImageProcessorCore.Formats { using System; using System.IO;