Exemplo n.º 1
0
 public virtual int CalcLength(DcmEncodeParam param)
 {
     totlen = param.undefSeqLen?8:0;
      for (int i = 0, n = vm(); i < n; ++i)
         totlen += GetItem(i).CalcLength(param) + (param.undefItemLen?16:8);
     return totlen;
 }
Exemplo n.º 2
0
        public virtual int CalcLength(DcmEncodeParam param)
        {
            totLen = 0;
            grCount = 0;

            uint curGrTag, prevGrTag = 0;
            IEnumerator enu = GetEnumerator();
            while( enu.MoveNext() )
            {
                DcmElement el = (DcmElement) enu.Current;
                curGrTag = el.tag() & 0xffff0000;
                if (curGrTag != prevGrTag)
                {
                    grCount++;
                    grTags = EnsureCapacity(grTags, grCount + 1);
                    grLens = EnsureCapacity(grLens, grCount + 1);
                    grTags[grCount - 1] = prevGrTag = curGrTag;
                    grLens[grCount - 1] = 0;
                }
                grLens[grCount - 1] += (param.explicitVR && !VRs.IsLengthField16Bit(el.vr()))?12:8;
                if (el is ValueElement)
                    grLens[grCount - 1] += el.length();
                else if (el is FragmentElement)
                    grLens[grCount - 1] += ((FragmentElement) el).CalcLength();
                else
                    grLens[grCount - 1] += ((SQElement) el).CalcLength(param);
            }
            grTags[grCount] = 0;
            if (!param.skipGroupLen)
                totLen += grCount * 12;
             for (int i = 0; i < grCount; ++i)
            {
                totLen += grLens[i];
            }
            return totLen;
        }
Exemplo n.º 3
0
 private void DoWrite(DcmHandlerI handler, DcmEncodeParam param)
 {
     int grIndex = 0;
     IEnumerator enu = GetEnumerator();
     while( enu.MoveNext() )
     {
         DcmElement el = (DcmElement) enu.Current;
         if (!param.skipGroupLen && grTags[grIndex] == (el.tag() & (int) (- (0x100000000 - 0xffff0000))))
         {
             byte[] b4 = new byte[4];
             ByteBuffer.Wrap(b4, param.byteOrder).Write(grLens[grIndex]);
             handler.StartElement( grTags[grIndex], VRs.UL, el.StreamPosition);
             handler.Value(b4, 0, 4);
             handler.EndElement();
             ++grIndex;
         }
         if (el is SQElement)
         {
             int len = param.undefSeqLen?- 1:el.length();
             handler.StartElement(el.tag(), VRs.SQ, el.StreamPosition);
             handler.StartSequence(len);
              for (int j = 0, m = el.vm(); j < m; )
             {
                 BaseDataset ds = (BaseDataset) el.GetItem(j);
                 int itemlen = param.undefItemLen?- 1:ds.length();
                 handler.StartItem(++j, ds.GetItemOffset(), itemlen);
                 ds.DoWrite(handler, param);
                 handler.EndItem(itemlen);
             }
             handler.EndSequence(len);
             handler.EndElement();
         }
         else if (el is FragmentElement)
         {
             long offset = el.StreamPosition;
             handler.StartElement(el.tag(), el.vr(), offset);
             handler.StartSequence(- 1);
             if (offset != - 1L)
             {
                 offset += 12;
             }
              for (int j = 0, m = el.vm(); j < m; )
             {
                 ByteBuffer bb = el.GetDataFragment(j, param.byteOrder);
                 handler.Fragment(++j, offset, bb.ToArray(), (int)bb.Position, bb.length());
                 if (offset != - 1L)
                 {
                     offset += (bb.length() + 9) & (~ 1);
                 }
             }
             handler.EndSequence(- 1);
             handler.EndElement();
         }
         else
         {
     //					int len = el.length();
             handler.StartElement(el.tag(), el.vr(), el.StreamPosition);
             ByteBuffer bb = el.GetByteBuffer(param.byteOrder);
             handler.Value(bb);
             handler.EndElement();
         }
     }
 }
