CSJ2K.j2k.codestream.writer.FileCodestreamWriter.writePacketHead C# (CSharp) Метод

writePacketHead() публичный Метод

Writes a packet head to the bit stream and returns the number of bytes used by this header. It returns the total number of bytes that the packet head takes in the bit stream. If in simulation mode then no data is written to the bit stream but the number of bytes is calculated. This can be used for iterative rate allocation.

If the length of the data that is to be written to the bit stream is more than the space left (as returned by getMaxAvailableBytes()) only the data that does not exceed the allowed length is written, the rest is discarded. However the value returned by the method is the total length of the packet, as if all of it was written to the bit stream.

If the bit stream header has not been commited yet and 'sim' is false, then the bit stream header is automatically commited (see commitBitstreamHeader() method) before writting the packet.

If an I/O error occurs while writing to the /// output stream. /// ///
public writePacketHead ( byte head, int hlen, bool sim, bool sop, bool eph ) : int
head byte The packet head data. /// ///
hlen int The number of bytes in the packet head. /// ///
sim bool Simulation mode flag. If true nothing is written to the bit /// stream, but the number of bytes that would be written is returned. /// ///
sop bool Start of packet header marker flag. This flag indicates /// whether or not SOP markers should be written. If true, SOP markers /// should be written, if false, they should not. /// ///
eph bool End of Packet Header marker flag. This flag indicates /// whether or not EPH markers should be written. If true, EPH markers /// should be written, if false, they should not. /// ///
Результат int
        public override int writePacketHead(byte[] head, int hlen, bool sim, bool sop, bool eph)
        {
            // CONVERSION PROBLEM?
            int len = hlen + (sop ? (int)CSJ2K.j2k.codestream.Markers.SOP_LENGTH : 0) + (eph ? (int)CSJ2K.j2k.codestream.Markers.EPH_LENGTH : 0);

            // If not in simulation mode write the data
            if (!sim)
            {
                // Write the head bytes
                if (MaxAvailableBytes < len)
                {
                    len = MaxAvailableBytes;
                }

                if (len > 0)
                {
                    // Write Start Of Packet header markers if necessary
                    if (sop)
                    {
                        // The first 4 bytes of the array have been filled in the
                        // classe's constructor.
                        sopMarker[4] = (byte) (packetIdx >> 8);
                        sopMarker[5] = (byte) (packetIdx);
                        out_Renamed.Write(sopMarker, 0, CSJ2K.j2k.codestream.Markers.SOP_LENGTH);
                        packetIdx++;
                        if (packetIdx > SOP_MARKER_LIMIT)
                        {
                            // Reset SOP value as we have reached its upper limit
                            packetIdx = 0;
                        }
                    }
                    out_Renamed.Write(head, 0, hlen);
                    // Update data length
                    ndata += len;

                    // Write End of Packet Header markers if necessary
                    if (eph)
                    {
                        out_Renamed.Write(ephMarker, 0, CSJ2K.j2k.codestream.Markers.EPH_LENGTH);
                    }

                    // Deal with ROI Information
                    lenLastNoROI += len;
                }
            }
            return len;
        }