public string GetVersionDescription() { try { var bytes = Directory.GetByteArray(PhotoshopDirectory.TagVersion); if (bytes == null) { return(null); } var reader = new ByteArrayReader(bytes); var pos = 0; var ver = reader.GetInt32(0); pos += 4; pos++; var readerLength = reader.GetInt32(5); pos += 4; var readerStr = reader.GetString(9, readerLength * 2, Encoding.BigEndianUnicode); pos += readerLength * 2; var writerLength = reader.GetInt32(pos); pos += 4; var writerStr = reader.GetString(pos, writerLength * 2, Encoding.BigEndianUnicode); pos += writerLength * 2; var fileVersion = reader.GetInt32(pos); return($"{ver} ({readerStr}, {writerStr}) {fileVersion}"); } catch { return(null); } }
private static IEnumerable <Face> ParseFaces(byte[] bytes, int firstRecordOffset, int posOffset, int recordLength) { if (bytes == null) { yield break; } var reader = new ByteArrayReader(bytes, isMotorolaByteOrder: false); int faceCount = reader.GetUInt16(0); if (faceCount == 0 || bytes.Length < firstRecordOffset + faceCount * recordLength) { yield break; } posOffset += firstRecordOffset; for (int i = 0, recordOffset = firstRecordOffset; i < faceCount; i++, recordOffset += recordLength, posOffset += recordLength) { yield return(new Face( x: reader.GetUInt16(posOffset), y: reader.GetUInt16(posOffset + 2), width: reader.GetUInt16(posOffset + 4), height: reader.GetUInt16(posOffset + 6), name: recordLength == 44 ? reader.GetString(recordOffset, 20, Encoding.UTF8).Trim(' ', '\0') : null, age: recordLength == 44 ? Age.FromPanasonicString(reader.GetString(recordOffset + 28, 20, Encoding.UTF8).Trim(' ', '\0')) : null)); } }
public virtual string GetVersionDescription() { try { sbyte[] bytes = _directory.GetByteArray(PhotoshopDirectory.TagVersion); if (bytes == null) { return(null); } RandomAccessReader reader = new ByteArrayReader(bytes); int pos = 0; int ver = reader.GetInt32(0); pos += 4; pos++; int readerLength = reader.GetInt32(5); pos += 4; string readerStr = reader.GetString(9, readerLength * 2, "UTF-16"); pos += readerLength * 2; int writerLength = reader.GetInt32(pos); pos += 4; string writerStr = reader.GetString(pos, writerLength * 2, "UTF-16"); pos += writerLength * 2; int fileVersion = reader.GetInt32(pos); return(Sharpen.Extensions.StringFormat("%d (%s, %s) %d", ver, readerStr, writerStr, fileVersion)); } catch (IOException) { return(null); } }
public virtual Face[] GetRecognizedFaces() { sbyte[] bytes = GetByteArray(TagFaceRecognitionInfo); if (bytes == null) { return(null); } RandomAccessReader reader = new ByteArrayReader(bytes); reader.SetMotorolaByteOrder(false); try { int faceCount = reader.GetUInt16(0); if (faceCount == 0) { return(null); } Face[] faces = new Face[faceCount]; for (int i = 0; i < faceCount; i++) { int offset = 4 + i * 44; string name = Sharpen.Extensions.Trim(reader.GetString(offset, 20, "ASCII")); string age = Sharpen.Extensions.Trim(reader.GetString(offset + 28, 20, "ASCII")); faces[i] = new Face(reader.GetUInt16(offset + 20), reader.GetUInt16(offset + 22), reader.GetUInt16(offset + 24), reader.GetUInt16(offset + 26), name, Age.FromPanasonicString(age)); } return(faces); } catch (IOException) { return(null); } }
public virtual string GetSlicesDescription() { try { sbyte[] bytes = _directory.GetByteArray(PhotoshopDirectory.TagSlices); if (bytes == null) { return(null); } RandomAccessReader reader = new ByteArrayReader(bytes); int nameLength = reader.GetInt32(20); string name = reader.GetString(24, nameLength * 2, "UTF-16"); int pos = 24 + nameLength * 2; int sliceCount = reader.GetInt32(pos); //pos += 4; return(Sharpen.Extensions.StringFormat("%s (%d,%d,%d,%d) %d Slices", name, reader.GetInt32(4), reader.GetInt32(8), reader.GetInt32(12), reader.GetInt32(16), sliceCount)); } catch (IOException) { /*for (int i=0;i<sliceCount;i++){ * pos+=16; * int slNameLen=getInt32(b,pos); * pos+=4; * String slName=new String(b, pos, slNameLen*2,"UTF-16"); * res+=slName; * }*/ return(null); } }
public virtual void Extract(sbyte[] segmentBytes, Com.Drew.Metadata.Metadata metadata, JpegSegmentType segmentType) { if (segmentBytes == null) { throw new ArgumentNullException("segmentBytes cannot be null"); } if (metadata == null) { throw new ArgumentNullException("metadata cannot be null"); } if (segmentType == null) { throw new ArgumentNullException("segmentType cannot be null"); } try { ByteArrayReader reader = new ByteArrayReader(segmentBytes); // // Check for the header preamble // try { if (!reader.GetString(0, JpegExifSegmentPreamble.Length).Equals(JpegExifSegmentPreamble)) { // TODO what do to with this error state? System.Console.Error.Println("Invalid JPEG Exif segment preamble"); return; } } catch (IOException e) { // TODO what do to with this error state? Sharpen.Runtime.PrintStackTrace(e, System.Console.Error); return; } // // Read the TIFF-formatted Exif data // new TiffReader().ProcessTiff(reader, new ExifTiffHandler(metadata, _storeThumbnailBytes), JpegExifSegmentPreamble.Length); } catch (TiffProcessingException e) { // TODO what do to with this error state? Sharpen.Runtime.PrintStackTrace(e, System.Console.Error); } catch (IOException e) { // TODO what do to with this error state? Sharpen.Runtime.PrintStackTrace(e, System.Console.Error); } }
public string GetSlicesDescription() { try { var bytes = Directory.GetByteArray(PhotoshopDirectory.TagSlices); if (bytes == null) { return(null); } var reader = new ByteArrayReader(bytes); var nameLength = reader.GetInt32(20); var name = reader.GetString(24, nameLength * 2, Encoding.BigEndianUnicode); var pos = 24 + nameLength * 2; var sliceCount = reader.GetInt32(pos); return($"{name} ({reader.GetInt32(4)},{reader.GetInt32(8)},{reader.GetInt32(12)},{reader.GetInt32(16)}) {sliceCount} Slices"); } catch { return(null); } }
public void ProcessChunk(string fourCc, byte[] payload) { switch (fourCc) { case "strh": { string error = null; var reader = new ByteArrayReader(payload, isMotorolaByteOrder: false); string fccType = null; string fccHandler = null; float dwScale = 0; float dwRate = 0; int dwLength = 0; try { fccType = reader.GetString(0, 4, Encoding.ASCII); fccHandler = reader.GetString(4, 4, Encoding.ASCII); //int dwFlags = reader.GetInt32(8); //int wPriority = reader.GetInt16(12); //int wLanguage = reader.GetInt16(14); //int dwInitialFrames = reader.GetInt32(16); dwScale = reader.GetFloat32(20); dwRate = reader.GetFloat32(24); //int dwStart = reader.GetInt32(28); dwLength = reader.GetInt32(32); //int dwSuggestedBufferSize = reader.GetInt32(36); //int dwQuality = reader.GetInt32(40); //int dwSampleSize = reader.GetInt32(44); //byte[] rcFrame = reader.GetBytes(48, 2); } catch (IOException e) { error = "Exception reading AviRiff chunk 'strh' : " + e.Message; } var directory = new AviDirectory(); if (error == null) { if (fccType == "vids") { directory.Set(AviDirectory.TAG_FRAMES_PER_SECOND, (dwRate / dwScale)); double duration = dwLength / (dwRate / dwScale); int hours = (int)duration / (int)(Math.Pow(60, 2)); int minutes = ((int)duration / (int)(Math.Pow(60, 1))) - (hours * 60); int seconds = (int)Math.Round((duration / (Math.Pow(60, 0))) - (minutes * 60)); string time = new DateTime(2000, 1, 1, hours, minutes, seconds).ToString("hh:mm:ss"); directory.Set(AviDirectory.TAG_DURATION, time); directory.Set(AviDirectory.TAG_VIDEO_CODEC, fccHandler); } else if (fccType == "auds") { directory.Set(AviDirectory.TAG_SAMPLES_PER_SECOND, (dwRate / dwScale)); } } else { directory.AddError(error); } _directories.Add(directory); break; } case "avih": { string error = null; var reader = new ByteArrayReader(payload, isMotorolaByteOrder: false); int dwStreams = 0; int dwWidth = 0; int dwHeight = 0; try { //int dwMicroSecPerFrame = reader.GetInt32(0); //int dwMaxBytesPerSec = reader.GetInt32(4); //int dwPaddingGranularity = reader.GetInt32(8); //int dwFlags = reader.GetInt32(12); //int dwTotalFrames = reader.GetInt32(16); //int dwInitialFrames = reader.GetInt32(20); dwStreams = reader.GetInt32(24); //int dwSuggestedBufferSize = reader.GetInt32(28); dwWidth = reader.GetInt32(32); dwHeight = reader.GetInt32(36); //byte[] dwReserved = reader.GetBytes(40, 4); } catch (IOException e) { error = "Exception reading AviRiff chunk 'avih' : " + e.Message; } var directory = new AviDirectory(); if (error == null) { directory.Set(AviDirectory.TAG_WIDTH, dwWidth); directory.Set(AviDirectory.TAG_HEIGHT, dwHeight); directory.Set(AviDirectory.TAG_STREAMS, dwStreams); } else { directory.AddError(error); } _directories.Add(directory); break; } } }