// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ // void GfxTexture::SaveTGA( const char* fname ) { FILE *file_TGA = fopen( fname, "wb"); if (file_TGA != NULL) { int nSize = Width * Height * (IsRGBA ? 4 : 1); void *buf_image = malloc( nSize ); if (buf_image != NULL) { glBindFramebuffer(GL_FRAMEBUFFER,FramebufferId); check_gl(); glReadPixels(0,0,Width,Height,IsRGBA ? GL_RGBA : GL_LUMINANCE, GL_UNSIGNED_BYTE, buf_image); check_gl(); glBindFramebuffer(GL_FRAMEBUFFER,0); raspitexutil_brga_to_rgba( (uint8_t*) buf_image, nSize ); write_tga( file_TGA, Width, Height, (uint8_t*) buf_image, nSize); free(buf_image); } fclose( file_TGA ); } }
/** * Writes the next GL frame-buffer to a RAW .ppm formatted file * using the specified file-handle. * @param state Pointer to the GL preview state. * @param outpt_file Output file handle for the ppm image. * @return Zero on success. */ int raspitex_capture(RASPITEX_STATE *state, FILE *output_file) { int rc = 0; uint8_t *buffer = NULL; size_t size = 0; vcos_log_trace("%s: state %p file %p", VCOS_FUNCTION, state, output_file); if (state && output_file) { /* Only request one capture at a time */ vcos_semaphore_wait(&state->capture.start_sem); state->capture.request = 1; /* Wait for capture to start */ vcos_semaphore_wait(&state->capture.completed_sem); /* Take ownership of the captured buffer */ buffer = state->capture.buffer; size = state->capture.size; state->capture.request = 0; state->capture.buffer = 0; state->capture.size = 0; /* Allow another capture to be requested */ vcos_semaphore_post(&state->capture.start_sem); } if (size == 0 || ! buffer) { vcos_log_error("%s: capture failed", VCOS_FUNCTION); rc = -1; goto end; } raspitexutil_brga_to_rgba(buffer, size); rc = write_tga(output_file, state->width, state->height, buffer, size); fflush(output_file); end: free(buffer); return rc; }