# CSJ2K.j2k.codestream.writer.PktEncoder.encodePacket

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="CSJ2K_j2k_codestream_writer_PktEncoder_encodePacket_" data-uid="CSJ2K.j2k.codestream.writer.PktEncoder.encodePacket*">encodePacket Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="CSJ2K_j2k_codestream_writer_PktEncoder_encodePacket_" data-uid="CSJ2K.j2k.codestream.writer.PktEncoder.encodePacket*"></a>
<h4 id="CSJ2K_j2k_codestream_writer_PktEncoder_encodePacket_System_Int32_System_Int32_System_Int32_System_Int32_CSJ2K_j2k_entropy_encoder_CBlkRateDistStats_____System_Int32_____CSJ2K_j2k_codestream_writer_BitOutputBuffer_System_Byte___System_Int32_" data-uid="CSJ2K.j2k.codestream.writer.PktEncoder.encodePacket(System.Int32,System.Int32,System.Int32,System.Int32,CSJ2K.j2k.entropy.encoder.CBlkRateDistStats[][],System.Int32[][],CSJ2K.j2k.codestream.writer.BitOutputBuffer,System.Byte[],System.Int32)">encodePacket(int, int, int, int, CBlkRateDistStats[][], int[][], BitOutputBuffer, byte[], int)</h4>
<div class="markdown level1 summary"><p>Encodes a packet and returns the buffer containing the encoded packet
header. The code-blocks appear in a 3D array of CBlkRateDistStats,
'cbs'. The first index is the tile index in lexicographical order, the
second index is the subband index (as defined in the Subband class),
and the third index is the code-block index (whithin the subband tile)
in lexicographical order as well. The indexes of the new truncation
points for each code-block are specified by the 3D array of int
'tIndx'. The indices of this array are the same as for cbs. The
truncation point indices in 'tIndx' are the indices of the elements of
the 'truncIdxs' array, of the CBlkRateDistStats class, that give the
real truncation points. If a truncation point index is negative it
means that the code-block has not been included in any layer yet. If
the truncation point is less than or equal to the highest truncation
point used in previous layers then the code-block is not included in
the packet. Otherwise, if larger, the code-block is included in the
packet. The body of the packet can be obtained with the
getLastBodyBuf() and getLastBodyLen() methods.</p>
<pre><code>       &lt;p&gt;Layers must be coded in increasing order, in consecutive manner, for
       each tile, component and resolution level (e.g., layer 1, then layer 2,
       etc.). For different tile, component and/or resolution level no
       particular order must be followed.&lt;/p&gt;
</code></pre>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public virtual BitOutputBuffer encodePacket(int ly, int c, int r, int t, CBlkRateDistStats[][] cbs, int[][] tIndx, BitOutputBuffer hbuf, byte[] bbuf, int pIdx)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Overridable Function encodePacket(ly As Integer, c As Integer, r As Integer, t As Integer, cbs As CBlkRateDistStats()(), tIndx As Integer()(), hbuf As BitOutputBuffer, bbuf As Byte(), pIdx As Integer) As BitOutputBuffer</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">ly</span></td>
      <td><p>The layer index (starts at 1).</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">c</span></td>
      <td><p>The component index.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">r</span></td>
      <td><p>The resolution level</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">t</span></td>
      <td><p>Index of the current tile</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="CSJ2K.j2k.entropy.encoder.CBlkRateDistStats.html">CBlkRateDistStats</a>[][]</td>
      <td><span class="parametername">cbs</span></td>
      <td><p>The 3D array of coded code-blocks.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a>[][]</td>
      <td><span class="parametername">tIndx</span></td>
      <td><p>The truncation point indices for each code-block.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="CSJ2K.j2k.codestream.writer.BitOutputBuffer.html">BitOutputBuffer</a></td>
      <td><span class="parametername">hbuf</span></td>
      <td><p>The header buffer. If null a new BitOutputBuffer is created
and returned. This buffer is reset before anything is written to it.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.byte">byte</a>[]</td>
      <td><span class="parametername">bbuf</span></td>
      <td><p>The body buffer. If null a new one is created. If not large
enough a new one is created.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">pIdx</span></td>
      <td><p>The precinct index.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="CSJ2K.j2k.codestream.writer.BitOutputBuffer.html">BitOutputBuffer</a></td>
      <td><p>The buffer containing the packet header.</p>
</td>
    </tr>
  </tbody>
</table>
</div>
