/// <summary> /// Function to determine if this codec can read the file or not. /// </summary> /// <param name="stream">Stream used to read the file information.</param> /// <returns> /// TRUE if the codec can read the file, FALSE if not. /// </returns> /// <exception cref="System.IO.IOException">Thrown when the <paramref name="stream"/> is write-only or if the stream cannot perform seek operations.</exception> /// <exception cref="System.IO.EndOfStreamException">Thrown when an attempt to read beyond the end of the stream is made.</exception> public override bool IsReadable(Stream stream) { TGAHeader header; long position = 0; if (stream == null) { throw new ArgumentNullException("stream"); } if (!stream.CanRead) { throw new IOException(Resources.GORGFX_STREAM_READ_ONLY); } if (!stream.CanSeek) { throw new IOException(Resources.GORGFX_STREAM_NO_SEEK); } if (stream.Length - stream.Position < DirectAccess.SizeOf <TGAHeader>()) { return(false); } try { position = stream.Position; var reader = new GorgonBinaryReader(stream, true); header = reader.ReadValue <TGAHeader>(); } finally { stream.Position = position; } if ((header.ColorMapType != 0) || (header.ColorMapLength != 0)) { return(false); } if ((header.Descriptor & (TGADescriptor.Interleaved2Way | TGADescriptor.Interleaved4Way)) != 0) { return(false); } if ((header.Width <= 0) || (header.Height <= 0)) { return(false); } if ((header.ImageType != TGAImageType.TrueColor) && (header.ImageType != TGAImageType.TrueColorRLE) && (header.ImageType != TGAImageType.BlackAndWhite) && (header.ImageType != TGAImageType.BlackAndWhiteRLE)) { return(false); } return(((header.ImageType != TGAImageType.BlackAndWhite) && (header.ImageType != TGAImageType.BlackAndWhiteRLE)) || (header.BPP == 8)); }
/// <summary> /// Initializes a new instance of the <see cref="GorgonChunkedFormat" /> class. /// </summary> /// <param name="stream">The stream to use to output the chunked data.</param> /// <param name="accessMode">Stream access mode for the chunk object.</param> /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="stream"/> parameter is NULL (Nothing in VB.Net).</exception> /// <exception cref="System.ArgumentException">Thrown when the <paramref name="accessMode"/> parameter is set to read, but the stream cannot be read. /// <para>-or-</para> /// <para>Thrown when the accessMode parameter is set to write, but the stream cannot be written.</para> /// <para>-or-</para> /// <para>Thrown if the stream can't perform seek operations.</para> /// </exception> protected GorgonChunkedFormat(Stream stream, ChunkAccessMode accessMode) { if (stream == null) { throw new ArgumentNullException("stream"); } ChunkAccessMode = accessMode; if (!stream.CanSeek) { throw new ArgumentException(Resources.GOR_STREAM_NOT_SEEKABLE, "stream"); } if (accessMode == ChunkAccessMode.Write) { if (!stream.CanWrite) { throw new ArgumentException(Resources.GOR_STREAM_IS_READONLY, "accessMode"); } Writer = new GorgonBinaryWriter(stream, true); } else { if (!stream.CanRead) { throw new ArgumentException(Resources.GOR_STREAM_IS_WRITEONLY, "accessMode"); } Reader = new GorgonBinaryReader(stream, true); } }
/// <summary> /// Initializes a new instance of the <see cref="GorgonChunkedFormat" /> class. /// </summary> /// <param name="stream">The stream to use to output the chunked data.</param> /// <param name="accessMode">Stream access mode for the chunk object.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="stream"/> parameter is NULL (Nothing in VB.Net).</exception> /// <exception cref="ArgumentException">Thrown when the <paramref name="accessMode"/> parameter is set to read, but the stream cannot be read. /// <para>-or-</para> /// <para>Thrown when the accessMode parameter is set to write, but the stream cannot be written.</para> /// <para>-or-</para> /// <para>Thrown if the stream can't perform seek operations.</para> /// </exception> protected GorgonChunkedFormat(Stream stream, ChunkAccessMode accessMode) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } ChunkAccessMode = accessMode; if (!stream.CanSeek) { throw new ArgumentException(Resources.GOR2DIO_ERR_STREAM_UNSEEKABLE, nameof(stream)); } if (accessMode == ChunkAccessMode.Write) { if (!stream.CanWrite) { throw new ArgumentException(Resources.GOR2DIO_ERR_STREAM_IS_READ_ONLY, nameof(accessMode)); } Writer = new GorgonBinaryWriter(stream, true); } else { if (!stream.CanRead) { throw new ArgumentException(Resources.GOR2DIO_ERR_STREAM_IS_WRITE_ONLY, nameof(accessMode)); } Reader = new GorgonBinaryReader(stream, true); } }