private bool MoveToNextHeader(StreamReaderHelper stream) { int blockLength = stream.GetWord(2, true); int headerMagic = stream.GetByte(0); int headerType = stream.GetByte(1); if (headerMagic == 0xff) { // EOI: last header. if (headerType == 0xd9) { return(false); } // Check for standalone markers. if (headerType == 0x01 || headerType >= 0xd0 && headerType <= 0xd7) { stream.CurrentOffset += 2; return(true); } // Now assume header with block size. stream.CurrentOffset += 2 + blockLength; return(true); } return(false); }
private bool TestColorFormatHeader(StreamReaderHelper stream, ImportedImage ii) { // The SOS header (start of scan). if (stream.GetWord(0, true) == 0xffda) { int components = stream.GetByte(4); if (components < 1 || components > 4 || components == 2) { return(false); } // 1 for grayscale, 3 for RGB, 4 for CMYK. int blockLength = stream.GetWord(2, true); // Integrity check: correct size? if (blockLength != 6 + 2 * components) { return(false); } // Eventually do more tests here. // Magic: we assume that all JPEG files with 4 components are RGBW (inverted CMYK) and not CMYK. // We add a test to tell CMYK from RGBW when we encounter a test file in CMYK format. ii.Information.ImageFormat = components == 3 ? ImageInformation.ImageFormats.JPEG : (components == 1 ? ImageInformation.ImageFormats.JPEGGRAY : ImageInformation.ImageFormats.JPEGRGBW); return(true); } return(false); }
private bool TestJfifHeader(StreamReaderHelper stream, ImportedImage ii) { // The App0 header should be the first header in every JFIF file. if (stream.GetWord(0, true) == 0xffe0) { // Now check for text "JFIF". if (stream.GetDWord(4, true) == 0x4a464946) { int blockLength = stream.GetWord(2, true); if (blockLength >= 16) { int version = stream.GetWord(9, true); int units = stream.GetByte(11); int densityX = stream.GetWord(12, true); int densityY = stream.GetWord(14, true); switch (units) { case 0: // Aspect ratio only. ii.Information.HorizontalAspectRatio = densityX; ii.Information.VerticalAspectRatio = densityY; break; case 1: // DPI. ii.Information.HorizontalDPI = densityX; ii.Information.VerticalDPI = densityY; break; case 2: // DPCM. ii.Information.HorizontalDPM = densityX * 100; ii.Information.VerticalDPM = densityY * 100; break; } // More information here? More tests? return(true); } } } return(false); }
private bool TestJfifHeader(StreamReaderHelper stream, ImportedImage ii) { // The App0 header should be the first header in every JFIF file. if (stream.GetWord(0, true) == 0xffe0) { // Now check for text "JFIF". if (stream.GetDWord(4, true) == 0x4a464946) { int blockLength = stream.GetWord(2, true); if (blockLength >= 16) { int version = stream.GetWord(9, true); int units = stream.GetByte(11); int densityX = stream.GetWord(12, true); int densityY = stream.GetWord(14, true); switch (units) { case 0: // Aspect ratio only. ii.Information.HorizontalAspectRatio = densityX; ii.Information.VerticalAspectRatio = densityY; break; case 1: // DPI. ii.Information.HorizontalDPI = densityX; ii.Information.VerticalDPI = densityY; break; case 2: // DPCM. ii.Information.HorizontalDPM = densityX * 100; ii.Information.VerticalDPM = densityY * 100; break; } // More information here? More tests? return true; } } } return false; }
private bool MoveToNextHeader(StreamReaderHelper stream) { int blockLength = stream.GetWord(2, true); int headerMagic = stream.GetByte(0); int headerType = stream.GetByte(1); if (headerMagic == 0xff) { // EOI: last header. if (headerType == 0xd9) return false; // Check for standalone markers. if (headerType == 0x01 || headerType >= 0xd0 && headerType <= 0xd7) { stream.CurrentOffset += 2; return true; } // Now assume header with block size. stream.CurrentOffset += 2 + blockLength; return true; } return false; }
private bool TestColorFormatHeader(StreamReaderHelper stream, ImportedImage ii) { // The SOS header (start of scan). if (stream.GetWord(0, true) == 0xffda) { int components = stream.GetByte(4); if (components < 1 || components > 4 || components == 2) return false; // 1 for grayscale, 3 for RGB, 4 for CMYK. int blockLength = stream.GetWord(2, true); // Integrity check: correct size? if (blockLength != 6 + 2 * components) return false; // Eventually do more tests here. // Magic: we assume that all JPEG files with 4 components are RGBW (inverted CMYK) and not CMYK. // We add a test to tell CMYK from RGBW when we encounter a test file in CMYK format. ii.Information.ImageFormat = components == 3 ? ImageInformation.ImageFormats.JPEG : (components == 1 ? ImageInformation.ImageFormats.JPEGGRAY : ImageInformation.ImageFormats.JPEGRGBW); return true; } return false; }