示例#1
0
        private static async Task DumpIfdEntryAsync(int index, TiffFieldReader fieldReader, TiffImageFileDirectoryEntry entry, CancellationToken cancellationToken)
        {
            string tagName  = Enum.IsDefined(typeof(TiffTag), entry.Tag) ? $"{entry.Tag} ({(int)entry.Tag})" : ((int)entry.Tag).ToString();
            string typeName = Enum.IsDefined(typeof(TiffFieldType), entry.Type) ? entry.Type.ToString() : "Unknown";

            Console.Write($"    Tag #{index}: {tagName}, {typeName}[{entry.ValueCount}].");

            switch (entry.Type)
            {
            case TiffFieldType.Byte:
                Console.Write(" Binary data not shown.");
                break;

            case TiffFieldType.ASCII:
                TiffValueCollection <string> valuesAscii = await fieldReader.ReadASCIIFieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                if (valuesAscii.IsEmpty)
                {
                    // Do nothing
                }
                else if (valuesAscii.Count == 1)
                {
                    Console.Write(" Value = " + valuesAscii.GetFirstOrDefault());
                }
                else
                {
                    Console.WriteLine();
                    for (int i = 0; i < valuesAscii.Count; i++)
                    {
                        Console.Write($"      [{i}] = {valuesAscii[i]}");
                    }
                }
                break;

            case TiffFieldType.Short:
                TiffValueCollection <ushort> valuesShort = await fieldReader.ReadShortFieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                DumpValueCollecion(valuesShort);
                break;

            case TiffFieldType.Long:
                TiffValueCollection <uint> valuesLong = await fieldReader.ReadLongFieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                DumpValueCollecion(valuesLong);
                break;

            case TiffFieldType.Rational:
                TiffValueCollection <TiffRational> valuesRational = await fieldReader.ReadRationalFieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                DumpValueCollecion(valuesRational);
                break;

            case TiffFieldType.SByte:
                Console.Write(" Binary data not shown.");
                break;

            case TiffFieldType.Undefined:
                Console.Write(" Binary data not shown.");
                break;

            case TiffFieldType.SShort:
                TiffValueCollection <short> valuesSShort = await fieldReader.ReadSShortFieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                DumpValueCollecion(valuesSShort);
                break;

            case TiffFieldType.SLong:
                TiffValueCollection <int> valuesSLong = await fieldReader.ReadSLongFieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                DumpValueCollecion(valuesSLong);
                break;

            case TiffFieldType.SRational:
                TiffValueCollection <TiffSRational> valuesSRational = await fieldReader.ReadSRationalFieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                DumpValueCollecion(valuesSRational);
                break;

            case TiffFieldType.Float:
                TiffValueCollection <float> valuesFloat = await fieldReader.ReadFloatFieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                DumpValueCollecion(valuesFloat);
                break;

            case TiffFieldType.Double:
                TiffValueCollection <double> valuesDouble = await fieldReader.ReadDoubleFieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                DumpValueCollecion(valuesDouble);
                break;

            case TiffFieldType.IFD:
                TiffValueCollection <TiffStreamOffset> valuesIfd = await fieldReader.ReadIFDFieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                DumpValueCollecion(valuesIfd);
                break;

            case TiffFieldType.Long8:
                TiffValueCollection <ulong> valuesLong8 = await fieldReader.ReadLong8FieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                DumpValueCollecion(valuesLong8);
                break;

            case TiffFieldType.SLong8:
                TiffValueCollection <long> valuesSLong8 = await fieldReader.ReadSLong8FieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                DumpValueCollecion(valuesSLong8);
                break;

            case TiffFieldType.IFD8:
                TiffValueCollection <TiffStreamOffset> valuesIfd8 = await fieldReader.ReadIFD8FieldAsync(entry, skipTypeValidation : true, cancellationToken : cancellationToken);

                DumpValueCollecion(valuesIfd8);
                break;

            default:
                Console.Write(" Unsupported field type.");
                break;
            }

            Console.WriteLine();
        }
示例#2
0
        private static async Task CopyFieldValueAsync(TiffFieldReader reader, TiffImageFileDirectoryEntry entry, TiffImageFileDirectoryWriter ifdWriter, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            switch (entry.Type)
            {
            case TiffFieldType.Byte:
                await ifdWriter.WriteTagAsync(entry.Tag, await reader.ReadByteFieldAsync(entry));

                break;

            case TiffFieldType.ASCII:
                await ifdWriter.WriteTagAsync(entry.Tag, await reader.ReadASCIIFieldAsync(entry));

                break;

            case TiffFieldType.Short:
                await ifdWriter.WriteTagAsync(entry.Tag, await reader.ReadShortFieldAsync(entry));

                break;

            case TiffFieldType.Long:
                await ifdWriter.WriteTagAsync(entry.Tag, await reader.ReadLongFieldAsync(entry));

                break;

            case TiffFieldType.Rational:
                await ifdWriter.WriteTagAsync(entry.Tag, await reader.ReadRationalFieldAsync(entry));

                break;

            case TiffFieldType.SByte:
                await ifdWriter.WriteTagAsync(entry.Tag, entry.Type, await reader.ReadByteFieldAsync(entry));

                break;

            case TiffFieldType.Undefined:
                await ifdWriter.WriteTagAsync(entry.Tag, entry.Type, await reader.ReadByteFieldAsync(entry));

                break;

            case TiffFieldType.SShort:
                await ifdWriter.WriteTagAsync(entry.Tag, await reader.ReadSShortFieldAsync(entry));

                break;

            case TiffFieldType.SLong:
                await ifdWriter.WriteTagAsync(entry.Tag, await reader.ReadSLongFieldAsync(entry));

                break;

            case TiffFieldType.SRational:
                await ifdWriter.WriteTagAsync(entry.Tag, await reader.ReadSRationalFieldAsync(entry));

                break;

            case TiffFieldType.Float:
                await ifdWriter.WriteTagAsync(entry.Tag, await reader.ReadFloatFieldAsync(entry));

                break;

            case TiffFieldType.Double:
                await ifdWriter.WriteTagAsync(entry.Tag, await reader.ReadDoubleFieldAsync(entry));

                break;

            case TiffFieldType.IFD:
                throw new NotSupportedException("This IFD type is not supported yet.");

            case TiffFieldType.Long8:
                await ifdWriter.WriteTagAsync(entry.Tag, await reader.ReadLong8FieldAsync(entry));

                break;

            case TiffFieldType.SLong8:
                await ifdWriter.WriteTagAsync(entry.Tag, await reader.ReadSLong8FieldAsync(entry));

                break;

            case TiffFieldType.IFD8:
                throw new NotSupportedException("This IFD type is not supported yet.");

            default:
                throw new NotSupportedException($"Unsupported IFD field type: {entry.Type}.");
            }
        }