so, i was experimenting a bit with the viewfinder image lurking ewavr's code in order to make the yuv-to-rgb conversion OS agnostic.
char* liveb = NULL;
unsigned char* buf1= NULL;
int WIDTH = 720;
int HEIGHT = 480;
int BUFWIDTH = 720;
long int SIZE = (BUFWIDTH*HEIGHT*6)/4;
liveb = ptp_chdk_get_memory(ADDRESS, SIZE, ¶ms, ¶ms.deviceinfo);
if (liveb == NULL)
return NULL;
buf1=(unsigned char*)liveb;
unsigned char* nastybuf =(unsigned char*) malloc (sizeof(unsigned char*)*SIZE);
if (nastybuf == NULL)
return NULL;
memcpy(nastybuf, liveb, SIZE);
int* col = (int*)nastybuf;
int x = 0; int y = 0;
for (y=0; y<HEIGHT; y++) {
for (x=0; x<BUFWIDTH; x+=4, buf1+=6) {
if ( x < WIDTH) {
*col++=get_pixel_yuv(buf1[1], buf1[0], buf1[2]);
*col++=get_pixel_yuv(buf1[3], buf1[0], buf1[2]);
*col++=get_pixel_yuv(buf1[4], buf1[0], buf1[2]);
*col++=get_pixel_yuv(buf1[5], buf1[0], buf1[2]);
}
}
}
free(liveb);
return nastybuf;
the current code returns a nice uchar* with raw rgb data. using the Qt toolkit i can magically convert this to whatever image format i want with two simple lines
QImage img(nastybuf, WIDTH, HEIGHT, QImage::Format_RGB32);
img.save("converted_image.bmp");
however a cool thing would have been returning "complete" image data instead of raw rgb without involving the use of a complete toolkit in orderd to be fast and more platform-independant as possible (i see ewavr uses Windows' GDI+ for converting the image data in his chdkde tool). I was thinking on linking some c library like libjpeg, what do you think? Is there a simpler solution in your opinion?
greets