     uint8_t r1;
     uint8_t r2 = s_data[offset + 1];
     uint8_t r3;
-    if ( (pix_offset + x) % 2 == 0 ) {
+    if ( (gX + x) % 2 == 0 ) {
         r1 = s_data[offset];
         r3 = s_data[offset + 2];
     } else {

        
    // Prepare unit size
    assert(coder->param_image.sampling_factor == GPUJPEG_4_4_4 || coder->param_image.sampling_factor == GPUJPEG_4_2_2);
    
    // Prepare kernel
    const dim3 threads (RGB_8BIT_THREADS);
    const dim3 grid (gpujpeg_div_and_round_up(image_width, RGB_8BIT_THREADS), image_height);

    // Run kernel
    struct gpujpeg_preprocessor_data data;

    // Color transform
    gpujpeg_color_transform<color_space, color_space_internal>::perform(r1, r2, r3);
    
    // Position
    int image_position = gX + x;
    int image_position_x = image_position % image_width;
    int image_position_y = image_position / image_width;
    
    // Store
    if ( image_position < (image_width * image_height) ) {
        gpujpeg_preprocessor_raw_to_comp_store<s_comp1_samp_factor_h, s_comp1_samp_factor_v>(r1, image_position_x, image_position_y, data.comp[0]);
        gpujpeg_preprocessor_raw_to_comp_store<s_comp2_samp_factor_h, s_comp2_samp_factor_v>(r2, image_position_x, image_position_y, data.comp[1]);
        gpujpeg_preprocessor_raw_to_comp_store<s_comp3_samp_factor_h, s_comp3_samp_factor_v>(r3, image_position_x, image_position_y, data.comp[2]);
