                                | (code_word >> (code_bit_size - new_bit_count) & ((1 << new_bit_count) - 1));
         
         out_byte_ptr[0] = out_byte;
+        if(out_byte == 0xFF) {
+            out_byte_ptr[1] = 0;
+            buffer_bits += 8;
+        }
         code_bit_size -= new_bit_count;
         buffer_bits += new_bit_count;
     }

        dc[comp] = 0;
    
    // Prepare data pointers
    uint8_t * data_compressed = &d_data_compressed[segment->data_compressed_index]; //TODO zmeni datovy typ
    uint8_t * data_compressed_start = data_compressed;
    
    // Non-interleaving mode
    if ( comp_count == 1 ) {

 * @return 0 if succeeds, otherwise nonzero
 */
__device__ int
gpujpeg_huffman_gpu_encoder_encode_block(int16_t * block, uint4 * &data_compressed, int *last_dc, int tid,
                struct gpujpeg_table_huffman_encoder* d_table_dc, struct gpujpeg_table_huffman_encoder* d_table_ac)
{
    // each thread loads a pair of values (pair after zigzag reordering)
