/*
	saveScreenshot - Writes a screenshot to the specified filename in JPEG
*/
void saveScreenshot (char *filename)
{
	Pic *in = NULL;

	if (filename == NULL)
		return;

	/* Allocate a picture buffer */
	in = pic_alloc (Scene::WINDOW_WIDTH, Scene::WINDOW_HEIGHT, 3, NULL);

	printf("File to save to: %s\n", filename);

	/* Loop over each row of the image and copy into the image */
	for (int i = Scene::WINDOW_HEIGHT - 1; i >= 0; i--)
	{
		glReadPixels(0, Scene::WINDOW_HEIGHT - 1 - i, Scene::WINDOW_WIDTH, 1, GL_RGB,
						GL_UNSIGNED_BYTE, &in->pix[i*in->nx*in->bpp]);
	}

	/* Output the file */
	if (jpeg_write(filename, in))
	{
		printf("File saved Successfully\n");
	}
	else
	{
		printf("Error in Saving\n");
	}

	/* Free memory used by image */
	pic_free(in);
}
/* Write a screenshot to the specified filename */
void saveScreenshot (char *filename)
{
  int i, j;
  Pic *in = NULL;

  if (filename == NULL)
    return;

  /* Allocate a picture buffer */
  in = pic_alloc(640, 480, 3, NULL);

  printf("File to save to: %s\n", filename);

  for (i=479; i>=0; i--) {
    glReadPixels(0, 479-i, 640, 1, GL_RGB, GL_UNSIGNED_BYTE,
                 &in->pix[i*in->nx*in->bpp]);
  }

  if (jpeg_write(filename, in))
    printf("File saved Successfully\n");
  else
    printf("Error in Saving\n");

  pic_free(in);
}
Beispiel #3
0
static int draw_frame(uint8_t *src[])
{
    static int framecounter = 0, subdircounter = 0;
    char buf[BUFLENGTH];
    static char subdirname[BUFLENGTH] = "";

    /* Start writing to new subdirectory after a certain amount of frames */
    if ( framecounter == jpeg_maxfiles ) {
        framecounter = 0;
    }

    /* If framecounter is zero (or reset to zero), increment subdirectory
     * number and create the subdirectory.
     * If jpeg_subdirs is not set, do nothing and resort to old behaviour. */
    if ( !framecounter && jpeg_subdirs ) {
        subdircounter++;
        snprintf(subdirname, BUFLENGTH, "%s%08d", jpeg_subdirs, subdircounter);
        snprintf(buf, BUFLENGTH, "%s/%s", jpeg_outdir, subdirname);
        jpeg_mkdir(buf, 0); /* This function only returns if creation was
                               successful. If not, the player will exit. */
    }
    
    framenum++;

    /* snprintf the full pathname of the outputfile */
    snprintf(buf, BUFLENGTH, "%s/%s/%08d.jpg", jpeg_outdir, subdirname,
                                                                    framenum);
    
    framecounter++;
    
    return jpeg_write(buf, src[0]);
}
/* Write a screenshot to the specified filename */
void saveScreenshot (char *filename){   

int i, j;   

Pic *in = NULL;   

Pic *out = NULL;

if (filename == NULL)       

return;

in = pic_alloc(640, 480, 3, NULL);   

out = pic_alloc(640, 480, 3, NULL);

printf("File to save to: %s\n", filename);


glReadPixels(0, 0, 640, 480, GL_RGB, GL_UNSIGNED_BYTE, &in->pix[0]);       

for ( int j=0; j<480; j++ ) { 

for ( int i=0; i<640; i++ ) { 

PIC_PIXEL(out, i, j, 0) = PIC_PIXEL(in, i, 480-1-j, 0); 

PIC_PIXEL(out, i, j, 1) = PIC_PIXEL(in, i, 480-1-j, 1);             

PIC_PIXEL(out, i, j, 2) = PIC_PIXEL(in, i, 480-1-j, 2); 

} 

}

if (jpeg_write(filename, out))       

printf("File saved Successfully\n");   

else       

printf("Error in Saving\n");

pic_free(in);    

pic_free(out);

}
Beispiel #5
0
void save_jpg()
{
  Pic *in = NULL;

  in = pic_alloc(640, 480, 3, NULL);
  printf("Saving JPEG file: %s\n", filename);

  memcpy(in->pix,buffer,3*WIDTH*HEIGHT);
  if (jpeg_write(filename, in))
    printf("File saved Successfully\n");
  else
    printf("Error in Saving\n");

  pic_free(in);      

}
Beispiel #6
0
/*
 * Capture v4l2 frame and save to jpeg
 */
int capture_frame(char *jpegFileName)
{
	unsigned int index;

	/* Request a capture buffer from the driver that can be copied
	 * to framebuffer */
	v4l2_dequeue_buffer(&camera);

	index = camera.buf.index;

	jpeg_write(jpegFileName, (unsigned char *)camera.buffers[index].start,
		camera.width, camera.height);

	/* Give the buffer back to the driver so it can be filled again */
	v4l2_queue_buffer(&camera);

	return 0;
}
Beispiel #7
0
/*
 * pic_write: write pic to file in the specified format
 * returns TRUE on success, FALSE on failure
 */
int pic_write(char *file, Pic *pic, Pic_file_format format)
{
	switch( format )
    {
      /*
    case PIC_TIFF_FILE:
			return tiff_write(file, pic);
			break;
      */		
    case PIC_PPM_FILE:
			return ppm_write(file, pic);
			break;

    case PIC_JPEG_FILE:
			return jpeg_write(file, pic);
			break;
			
    default:
			fprintf(stderr, "pic_write: can't write %s, unknown format\n", file);
			return FALSE;
    }
}