         grid.y *= 2;
         grid.x = gpujpeg_div_and_round_up(grid.x, 2);
     }
-
+    
+    // Decompose input image width for faster division using multiply-high and right shift
+    uint32_t width_div_mul, width_div_shift;
+    gpujpeg_const_div_prepare(image_width, width_div_mul, width_div_shift);
+    
     // Run kernel
     struct gpujpeg_preprocessor_data data;
     for ( int comp = 0; comp < 3; comp++ ) {

    
    // 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) ) {

        coder->d_data_raw,
        coder->d_data_raw + coder->data_raw_size,
        image_width,
        image_height,
        width_div_mul,
        width_div_shift
    );
    cudaThreadSynchronize();
    gpujpeg_cuda_check_error("Preprocessor encoding failed");
