예제 #1
0
        protected override Array DecodeProper(byte[] bytes)
        {
            ValueMultiplicity vm = Tag.GetDictionaryEntry().VM;

            if (vm.Equals(1) || vm.IsUndefined)
            {
                if (bytes.Length % 2 != 0)
                {
                    throw new EncodingException(
                              "A value of multiple 2 bytes is only allowed.", Tag,
                              Name + "/value.Length", bytes.Length.ToString());
                }
                // TODO: Get allowed length from transfer syntax.
                ushort[] wordValue = new ushort[bytes.Length / 2];
                byte[]   buffer    = new byte[2];
                for (int i = 0; i < wordValue.Length; i++)
                {
                    Array.Copy(bytes, i * 2, buffer, 0, 2);
                    wordValue[i] = BitConverter.ToUInt16(
                        TransferSyntax.CorrectByteOrdering(buffer), 0);
                }
                return(new ushort[1][] { wordValue });
            }
            else
            {
                throw new EncodingException(
                          "Multiple values are not allowed within this field.", Tag,
                          Name + "/VM", vm.ToString());
            }
        }
예제 #2
0
 protected override Array DecodeImproper(byte[] bytes)
 {
     byte[][] multiValue = ToImproperMultiValue(bytes, 2);
     short[]  number     = new short[multiValue.Length];
     for (int i = 0; i < number.Length; i++)
     {
         number[i] = BitConverter.ToInt16(
             TransferSyntax.CorrectByteOrdering(multiValue[i]), 0);
     }
     return(number);
 }
예제 #3
0
 protected override Array DecodeImproper(byte[] bytes)
 {
     float[] floatValue = new float[(int)Math.Floor((double)bytes.Length / 4)];
     byte[]  buffer     = new byte[4];
     for (int i = 0; i < floatValue.Length; i++)
     {
         Array.Copy(bytes, i * 4, buffer, 0, 4);
         floatValue[i] = BitConverter.ToSingle(
             TransferSyntax.CorrectByteOrdering(buffer), 0);
     }
     return(new float[1][] { floatValue });
 }
예제 #4
0
 protected override Array DecodeImproper(byte[] bytes)
 {
     ushort[] wordValue = new ushort[(int)Math.Floor((double)bytes.Length / 2)];
     byte[]   buffer    = new byte[2];
     for (int i = 0; i < wordValue.Length; i++)
     {
         Array.Copy(bytes, i * 2, buffer, 0, 2);
         wordValue[i] = BitConverter.ToUInt16(
             TransferSyntax.CorrectByteOrdering(buffer), 0);
     }
     return(new ushort[1][] { wordValue });
 }
예제 #5
0
 protected override Array DecodeImproper(byte[] bytes)
 {
     byte[][] multiValue = ToImproperMultiValue(bytes, 4);
     Tag[]    tagValue   = new Tag[multiValue.Length];
     for (int i = 0; i < tagValue.Length; i++)
     {
         int group = TransferSyntax.CorrectByteOrdering(
             BitConverter.ToUInt16(multiValue[i], 0));
         int element = TransferSyntax.CorrectByteOrdering(
             BitConverter.ToUInt16(multiValue[i], 2));
         tagValue[i] = new Tag(group, element);
     }
     return(tagValue);
 }
예제 #6
0
 protected override Array DecodeProper(byte[] bytes)
 {
     byte[][] multiValue = ToProperMultiValue(bytes, 2);
     if (bytes.Length == 2 * multiValue.Length)
     {
         short[] number = new short[multiValue.Length];
         for (int i = 0; i < number.Length; i++)
         {
             number[i] = BitConverter.ToInt16(
                 TransferSyntax.CorrectByteOrdering(multiValue[i]), 0);
         }
         return(number);
     }
     else
     {
         throw new EncodingException(
                   "A value of multiple 2 bytes is only allowed.",
                   Tag, Name + "/value.Length", bytes.Length.ToString());
     }
 }
예제 #7
0
        protected override Array DecodeProper(byte[] bytes)
        {
            ValueMultiplicity vm = Tag.GetDictionaryEntry().VM;

            if (vm.Equals(1) || vm.IsUndefined)
            {
                if (bytes.Length % 4 != 0)
                {
                    throw new EncodingException(
                              "A value of multiple 4 bytes is only allowed.", Tag,
                              Name + "/value.Length", bytes.Length.ToString());
                }
                if (bytes.Length <= 0xFFFFFFB)
                {
                    float[] floatValue = new float[bytes.Length / 4];
                    byte[]  buffer     = new byte[4];
                    for (int i = 0; i < floatValue.Length; i++)
                    {
                        Array.Copy(bytes, i * 4, buffer, 0, 4);
                        floatValue[i] = BitConverter.ToSingle(
                            TransferSyntax.CorrectByteOrdering(buffer), 0);
                    }
                    return(new float[1][] { floatValue });
                }
                else
                {
                    throw new EncodingException(
                              "A value of max. 2^32 - 4 bytes is only allowed.",
                              Tag, Name + "/value.Length", bytes.Length.ToString());
                }
            }
            else
            {
                throw new EncodingException(
                          "Multiple values are not allowed within this field.",
                          Tag, Name + "/VM", vm.ToString());
            }
        }
예제 #8
0
 protected override Array DecodeProper(byte[] bytes)
 {
     byte[][] multiValue = ToProperMultiValue(bytes, 4);
     if (bytes.Length == 4 * multiValue.Length)
     {
         Tag[] tagValue = new Tag[multiValue.Length];
         for (int i = 0; i < tagValue.Length; i++)
         {
             int group = TransferSyntax.CorrectByteOrdering(
                 BitConverter.ToUInt16(multiValue[i], 0));
             int element = TransferSyntax.CorrectByteOrdering(
                 BitConverter.ToUInt16(multiValue[i], 2));
             tagValue[i] = new Tag(group, element);
         }
         return(tagValue);
     }
     else
     {
         throw new EncodingException(
                   "A value of multiple 4 bytes is only allowed.", Tag,
                   Name + "/value.Length", bytes.Length.ToString());
     }
 }