Browse Source

jpeg now preserves dpi

Former-commit-id: fcf404c9fede3784fd312aaba739185e12aba2d8
Former-commit-id: 08d5865cda85d173d37e895373cb110d6fa4b053
Former-commit-id: 1350e5c663eca447189095abfe5f8a316c5a970c
af/merge-core
James Jackson-South 10 years ago
parent
commit
ad2249bbec
  1. 2
      src/ImageProcessorCore/Formats/Jpg/JpegDecoderCore.cs.REMOVED.git-id
  2. 74
      src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs
  3. 4
      tests/ImageProcessorCore.Tests/Formats/Jpg/GeneralFormatTests.cs

2
src/ImageProcessorCore/Formats/Jpg/JpegDecoderCore.cs.REMOVED.git-id

@ -1 +1 @@
3ef7ce74c01efdb8145d6b3d03c937c862025a00 64d830f6c3b8d21e7c1d250c9ab513a24cd54923

74
src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs

@ -488,15 +488,10 @@ namespace ImageProcessorCore.Formats
int componentCount = 3; int componentCount = 3;
// Write the Start Of Image marker. // Write the Start Of Image marker.
double densityX = ((Image<T,TP>)image).HorizontalResolution; double densityX = ((Image<T, TP>)image).HorizontalResolution;
double densityY = ((Image<T, TP>)image).VerticalResolution; double densityY = ((Image<T, TP>)image).VerticalResolution;
//WriteApplicationHeader(densityX, densityY); WriteApplicationHeader((short)densityX, (short)densityY);
// TODO: JFIF header etc.
this.buffer[0] = 0xff;
this.buffer[1] = 0xd8;
stream.Write(this.buffer, 0, 2);
// Write the quantization tables. // Write the quantization tables.
this.WriteDQT(); this.WriteDQT();
@ -539,50 +534,41 @@ namespace ImageProcessorCore.Formats
/// <summary> /// <summary>
/// Writes the application header containing the Jfif identifier plus extra data. /// Writes the application header containing the Jfif identifier plus extra data.
/// </summary> /// </summary>
/// <param name="image">The image to encode from.</param> /// <param name="horizontalResolution">The resolution of the image in the x- direction.</param>
/// <param name="writer">The writer to write to the stream.</param> /// <param name="verticalResolution">The resolution of the image in the y- direction.</param>
private void WriteApplicationHeader(double horizontalResolution, double verticalResolution) private void WriteApplicationHeader(short horizontalResolution, short verticalResolution)
{ {
// Write the start of image marker. Markers are always prefixed with with 0xff. // Write the start of image marker. Markers are always prefixed with with 0xff.
this.buffer[0] = JpegConstants.Markers.XFF; this.buffer[0] = JpegConstants.Markers.XFF;
this.buffer[1] = JpegConstants.Markers.SOI; this.buffer[1] = JpegConstants.Markers.SOI;
this.outputStream.Write(this.buffer, 0, 2);
// Write the jfif headers
this.buffer[0] = JpegConstants.Markers.XFF;
this.buffer[0] = JpegConstants.Markers.APP0; // Application Marker
this.buffer[0] = JpegConstants.Markers.XFF;
this.buffer[0] = JpegConstants.Markers.XFF;
this.buffer[0] = JpegConstants.Markers.XFF;
this.buffer[0] = JpegConstants.Markers.XFF;
this.buffer[0] = JpegConstants.Markers.XFF;
byte[] jfif = { // Write the JFIF headers
JpegConstants.Markers.XFF, this.buffer[2] = JpegConstants.Markers.XFF;
JpegConstants.Markers.APP0, // Application Marker this.buffer[3] = JpegConstants.Markers.APP0; // Application Marker
0x00, this.buffer[4] = 0x00;
0x10, this.buffer[5] = 0x10;
0x4a, // J this.buffer[6] = 0x4a; // J
0x46, // F this.buffer[7] = 0x46; // F
0x49, // I this.buffer[8] = 0x49; // I
0x46, // F this.buffer[9] = 0x46; // F
0x00, // = "JFIF",'\0' this.buffer[10] = 0x00; // = "JFIF",'\0'
0x01, // versionhi this.buffer[11] = 0x01; // versionhi
0x01, // versionlo this.buffer[12] = 0x01; // versionlo
0x01, // xyunits as dpi this.buffer[13] = 0x01; // xyunits as dpi
};
// No thumbnail // No thumbnail
byte[] thumbnail = { this.buffer[14] = 0x00; // Thumbnail width
0x00, // Thumbnail width this.buffer[15] = 0x00; // Thumbnail height
0x00 // Thumbnail height
}; this.outputStream.Write(this.buffer, 0, 16);
// http://stackoverflow.com/questions/2188660/convert-short-to-byte-in-java // Resolution. Big Endian
//writer.Write(jfif); this.buffer[0] = (byte)(horizontalResolution >> 8);
//writer.Write((short)densityX); this.buffer[1] = (byte)horizontalResolution;
//writer.Write((short)densityY); this.buffer[2] = (byte)(verticalResolution >> 8);
//writer.Write(thumbnail); this.buffer[3] = (byte)verticalResolution;
this.outputStream.Write(this.buffer, 0, 4);
} }
/// <summary> /// <summary>

4
tests/ImageProcessorCore.Tests/Formats/Jpg/JpegFileTests.cs → tests/ImageProcessorCore.Tests/Formats/Jpg/GeneralFormatTests.cs

@ -1,4 +1,4 @@
// <copyright file="SamplerTests.cs" company="James Jackson-South"> // <copyright file="GeneralFormatTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -9,7 +9,7 @@ namespace ImageProcessorCore.Tests
using Xunit; using Xunit;
public class JpegFileTests : FileTestBase public class GeneralFormatTests : FileTestBase
{ {
[Fact] [Fact]
public void ResolutionShouldChange() public void ResolutionShouldChange()
Loading…
Cancel
Save