Exemplo n.º 4
0
 public virtual void WriteFile(System.IO.Stream outs, DcmEncodeParam param)
 {
     FileMetaInfo fmi = GetFileMetaInfo();
     if (fmi != null)
     {
         fmi.Write(outs);
         if (param == null)
         {
             param = DcmDecodeParam.ValueOf(fmi.TransferSyntaxUID);
         }
     }
     WriteDataset(outs, param);
 }
Exemplo n.º 5
0
 public virtual void WriteDataset(System.IO.Stream outs, DcmEncodeParam param)
 {
     if (param == null)
     {
         param = DcmDecodeParam.IVR_LE;
     }
     // TODO: Check deflated
     WriteDataset(new DcmStreamHandler(outs), param);
 }
Exemplo n.º 6
0
 public virtual void WriteDataset(DcmHandlerI handler, DcmEncodeParam param)
 {
     if (!(param.skipGroupLen && param.undefItemLen && param.undefSeqLen))
         CalcLength(param);
     handler.StartDataset();
     handler.DcmDecodeParam = param;
     DoWrite(handler, param);
     handler.EndDataset();
 }
Exemplo n.º 7
0
        public virtual void WriteHeader( Stream os, DcmEncodeParam encParam, uint tag, int vr, int len)
        {
            if (encParam.byteOrder == ByteOrder.LITTLE_ENDIAN)
            {
                os.WriteByte((Byte) (tag >> 16));
                os.WriteByte((Byte) (tag >> 24));
                os.WriteByte((Byte) (tag >> 0));
                os.WriteByte((Byte) (tag >> 8));
            }
            else
            {
                os.WriteByte((Byte) (tag >> 24));
                os.WriteByte((Byte) (tag >> 16));
                os.WriteByte((Byte) (tag >> 8));
                os.WriteByte((Byte) (tag >> 0));
            }

            if (encParam.explicitVR)
            {
                os.WriteByte((Byte) (vr >> 8));
                os.WriteByte((Byte) (vr >> 0));
                if (VRs.IsLengthField16Bit(vr))
                {
                    if (encParam.byteOrder == ByteOrder.LITTLE_ENDIAN)
                    {
                        os.WriteByte((Byte) (len >> 0));
                        os.WriteByte((Byte) (len >> 8));
                    }
                    else
                    {
                        os.WriteByte((Byte) (len >> 8));
                        os.WriteByte((Byte) (len >> 0));
                    }
                    return ;
                }
                else
                {
                    os.WriteByte((Byte) 0);
                    os.WriteByte((Byte) 0);
                }
            }
            if (encParam.byteOrder == ByteOrder.LITTLE_ENDIAN)
            {
                os.WriteByte((Byte) (len >> 0));
                os.WriteByte((Byte) (len >> 8));
                os.WriteByte((Byte) (len >> 16));
                os.WriteByte((Byte) (len >> 24));
            }
            else
            {
                // order == ByteOrder.BIG_ENDIAN
                os.WriteByte((Byte) (len >> 24));
                os.WriteByte((Byte) (len >> 16));
                os.WriteByte((Byte) (len >> 8));
                os.WriteByte((Byte) (len >> 0));
            }
        }
Exemplo n.º 8
0
 private void storeToFile(DcmParser parser, Dataset ds, FileInfo file, DcmEncodeParam encParam)
 {
     Stream outs = openOutputStream(file);
     try
     {
         ds.WriteFile(outs, encParam);
         if (parser.ReadTag == Tags.PixelData)
         {
             ds.WriteHeader(outs, encParam, parser.ReadTag, parser.ReadVR, parser.ReadLength);
             copy(parser.InputStream, outs);
         }
     }
     finally
     {
         try
         {
             outs.Close();
         }
         catch (IOException ignore)
         {
         }
     }
 }