Exemplo n.º 1
0
        /// <summary>
        /// Read the values of InteroperabilityIndex tag.
        /// Field description: Indicates the identification of the Interoperability rule.
        /// </summary>
        /// <param name="tagReader">The tag reader to use.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that fires if the user want to stop the current task.</param>
        /// <returns>A <see cref="ValueTask{TiffValueCollection}"/> that completes when the value of the tag is read and return the read values.</returns>
        public static ValueTask <string?> ReadInteroperabilityIndexAsync(this TiffTagReader tagReader, CancellationToken cancellationToken = default)
        {
            ValueTask <TiffValueCollection <string> > valueTask = tagReader.ReadASCIIFieldAsync((TiffTag)0x0001, cancellationToken);

            if (valueTask.IsCompletedSuccessfully)
            {
                TiffValueCollection <string> result = valueTask.GetAwaiter().GetResult();
                return(new ValueTask <string?>(result.GetFirstOrDefault()));
            }

            return(new ValueTask <string?>(TransformValueTaskAsync(valueTask)));
Exemplo n.º 2
0
 private static void DumpValueCollecionSimple <T>(TiffValueCollection <T> values)
 {
     Console.Write("[");
     if (values.IsEmpty)
     {
         // Do nothing
     }
     else if (values.Count == 1)
     {
         Console.Write(values.GetFirstOrDefault());
     }
     else
     {
         for (int i = 0; i < values.Count; i++)
         {
             Console.Write(values[i]);
             if (i != values.Count - 1)
             {
                 Console.Write(", ");
             }
         }
     }
     Console.Write("]");
 }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
            static async Task <string?> TransformValueTaskAsync(ValueTask <TiffValueCollection <string> > valueTask)
            {
                TiffValueCollection <string> result = await valueTask.ConfigureAwait(false);

                return(result.GetFirstOrDefault());
            }