示例#1
0
文件: jd11.c 项目: rajbot/gphoto
struct Image*
jd11_get_picture(int picnum,int thumbnail) {
        struct Image	*image;
	int		nrofpics;
	int		h,fd;
	unsigned char	*indexbuf,*uncomp[3],**imagebufs;
	int		sizes[3];
	char		*s;

	if (picnum==0) {
	    fprintf(stderr,"jd11_get_picture: picnum 0???\n");
	    assert(picnum);
	}
	picnum--;
	fd=serial_open(serial_port);
	if (fd==-1) {
	    return NULL;
	}
	nrofpics = serial_index_reader(fd,&indexbuf);
	if (!nrofpics || (picnum>nrofpics)) {
	    return NULL;
	}

	image = (struct Image*)malloc(sizeof(struct Image));
	memset(image,0,sizeof(*image));

	if (thumbnail) {
	    	int ind;

		image->image = malloc(1*64*48*5+200); /* guessing imagesize */
		strcpy(image->image,"P2\n64 48\n255\n");
		s=image->image+strlen(image->image);
		ind = picnum*64*48;
		for (h=48;h--;) { /* upside down */
		    int w;
		    for (w=64;w--;) { /* and right to left */
			sprintf(s,"%d ",indexbuf[ind+(h*64)+w]);s+=strlen(s);
			if ((w&0xf)==0xf)
			    	*s++='\n';
		    }
		}
		*s++='\0';
		image->image_size = strlen(image->image);
		strcpy(image->image_type,"ppm");
		free(indexbuf);
		return image;
	}
	free(indexbuf);
	serial_image_reader(fd,picnum,&imagebufs,sizes);
	uncomp[0] = malloc(320*480);
	uncomp[1] = malloc(320*480/2);
	uncomp[2] = malloc(320*480/2);
	if (sizes[0]!=115200) {
		picture_decomp_v1(imagebufs[0],uncomp[0],320,480);
		picture_decomp_v1(imagebufs[1],uncomp[1],320,480/2);
		picture_decomp_v1(imagebufs[2],uncomp[2],320,480/2);
	} else {
		picture_decomp_v2(imagebufs[0],uncomp[0],320,480);
		picture_decomp_v2(imagebufs[1],uncomp[1],320,480/2);
		picture_decomp_v2(imagebufs[2],uncomp[2],320,480/2);
	}

	image->image = malloc(1*640*480*3+200); /* guessing imagesize */
	strcpy(image->image,"P6\n640 480\n255\n");
	s=image->image+strlen(image->image);
	image->image_size = strlen(image->image)+640*480*3;
	for (h=480;h--;) { /* upside down */
	    int w;
	    for (w=640;w--;) { /* right to left */
		/* and images are in green red blue */
		*s++=uncomp[1][(h/2)*320+(w/2)];
		*s++=uncomp[0][h*320+(w/2)];
		*s++=uncomp[2][(h/2)*320+(w/2)];
	    }
	}
	free(uncomp[0]);free(uncomp[1]);free(uncomp[2]);
	free(imagebufs[0]);free(imagebufs[1]);free(imagebufs[2]);free(imagebufs);
	strcpy(image->image_type,"ppm");
	serial_close(fd);
	return image;
}
示例#2
0
int
jd11_get_image_full(
    Camera *camera, CameraFile*file, int nr, int raw, GPContext *context
) {
    unsigned char	*s,*uncomp[3],**imagebufs;
    int			ret,sizes[3];
    unsigned char	*data;
    int 		h;

    ret = serial_image_reader(camera,file,nr,&imagebufs,sizes, context);
    if (ret!=GP_OK)
	return ret;
    uncomp[0] = malloc(320*480);
    uncomp[1] = malloc(320*480/2);
    uncomp[2] = malloc(320*480/2);
    if (sizes[0]!=115200) {
	    picture_decomp_v1(imagebufs[0],uncomp[0],320,480);
	    picture_decomp_v1(imagebufs[1],uncomp[1],320,480/2);
	    picture_decomp_v1(imagebufs[2],uncomp[2],320,480/2);
    } else {
	    picture_decomp_v2(imagebufs[0],uncomp[0],320,480);
	    picture_decomp_v2(imagebufs[1],uncomp[1],320,480/2);
	    picture_decomp_v2(imagebufs[2],uncomp[2],320,480/2);
    }
    gp_file_append(file, IMGHEADER, strlen(IMGHEADER));
    data = malloc(640*480*3);
    if (!raw) {
	unsigned char *bayerpre;
	s = bayerpre = malloc(640*480);
	/* note that picture is upside down and left<->right mirrored */
	for (h=480;h--;) {
	    int w;
	    for (w=320;w--;) {
		if (h&1) {
		    /* G B G B G B G B G */
		    *s++ = uncomp[2][(h/2)*320+w];
		    *s++ = uncomp[0][h*320+w];
		} else {
		    /* R G R G R G R G R */
		    *s++ = uncomp[0][h*320+w];
		    *s++ = uncomp[1][(h/2)*320+w];
		}
	    }
	}
	gp_bayer_decode(bayerpre,640,480,data,BAYER_TILE_RGGB);
	free(bayerpre);
    } else {
	s=data;
	for (h=480;h--;) { /* upside down */
	    int w;
	    for (w=640;w--;) { /* right to left */
		/* and images are in green red blue */
		*s++=uncomp[1][(h/2)*320+(w/2)];
		*s++=uncomp[0][h*320+(w/2)];
		*s++=uncomp[2][(h/2)*320+(w/2)];
	    }
	}
    }
    free(uncomp[0]);free(uncomp[1]);free(uncomp[2]);
    free(imagebufs[0]);free(imagebufs[1]);free(imagebufs[2]);free(imagebufs);
    gp_file_append(file, (char*)data, 640*480*3);
    free(data);
    return GP_OK;
}