1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Libvideo.h"
#include "Libvideonext.h"
#include <signal.h>
#include <X11/Xlib.h>
#include "Libvideo.c"
#include <X11/extensions/xf86dga.h>
#include <X11/Xutil.h>
#include"RGBtoBMP+envoie.c"
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "FreeImage.h"
void acquisition()
{
FILE* file;
int width,height,depth,lenght,i=0,j=0;
char fic[15];
unsigned char * buffer;
struct stat buf;
FIMEMORY *hmem = NULL;
BYTE * mem_buffer=NULL;
BYTE * test;
RGBQUAD *pix;
int k;
long file_size;
buffer=GrabVideo(&video,&width,&height,&depth);
FIBITMAP *dib = FreeImage_AllocateT(FIT_BITMAP,width,height,3,0,0,0);
//je créer le conteneur de l'image de type image classique, puisque mon buffer est en rgb24
if(buffer!=NULL)
{
while(buffer!=NULL)
{
//je rempli le conteneur dib
for(k=0;k<height;k++)
{
pix[j].rgbBlue=buffer[i];
pix[j].rgbGreen=buffer[i+1];
pix[j].rgbRed=buffer[i+2];
FreeImage_SetPixelColor(dib, i, k,pix);
i+=3;
j=j+1;
}
}
//la g copier le bout de code ds la doc freeimaeg pour sauver en un type donné, donc la JPEG
// open and allocate a memory stream
hmem = FreeImage_OpenMemory(0,0);
FreeImage_SaveToMemory(FIF_JPEG,dib, hmem, 0);
// at this point, hmem contains the entire data in memory stored in fif format.
// the amount of space used by the memory is equal to file_size
file_size = FreeImage_TellMemory(hmem);
printf("File size : %ld\n", file_size);
// its easy to load an image from memory as well
// seek to the start of the memory stream
FreeImage_SeekMemory(hmem, 0L, SEEK_SET);
// get the file type
FREE_IMAGE_FORMAT mem_fif = FreeImage_GetFileTypeFromMemory(hmem, 0);
// load an image from the memory handle
FIBITMAP *check = FreeImage_LoadFromMemory(mem_fif, hmem, 0);
// save as a regular file
FreeImage_Save(FIF_JPEG, check, "dump.jpeg", JPEG_DEFAULT);
// make sure to close the stream since FreeImage_SaveToMemory
// will cause internal memory allocations and this is the only
// way to free this allocated memory
FreeImage_CloseMemory(hmem);
FreeImage_Unload(check);
FreeImage_Unload(dib);
envoiepacket(file_size,(char*)buffer);
}
// close and free the memory stream
else
printf("erreur grabbing\n");
CloseVideo(&video);
exit(0);
} |
Partager