     }
     
     // each thread gets codeword for its two pixels
-    int even_code_size = 0, even_code_value = 0, odd_code_size = 0, odd_code_value = 0;
+    unsigned int even_code_size = 0, even_code_value = 0, odd_code_size = 0, odd_code_value = 0;
     if(nonzero_follows || !tid) {
         gpujpeg_huffman_gpu_encode_value(even_code_size, even_code_value, zeros_before_even & 0xf, in_even, d_table_even);
         gpujpeg_huffman_gpu_encode_value(odd_code_size, odd_code_value, zeros_before_odd & 0xf, in_odd, d_table_ac);


/**
 * Adds up to 32 bits at once.
 */
__device__ inline void 
gpujpeg_huffman_gpu_encoder_emit_bits(unsigned int & remaining_bits, int & byte_count, int & bit_count, uint8_t * const out_ptr, const int code_bit_size, unsigned int code_word) {
    // TODO: move codeword upshifting into parallel kernel
    code_word <<= (32 - code_bit_size);
    
    // concatenate with remaining bits
    remaining_bits |= code_word >> bit_count;



__device__ static void
gpujpeg_huffman_gpu_encode_value(unsigned int & out_nbits, unsigned int & out_cword, const int preceding_zero_count, const int value,
                                 const struct gpujpeg_table_huffman_encoder * const d_table) {
    out_cword = value;
    int absolute = value;
