test/opengl_interop/main.c
void
image_generate(struct application* app)
{
    static int max = 100;
    static int change = 10;
    
    printf("Image: ImageRender Started\n");
        
    TIMER_INIT();
    TIMER_START();
    
    // Render new image
    max += change;
    if ( max < 0 || max > 255 ) {
        change = -change;
        max += change;
    }
    image_render(app->image, max);
        
    TIMER_STOP_PRINT("Image: ImageRendered");
    TIMER_START();
    
    // Encode image
    uint8_t* image_compressed = NULL;
    int image_compressed_size = 0;
    // Copy data to host memory
    cudaMemcpy(app->image->data, app->image->d_data, app->width * app->height * 3 * sizeof(uint8_t), cudaMemcpyDeviceToHost);
    struct gpujpeg_encoder_input input;
    gpujpeg_encoder_input_set_image(&input, app->image->data);
    assert(gpujpeg_encoder_encode(app->encoder, &input, &image_compressed, &image_compressed_size) == 0);
    
    TIMER_STOP_PRINT("Image: ImageEncode");
    TIMER_START();
    
    // Decode image
    gpujpeg_decoder_decode(app->decoder, image_compressed, image_compressed_size, &app->decoder_output);
    
    app->new_image = 1;
    
    TIMER_STOP_PRINT("Image: ImageDecode");
}
/**
 * Generate new image, encode it with JPEG and decode it into OpenGL texture
 * 
 * @param app
 * @return void
 */
Generate new image, encode it with JPEG and decode it into OpenGL texture

@param app
@return void
Generate new image encode it with JPEG and decode it into OpenGL texture @param app @return void
void
image_generate(struct application* app)
{
    static int max = 100;
    static int change = 10;
    printf("Image: ImageRender Started\n");
    TIMER_INIT();
    TIMER_START();
    max += change;
    if ( max < 0 || max > 255 ) {
        change = -change;
        max += change;
    }
    image_render(app->image, max);
    TIMER_STOP_PRINT("Image: ImageRendered");
    TIMER_START();
    uint8_t* image_compressed = NULL;
    int image_compressed_size = 0;
    cudaMemcpy(app->image->data, app->image->d_data, app->width * app->height * 3 * sizeof(uint8_t), cudaMemcpyDeviceToHost);
    struct gpujpeg_encoder_input input;
    gpujpeg_encoder_input_set_image(&input, app->image->data);
    assert(gpujpeg_encoder_encode(app->encoder, &input, &image_compressed, &image_compressed_size) == 0);
    TIMER_STOP_PRINT("Image: ImageEncode");
    TIMER_START();
    gpujpeg_decoder_decode(app->decoder, image_compressed, image_compressed_size, &app->decoder_output);
    app->new_image = 1;
    TIMER_STOP_PRINT("Image: ImageDecode");
}
void image_generate ( struct application * app ) { static int max = 100 ; static int change = 10 ; printf ( " \n " ) ; TIMER_INIT ( ) ; TIMER_START ( ) ; max += change ; if ( max < 0 || max > 255 ) { change = - change ; max += change ; } image_render ( app -> image , max ) ; TIMER_STOP_PRINT ( " " ) ; TIMER_START ( ) ; uint8_t * image_compressed = NULL ; int image_compressed_size = 0 ; cudaMemcpy ( app -> image -> data , app -> image -> d_data , app -> width * app -> height * 3 * sizeof ( uint8_t ) , cudaMemcpyDeviceToHost ) ; struct gpujpeg_encoder_input input ; gpujpeg_encoder_input_set_image ( & input , app -> image -> data ) ; assert ( gpujpeg_encoder_encode ( app -> encoder , & input , & image_compressed , & image_compressed_size ) == 0 ) ; TIMER_STOP_PRINT ( " " ) ; TIMER_START ( ) ; gpujpeg_decoder_decode ( app -> decoder , image_compressed , image_compressed_size , & app -> decoder_output ) ; app -> new_image = 1 ; TIMER_STOP_PRINT ( " " ) ; }
Generate new image, encode it with JPEG and decode it into OpenGL texture
Generate new image encode it with JPEG and decode it into OpenGL texture
// Render new image // Encode image // Copy data to host memory // Decode image