public override void Write(uint value)
 {
     if (swapped)
     {
         base.Write(MSBSwapper.SwapDW(value));
     }
     else
     {
         base.Write(value);
     }
 }
 public override uint ReadUInt32()
 {
     if (swapped)
     {
         return(MSBSwapper.SwapDW(base.ReadUInt32()));
     }
     else
     {
         return(base.ReadUInt32());
     }
 }
 public override void Write(float value)
 {
     //RxIMP: See if there's a less retarded way to do this
     if (swapped)
     {
         base.Write(MSBSwapper.SwapDW(BitConverter.ToUInt32(BitConverter.GetBytes(value), 0)));
     }
     else
     {
         base.Write(value);
     }
 }
 public override float ReadSingle()
 {
     //RxIMP: See if there's a less retarded way to do this
     if (swapped)
     {
         return(BitConverter.ToSingle(BitConverter.GetBytes(MSBSwapper.SwapDW(base.ReadUInt32())), 0));
     }
     else
     {
         return(base.ReadSingle());
     }
 }
Exemplo n.º 5
0
        internal override uint ParseData(SwappableBinaryReader br, ILogger logger, uint length, TransferSyntax transferSyntax)
        {
            //Covered by PS 3.5, Chapter 7.5 (pg. 42-45)
            bool encapImage = (Tag == DICOMTags.PixelData);

            bool done  = false;
            uint count = 0;

            while (!done)
            {
                //If explicit length, see if we're done
                if (length != 0xFFFFFFFF && count >= length)
                {
                    done = true;
                    continue;
                }

                ushort grp  = br.ReadUInt16();
                ushort elem = br.ReadUInt16();
                uint   len  = br.ReadUInt32();
                count += 8;

                //Sometimes there's retarded files that are msb swapped inside of sequences outside of the transfer syntax
                bool needMoreSwap = (grp == 0xFEFF);

                if (needMoreSwap)
                {
                    //Swap the reader for now, then swap back after the sqitem
                    br.ToggleSwapped();

                    //still have to swap the stuff we've already read by hand tho
                    grp  = MSBSwapper.SwapW(grp);
                    elem = MSBSwapper.SwapW(elem);
                    len  = MSBSwapper.SwapDW(len);
                }

                if (grp == 0xFFFE && elem == 0xE000)
                {
                    //Normal element, parse it out.
                    SQItem item = new SQItem(this);
                    count += item.ParseStream(br, logger, transferSyntax, len, encapImage);
                    Items.Add(item);
                }
                else if (grp == 0xFFFE && elem == 0xE0DD)
                {
                    //End element

                    //In case there's garbage in there, read the length bytes
                    br.ReadBytes((int)len);
                    count += len;

                    done = true;
                }
                else
                {
                    throw new NotImplementedException();
                }

                //toggle back in case it's just one SQItem that's hosed
                if (needMoreSwap)
                {
                    br.ToggleSwapped();
                }
            }

            return(count);
        }