Browse Source

WIP JFIF header

Former-commit-id: dd8bcac8f7d1170abb4796ae621e2a3409a1f2e3
Former-commit-id: f8f08b02228d80090537579c1581959ae4d03a9a
Former-commit-id: 7f62ae7e5dac7a5412233c7a229a905c13306351
pull/1/head
James Jackson-South 10 years ago
parent
commit
439509f3be
  1. 54
      src/ImageProcessorCore/Formats/Jpg/JpegEncoderCore.cs

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

@ -488,6 +488,11 @@ namespace ImageProcessorCore.Formats
int componentCount = 3;
// Write the Start Of Image marker.
double densityX = ((Image<T,TP>)image).HorizontalResolution;
double densityY = ((Image<T, TP>)image).VerticalResolution;
//WriteApplicationHeader(densityX, densityY);
// TODO: JFIF header etc.
this.buffer[0] = 0xff;
this.buffer[1] = 0xd8;
@ -531,6 +536,55 @@ namespace ImageProcessorCore.Formats
return -((-dividend + (divisor >> 1)) / divisor);
}
/// <summary>
/// Writes the application header containing the Jfif identifier plus extra data.
/// </summary>
/// <param name="image">The image to encode from.</param>
/// <param name="writer">The writer to write to the stream.</param>
private void WriteApplicationHeader(double horizontalResolution, double verticalResolution)
{
// Write the start of image marker. Markers are always prefixed with with 0xff.
this.buffer[0] = JpegConstants.Markers.XFF;
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 = {
JpegConstants.Markers.XFF,
JpegConstants.Markers.APP0, // Application Marker
0x00,
0x10,
0x4a, // J
0x46, // F
0x49, // I
0x46, // F
0x00, // = "JFIF",'\0'
0x01, // versionhi
0x01, // versionlo
0x01, // xyunits as dpi
};
// No thumbnail
byte[] thumbnail = {
0x00, // Thumbnail width
0x00 // Thumbnail height
};
// http://stackoverflow.com/questions/2188660/convert-short-to-byte-in-java
//writer.Write(jfif);
//writer.Write((short)densityX);
//writer.Write((short)densityY);
//writer.Write(thumbnail);
}
/// <summary>
/// Writes the Define Quantization Marker and tables.
/// </summary>

Loading…
Cancel
Save