Beispiel #1
0
        /// <summary>
        /// Set data indicated Dicom Tag and Element read from FileStream
        /// </summary>
        /// <param name="fs">target dcm file FileStream</param>
        /// <param name="count">reference for FileStream position</param>
        /// <param name="tagele_obj">reference for TagElementObjectData parameter</param>
        private void SetDataContainer(FileStream fs, ref Int64 count, ref TagElementObjectData tagele_obj)
        {
            Int64 i = count;

            byte[] vr    = new byte[2];
            byte[] len   = new byte[2];
            byte[] blanc = new byte[2];

            fs.Read(vr, 0, 2);
            fs.Read(len, 0, 2);

            i += 4;

            int size = ToInt32_LittleEndian(len);

            if (0 == size)
            {
                fs.Read(len, 0, 2);
                fs.Read(blanc, 0, 2);

                i += 4;

                if (blanc[0] == 0x00 && blanc[1] == 0x00)
                {
                    size = ToInt32_LittleEndian(len);
                }
                else
                {
                    fs.Position -= 4;
                    return;
                }
            }

            byte[] data = new byte[size];

            fs.Read(data, 0, size);

            i += size;

            count = i;

            tagele_obj.vr     = vr;
            tagele_obj.length = len;
            tagele_obj.value  = data;
        }
Beispiel #2
0
        /// <summary>
        /// Set pixcel data chunk '7FE0,0010' from target opened dcm FileStream.
        /// </summary>
        /// <param name="fs">target dcm file FileStream</param>
        /// <param name="start">start point of '7FEO,0010' chunk</param>
        /// <param name="end">end point of '7FEO,0010' chunk</param>
        /// <param name="count">reference for FileStream position</param>
        /// <param name="tagele_obj">reference for TagElementObjectData parameter</param>
        private void SetPixcelsDataContainer(FileStream fs, int start, int end, ref long count, ref TagElementObjectData tagele_obj)
        {
            byte[] vr  = new byte[2];
            byte[] len = new byte[2];

            fs.Read(vr, 0, 2);
            fs.Read(len, 0, 2);

            count += 2;

            int size = end - start;

            byte[] data = new byte[size];

            fs.Read(data, 0, size);

            count += size;

            tagele_obj.vr     = vr;
            tagele_obj.length = len;
            tagele_obj.value  = data;
        }
Beispiel #3
0
        private void ExecuteCommnadDisplayAndParsing()
        {
            ConvertJpegToDICOMFile(iFilename, intermediateFile);

            iFilename = intermediateFile;

            whitebalance = 0;

            int tag_h = 0;
            int tag_l = 0;
            int ele_h = 0;
            int ele_l = 0;

            var   fi         = new FileInfo(iFilename);
            var   fileLength = fi.Length;
            Int64 fi_count   = 0;
            int   i          = 0;

            List <string> TagEle = new List <string>();

            dataGridView1.DoubleClick += DataGridView1_DoubleClick;

            pictureBox1.MouseWheel += PictureBox1_MouseWheel;

            using (var fs = new FileStream(iFilename, FileMode.Open))
            {
                fs.Position = 132;
                fi_count    = 132;

                while (fi_count < fileLength)
                {
                    var tag_element_name = ParseTagElementContainer(fs, ref fi_count);

                    TagEle.Add(tag_element_name);
                }
            }

            fi_count = 0;

            using (var fs = new FileStream(iFilename, FileMode.Open))
            {
                fs.Position = 132;
                fi_count    = 132;

                while (fi_count < fileLength)
                {
                    GetTagElementByte(TagEle[i], out tag_h, out tag_l, out ele_h, out ele_l);

                    var read_tag_h = fs.ReadByte();
                    var read_tag_l = fs.ReadByte();

                    fi_count += 2;

                    if (read_tag_h == tag_h && read_tag_l == tag_l)
                    {
                        var read_ele_h = fs.ReadByte();
                        var read_ele_l = fs.ReadByte();

                        fi_count += 2;

                        if (read_ele_h == ele_h && read_ele_l == ele_l)
                        {
                            TagElementObjectData obj = new TagElementObjectData();

                            obj.tag     = new byte[] { (byte)tag_h, (byte)tag_l };
                            obj.element = new byte[] { (byte)ele_h, (byte)ele_l };

                            if ("7FE0,0010" == TagEle[i])
                            {
                                long start = fs.Position - 4;

                                SetPixcelsDataContainer(fs, (int)start, (int)fileLength, ref fi_count, ref obj);

                                obj_data = obj;

                                bitmap = CreateBitmap(obj.value, width, height, window_center, window_width);

                                DrawPictureBox(obj.value, width, height, window_center, window_width);
                            }
                            else
                            {
                                SetDataContainer(fs, ref fi_count, ref obj);

                                tagele_obj.Add(obj);

                                if ("0028,0010" == TagEle[i])
                                {
                                    width = GetWidthFrom00280010(obj);
                                }
                                if ("0028,0011" == TagEle[i])
                                {
                                    height = GetHeightFrom00280011(obj);
                                }

                                if ("0028,1050" == TagEle[i])
                                {
                                    window_center = double.Parse(Encoding.UTF8.GetString(obj.value));
                                }

                                if ("0028,1051" == TagEle[i])
                                {
                                    window_width = double.Parse(Encoding.UTF8.GetString(obj.value));
                                }
                            }

                            i++;
                        }
                    }
                }
            }

            ShowTagElementData(tagele_obj);

            DisplayPictureboxImageData();

            File.Delete(intermediateFile);
        }
Beispiel #4
0
 private int GetHeightFrom00280011(TagElementObjectData obj)
 {
     return(ToInt32_LittleEndian(obj.value));
 }
Beispiel #5
0
 /// <summary>
 /// It gets Planar configuration parameters 1 or 0
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 private int GetPlanarConfiguration(TagElementObjectData obj)
 {
     return(ToInt32_LittleEndian(obj.value));
 }
Beispiel #6
0
 /// <summary>
 /// It gets Photometoric parameter like RGB or MONOCHROME2.
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 string GetPhotometoricInterpretation(TagElementObjectData obj)
 {
     return(Encoding.ASCII.GetString(obj.value));
 }