* main.c: Removed.
* library.c: Reworked Bayer array decoding. Use global bayer routines. * library.c, barbie.c: Largish clean up. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@10297 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
7
camlibs/barbie/ChangeLog
Normal file
7
camlibs/barbie/ChangeLog
Normal file
@@ -0,0 +1,7 @@
|
||||
2007-05-23 Marcus Meissner <marcus@jet.franken.de>
|
||||
|
||||
* main.c: Removed.
|
||||
* library.c: Reworked Bayer array decoding.
|
||||
Use global bayer routines.
|
||||
|
||||
* library.c, barbie.c: Largish clean up.
|
||||
@@ -1,5 +1,3 @@
|
||||
EXTRA_DIST += barbie/main.c
|
||||
|
||||
EXTRA_LTLIBRARIES += barbie.la
|
||||
|
||||
barbie_la_SOURCES = \
|
||||
|
||||
@@ -38,7 +38,6 @@ int
|
||||
camera_id (CameraText *id)
|
||||
{
|
||||
strcpy(id->text, "barbie");
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
@@ -73,12 +72,8 @@ file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
|
||||
void *data, GPContext *context)
|
||||
{
|
||||
Camera *camera = data;
|
||||
int count;
|
||||
|
||||
count = barbie_file_count (camera->port);
|
||||
gp_list_populate (list, "mattel%02i.ppm", count);
|
||||
|
||||
return GP_OK;
|
||||
return gp_list_populate (list, "mattel%02i.ppm", barbie_file_count (camera->port));
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -92,6 +87,8 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
|
||||
|
||||
/* Retrieve the number of the photo on the camera */
|
||||
num = gp_filesystem_number (camera->fs, "/", filename, context);
|
||||
if (num < GP_OK)
|
||||
return num;
|
||||
|
||||
switch (type) {
|
||||
case GP_FILE_TYPE_NORMAL:
|
||||
@@ -110,7 +107,6 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
|
||||
gp_file_set_name (file, filename);
|
||||
gp_file_set_mime_type (file, "image/ppm");
|
||||
gp_file_set_data_and_size (file, data, size);
|
||||
|
||||
return GP_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <bayer.h>
|
||||
#include <gphoto2/gphoto2.h>
|
||||
#include "barbie.h"
|
||||
|
||||
@@ -17,31 +18,12 @@ static char *barbie_read_data (GPPort *port, char *cmd, int cmd_size, int data_t
|
||||
=======================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
barbie_packet_dump(GPPort *port, int direction, char *buf, int size) {
|
||||
int x;
|
||||
|
||||
if (direction == 0)
|
||||
GP_DEBUG( "\tRead Packet (%i): ", size);
|
||||
else
|
||||
GP_DEBUG( "\tWrite Packet (%i): ", size);
|
||||
for (x=0; x<size; x++) {
|
||||
if (isalpha(buf[x]))
|
||||
GP_DEBUG ("[ '%c' ] ", (unsigned char)buf[x]);
|
||||
else
|
||||
GP_DEBUG ("[ x%02x ] ", (unsigned char)buf[x]);
|
||||
}
|
||||
GP_DEBUG ("\n");
|
||||
}
|
||||
|
||||
static int
|
||||
barbie_write_command(GPPort *port, char *command, int size) {
|
||||
|
||||
int x;
|
||||
|
||||
barbie_packet_dump(port, 1, command, size);
|
||||
x=gp_port_write(port, command, size);
|
||||
return (x == GP_OK);
|
||||
x = gp_port_write(port, command, size);
|
||||
return (x >= GP_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -52,7 +34,6 @@ barbie_read_response(GPPort *port, char *response, int size) {
|
||||
|
||||
/* Read the ACK */
|
||||
x=gp_port_read(port, &ack, 1);
|
||||
barbie_packet_dump(port, 0, &ack, 1);
|
||||
|
||||
if ((ack != ACK)||(x<0))
|
||||
return (0);
|
||||
@@ -60,7 +41,6 @@ barbie_read_response(GPPort *port, char *response, int size) {
|
||||
/* Read the Response */
|
||||
memset(response, 0, size);
|
||||
x=gp_port_read(port,response, size);
|
||||
barbie_packet_dump(port, 0, response, x);
|
||||
return (x > 0);
|
||||
}
|
||||
|
||||
@@ -85,10 +65,9 @@ int barbie_exchange (GPPort *port, char *cmd, int cmd_size, char *resp, int resp
|
||||
}
|
||||
|
||||
int barbie_ping(GPPort *port) {
|
||||
|
||||
char cmd[4], resp[4];
|
||||
|
||||
GP_DEBUG( "Pinging the camera\n");
|
||||
GP_DEBUG( "Pinging the camera...");
|
||||
|
||||
memcpy(cmd, packet_1, 4);
|
||||
cmd[COMMAND_BYTE] = 'E';
|
||||
@@ -99,15 +78,14 @@ int barbie_ping(GPPort *port) {
|
||||
|
||||
if (resp[DATA1_BYTE] != 'x')
|
||||
return (0);
|
||||
GP_DEBUG ("Ping answered!\n");
|
||||
GP_DEBUG ("Ping answered!");
|
||||
return (1);
|
||||
}
|
||||
|
||||
int barbie_file_count (GPPort *port) {
|
||||
|
||||
char cmd[4], resp[4];
|
||||
|
||||
GP_DEBUG ("Getting the number of pictures\n");
|
||||
GP_DEBUG ("Getting the number of pictures...");
|
||||
|
||||
memcpy(cmd, packet_1, 4);
|
||||
|
||||
@@ -155,18 +133,17 @@ char *barbie_read_picture(GPPort *port, int picture_number, int get_thumbnail, i
|
||||
}
|
||||
|
||||
char *barbie_read_data (GPPort *port, char *cmd, int cmd_size, int data_type, int *size) {
|
||||
|
||||
char c, resp[4];
|
||||
int n1, n2, n3, n4, x, y, z;
|
||||
unsigned char r, g, b;
|
||||
char *s = NULL, *us = NULL, *rg = NULL;
|
||||
int cols, visrows, blackrows, statusbytes;
|
||||
int x, y, z;
|
||||
char *s = NULL, *us = NULL, *rg = NULL, *t = NULL;
|
||||
char ppmhead[64];
|
||||
|
||||
if (barbie_exchange(port, cmd, cmd_size, resp, 4) != 1)
|
||||
return (0);
|
||||
switch (data_type) {
|
||||
case BARBIE_DATA_FIRMWARE:
|
||||
GP_DEBUG ("Getting Firmware\n");
|
||||
GP_DEBUG ("Getting Firmware...");
|
||||
/* we're getting the firmware revision */
|
||||
*size = resp[2];
|
||||
s = (char *)malloc(sizeof(char)*(*size));
|
||||
@@ -178,25 +155,27 @@ char *barbie_read_data (GPPort *port, char *cmd, int cmd_size, int data_type, in
|
||||
}
|
||||
break;
|
||||
case BARBIE_DATA_PICTURE:
|
||||
GP_DEBUG( "Getting Picture\n");
|
||||
GP_DEBUG( "Getting Picture...");
|
||||
/* we're getting a picture */
|
||||
n1 = (unsigned char)resp[2];
|
||||
n2 = (unsigned char)resp[3];
|
||||
cols = (unsigned char)resp[2];
|
||||
blackrows = (unsigned char)resp[3];
|
||||
if (gp_port_read(port, &c, 1) < 0)
|
||||
return (NULL);
|
||||
n3 = (unsigned char)c;
|
||||
visrows = (unsigned char)c;
|
||||
if (gp_port_read(port, &c, 1) < 0)
|
||||
return (NULL);
|
||||
n4 = (unsigned char)c;
|
||||
*size = PICTURE_SIZE(n1, n2, n3, n4);
|
||||
printf("\tn1=%i n2=%i n3=%i n4=%i size=%i\n", n1, n2 ,n3, n4, *size);
|
||||
sprintf(ppmhead, "P6\n# test.ppm\n%i %i\n255\n", n1-1, (n2+n3-1));
|
||||
statusbytes = (unsigned char)c;
|
||||
*size = PICTURE_SIZE(cols, blackrows, visrows, statusbytes);
|
||||
sprintf(ppmhead, "P6\n# test.ppm\n%i %i\n255\n", cols-4, visrows);
|
||||
printf("\tcols=%i blackrows=%i visrows=%i statusbytes=%i size=%i\n", cols, blackrows ,visrows, statusbytes, *size);
|
||||
us = (char *)malloc(sizeof(char)*(*size));
|
||||
rg = (char *)malloc(sizeof(char)*(*size));
|
||||
s = (char *)malloc(sizeof(char)*(n1-1)*(n2+n3-1)*3+strlen(ppmhead));
|
||||
s = (char *)malloc(sizeof(char)*cols*(blackrows+visrows)*3+strlen(ppmhead));
|
||||
t = (char *)malloc(sizeof(char)*(cols-4)*visrows*3+strlen(ppmhead));
|
||||
memset(us, 0, *size);
|
||||
memset(rg, 0, *size);
|
||||
memset(s , 0, *size+strlen(ppmhead));
|
||||
memset(t , 0, *size+strlen(ppmhead));
|
||||
if (gp_port_read(port, us, *size)<0) {
|
||||
free(us);
|
||||
free(rg);
|
||||
@@ -205,31 +184,29 @@ printf("\tn1=%i n2=%i n3=%i n4=%i size=%i\n", n1, n2 ,n3, n4, *size);
|
||||
}
|
||||
/* Unshuffle the data */
|
||||
*size = *size - 16;
|
||||
for (x=0; x<(n2+n3); x++) {
|
||||
for (y=0; y<n1; y++) {
|
||||
z = x*n1 + y/2 + y%2*(n1/2+2);
|
||||
rg[x*n1+y] = us[z];
|
||||
for (x=0; x<blackrows+visrows; x++) {
|
||||
for (y=0; y<cols-4; y++) {
|
||||
z = x*cols + y/2 + (y%2)*(cols/2+2);
|
||||
rg[x*cols+(y^1)] = us[z];
|
||||
}
|
||||
}
|
||||
/* Camera uses Bayen array:
|
||||
* bg bg ...
|
||||
* gr gr ...
|
||||
free (us);
|
||||
strcpy (t, ppmhead);
|
||||
z = strlen(t);
|
||||
/* Camera uses a Bayer CCD array:
|
||||
* gb gb ...
|
||||
* rg rg ...
|
||||
*/
|
||||
strcpy(s, ppmhead);
|
||||
z = strlen(s);
|
||||
for (x=0; x<(n2+n3-1); x++) {
|
||||
for (y=0; y<(n1-1); y++) {
|
||||
b = (unsigned char)rg[x*n1+y];
|
||||
g = (((unsigned char)rg[(x+1)*n1+y] +
|
||||
(unsigned char)rg[x*n1+y+1]) / 2);
|
||||
r = (unsigned char)rg[(x+1)*n1+y+1];
|
||||
s[z++] = r;
|
||||
s[z++] = g;
|
||||
s[z++] = b;
|
||||
}
|
||||
}
|
||||
gp_bayer_decode (rg, cols, blackrows+visrows, s+z, BAYER_TILE_GBRG);
|
||||
free (rg);
|
||||
/* Shrink it a bit to avoid junk cols and black rows */
|
||||
for (x=0; x<visrows; x++)
|
||||
memcpy (t+z+x*(cols-4)*3,s+z+cols*(x+blackrows)*3,(cols-4)*3);
|
||||
z+= visrows*(cols-4)*3;
|
||||
*size = z;
|
||||
GP_DEBUG( "size=%i\n", *size);
|
||||
memcpy(s,t,z);
|
||||
free (t);
|
||||
GP_DEBUG( "size=%i", *size);
|
||||
break;
|
||||
case BARBIE_DATA_THUMBNAIL:
|
||||
break;
|
||||
@@ -238,12 +215,8 @@ printf("\tn1=%i n2=%i n3=%i n4=%i size=%i\n", n1, n2 ,n3, n4, *size);
|
||||
}
|
||||
/* read the footer */
|
||||
if (gp_port_read(port, &c, 1) < 0) {
|
||||
free(us);
|
||||
free(rg);
|
||||
free(s);
|
||||
return (0);
|
||||
}
|
||||
free(us);
|
||||
free(rg);
|
||||
return(s);
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "barbie.h"
|
||||
|
||||
char serial_port[32];
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
|
||||
int size, x;
|
||||
char *s;
|
||||
char fname[16];
|
||||
FILE *fp;
|
||||
sprintf(serial_port, "/dev/ttyS0");
|
||||
|
||||
if (barbie_initialize() != 1)
|
||||
printf("initialization failed\n");
|
||||
else
|
||||
printf("initialization succeeded\n");
|
||||
|
||||
for (x=3; x<=3; x++) {
|
||||
s = barbie_read_picture(x, 0,&size);
|
||||
if (s) {
|
||||
sprintf(fname, "temp-%i.ppm", x);
|
||||
fp = fopen(fname, "w");
|
||||
fwrite(s, size, 1, fp);
|
||||
fclose(fp);
|
||||
free(s);
|
||||
} else {
|
||||
printf("error!\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* display number of pictures
|
||||
printf("%i\n", barbie_number_of_pictures());
|
||||
*/
|
||||
|
||||
/* take a picture
|
||||
printf("%i\n", barbie_take_picture());
|
||||
*/
|
||||
|
||||
/* firmware revision
|
||||
s = barbie_read_firmware();
|
||||
if (s) {
|
||||
printf("%s\n", s);
|
||||
free(s);
|
||||
} else {
|
||||
printf("0\n");
|
||||
}
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user