CSJ2K.j2k.util.CodestreamManipulator.createTileParts C# (CSharp) Метод

createTileParts() приватный Метод

This method creates the tileparts from the buffered tile headers, packet headers and packet data
If an I/O error ocurred. /// ///
private createTileParts ( ) : void
Результат void
        private void createTileParts()
        {
            int i, prem, t, length;
            int pIndex; // phIndex removed
            int tppStart;
            int tilePart;
            int p, np, nomnp;
            int numTileParts;
            int numPackets;
            System.IO.MemoryStream temp = new System.IO.MemoryStream();
            byte[] tempByteArr;

            // Create tile parts
            tileParts = new byte[nt][][];
            maxtp = 0;

            for (t = 0; t < nt; t++)
            {
                // Calculate number of tile parts. If tileparts are not used,
                // put all packets in the first tilepart
                if (pptp == 0)
                    pptp = ppt[t];
                prem = ppt[t];
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                numTileParts = (int) System.Math.Ceiling(((double) prem) / pptp);
                numPackets = packetHeaders[t].Length;
                maxtp = (numTileParts > maxtp)?numTileParts:maxtp;
                tileParts[t] = new byte[numTileParts][];

                // Create all the tile parts for tile t
                tppStart = 0;
                pIndex = 0;
                p = 0;
                //phIndex = 0;

                for (tilePart = 0; tilePart < numTileParts; tilePart++)
                {

                    // Calculate number of packets in this tilepart
                    nomnp = (pptp > prem)?prem:pptp;
                    np = nomnp;

                    // Write tile part header
                    if (tilePart == 0)
                    {
                        // Write original tile part header up to SOD marker
                        temp.Write(tileHeaders[t], 0, tileHeaders[t].Length - 2);
                    }
                    else
                    {
                        // Write empty header of length TP_HEAD_LEN-2
                        temp.Write(new byte[TP_HEAD_LEN - 2], 0, TP_HEAD_LEN - 2);
                    }

                    // Write PPT marker segments if PPT used
                    if (pptUsed)
                    {
                        int pptLength = 3; // Zppt and Lppt
                        int pptIndex = 0;
                        int phLength;

                        p = pIndex;
                        while (np > 0)
                        {
                            phLength = packetHeaders[t][p].Length;

                            // If the total legth of the packet headers is greater
                            // than MAX_LPPT, several PPT markers are needed
                            if (pptLength + phLength > CSJ2K.j2k.codestream.Markers.MAX_LPPT)
                            {

                                temp.WriteByte((System.Byte) SupportClass.URShift(CSJ2K.j2k.codestream.Markers.PPT, 8));
                                temp.WriteByte((System.Byte) (CSJ2K.j2k.codestream.Markers.PPT & 0x00FF));
                                temp.WriteByte((System.Byte) SupportClass.URShift(pptLength, 8));
                                temp.WriteByte((System.Byte) pptLength);
                                temp.WriteByte((System.Byte) pptIndex++);
                                for (i = pIndex; i < p; i++)
                                {
                                    temp.Write(packetHeaders[t][i], 0, packetHeaders[t][i].Length);
                                }
                                pptLength = 3; // Zppt and Lppt
                                pIndex = p;
                            }
                            pptLength += phLength;
                            p++;
                            np--;
                        }
                        // Write last PPT marker
                        temp.WriteByte((System.Byte) SupportClass.URShift(CSJ2K.j2k.codestream.Markers.PPT, 8));
                        temp.WriteByte((System.Byte) (CSJ2K.j2k.codestream.Markers.PPT & 0x00FF));
                        temp.WriteByte((System.Byte) SupportClass.URShift(pptLength, 8));
                        temp.WriteByte((System.Byte) pptLength);
                        temp.WriteByte((System.Byte) pptIndex);
                        for (i = pIndex; i < p; i++)
                        {

                            temp.Write(packetHeaders[t][i], 0, packetHeaders[t][i].Length);
                        }
                    }
                    pIndex = p;
                    np = nomnp;

                    // Write SOD marker
                    temp.WriteByte((System.Byte) SupportClass.URShift(CSJ2K.j2k.codestream.Markers.SOD, 8));
                    temp.WriteByte((System.Byte) (CSJ2K.j2k.codestream.Markers.SOD & 0x00FF));

                    // Write packet data and packet headers if PPT and PPM not used
                    for (p = tppStart; p < tppStart + np; p++)
                    {
                        if (!tempSop)
                        {
                            temp.Write(sopMarkSeg[t][p], 0, CSJ2K.j2k.codestream.Markers.SOP_LENGTH);
                        }

                        if (!(ppmUsed || pptUsed))
                        {
                            temp.Write(packetHeaders[t][p], 0, packetHeaders[t][p].Length);
                        }

                        temp.Write(packetData[t][p], 0, packetData[t][p].Length);
                    }
                    tppStart += np;

                    // Edit tile part header
                    tempByteArr = temp.ToArray();
                    tileParts[t][tilePart] = tempByteArr;
                    length = (int)temp.Length;

                    if (tilePart == 0)
                    {
                        // Edit first tile part header
                        tempByteArr[6] = (byte) (SupportClass.URShift(length, 24)); // Psot
                        tempByteArr[7] = (byte) (SupportClass.URShift(length, 16));
                        tempByteArr[8] = (byte) (SupportClass.URShift(length, 8));
                        tempByteArr[9] = (byte) (length);
                        tempByteArr[10] = (byte) SupportClass.Identity((0)); // TPsot
                        tempByteArr[11] = (byte) (numTileParts); // TNsot
                    }
                    else
                    {
                        // Edit tile part header
                        tempByteArr[0] = (byte) (SupportClass.URShift(CSJ2K.j2k.codestream.Markers.SOT, 8)); // SOT
                        tempByteArr[1] = (byte) (CSJ2K.j2k.codestream.Markers.SOT & 0x00FF);
                        tempByteArr[2] = (byte) SupportClass.Identity((0)); // Lsot
                        tempByteArr[3] = (byte) SupportClass.Identity((10));
                        tempByteArr[4] = (byte) (SupportClass.URShift(t, 8)); // Isot
                        tempByteArr[5] = (byte) (t); //
                        tempByteArr[6] = (byte) (SupportClass.URShift(length, 24)); // Psot
                        tempByteArr[7] = (byte) (SupportClass.URShift(length, 16));
                        tempByteArr[8] = (byte) (SupportClass.URShift(length, 8));
                        tempByteArr[9] = (byte) (length);
                        tempByteArr[10] = (byte) (tilePart); //TPsot
                        tempByteArr[11] = (byte) (numTileParts); // TNsot
                    }
                    //UPGRADE_ISSUE: Method 'java.io.ByteArrayOutputStream.reset' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioByteArrayOutputStreamreset'"
                    //temp.reset();
                    temp.SetLength(0);
                    prem -= np;
                }
            }
            temp.Dispose();
        }