2001-10-01 Lutz M�ller <urc8@rz.uni-karlsruhe.de>

* camlibs/konica: Rejoice, we no longer have a glib dependency!


git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@2348 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Lutz Mueller
2001-10-01 18:00:19 +00:00
parent 73441bd952
commit 6de0760d28
6 changed files with 134 additions and 139 deletions

View File

@@ -1,3 +1,7 @@
2001-10-01 Lutz Müller <urc8@rz.uni-karlsruhe.de>
* camlibs/konica: Rejoice, we no longer have a glib dependency!
2001-10-01 Lutz Müller <urc8@rz.uni-karlsruhe.de>
* camlibs/konica/konica.[c,h]:

View File

@@ -3,8 +3,6 @@ SUBDIRS = localization
camlibdir = $(prefix)/lib/gphoto2
camlib_LTLIBRARIES = libgphoto2_konica.la
CFLAGS = @CFLAGS@ `glib-config --cflags`
LDFLAGS = @LDFLAGS@ `glib-config --libs`
EXTRA_DIST = EXPERTS
INCLUDES =\

View File

@@ -19,7 +19,6 @@
*/
#include <gphoto2.h>
#include <glib.h>
#include <stdlib.h>
#include <stdio.h>
@@ -110,7 +109,7 @@ k_init (gp_port* device)
}
int
k_erase_image (gp_port* device, gboolean image_id_long, unsigned long image_id)
k_erase_image (gp_port* device, int image_id_long, unsigned long image_id)
{
/************************************************/
/* Command to erase one image. */
@@ -158,7 +157,7 @@ k_erase_image (gp_port* device, gboolean image_id_long, unsigned long image_id)
}
gint
int
k_format_memory_card (gp_port* device)
{
/************************************************/
@@ -191,7 +190,8 @@ k_format_memory_card (gp_port* device)
}
gint k_erase_all (gp_port* device, guint* number_of_images_not_erased)
int
k_erase_all (gp_port* device, unsigned int *number_of_images_not_erased)
{
/************************************************/
/* Command to erase all images in the camera, */
@@ -231,8 +231,8 @@ gint k_erase_all (gp_port* device, guint* number_of_images_not_erased)
int
k_set_protect_status (gp_port *device, gboolean image_id_long,
unsigned long image_id, gboolean protected)
k_set_protect_status (gp_port *device, int image_id_long,
unsigned long image_id, int protected)
{
/************************************************/
/* Command to set the protect status of one */
@@ -289,12 +289,12 @@ k_set_protect_status (gp_port *device, gboolean image_id_long,
int
k_get_image (
gp_port* device,
gboolean image_id_long,
unsigned long image_id,
gp_port *device,
int image_id_long,
unsigned long image_id,
KImageType image_type,
unsigned char** image_buffer,
guint* image_buffer_size)
unsigned char **image_buffer,
unsigned int *image_buffer_size)
{
/************************************************/
/* Commands to get an image from the camera. */
@@ -330,7 +330,7 @@ k_get_image (
unsigned char sb[] = {0x00, 0x88, 0x00, 0x00, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00};
unsigned char *rb = NULL;
guint rbs;
unsigned int rbs;
CHECK_NULL (image_buffer && image_buffer_size);
@@ -366,14 +366,14 @@ k_get_image (
int
k_get_image_information (
gp_port* device,
gboolean image_id_long,
unsigned long image_number,
unsigned long* image_id,
guint* exif_size,
gboolean* protected,
unsigned char** information_buffer,
guint* information_buffer_size)
gp_port *device,
int image_id_long,
unsigned long image_number,
unsigned long *image_id,
unsigned int *exif_size,
int *protected,
unsigned char **information_buffer,
unsigned int *information_buffer_size)
{
/************************************************/
/* Command to get the information about an */
@@ -446,8 +446,8 @@ k_get_image_information (
}
int
k_get_preview (gp_port* device, gboolean thumbnail,
unsigned char** image_buffer, guint* image_buffer_size)
k_get_preview (gp_port* device, int thumbnail,
unsigned char **image_buffer, unsigned int *image_buffer_size)
{
/************************************************/
/* Command to get the preview from the camera. */
@@ -527,17 +527,17 @@ k_get_io_capability (gp_port *device,
int
k_get_information (
gp_port* device,
gchar** model,
gchar** serial_number,
unsigned char* hardware_version_major,
unsigned char* hardware_version_minor,
unsigned char* software_version_major,
unsigned char* software_version_minor,
unsigned char* testing_software_version_major,
unsigned char* testing_software_version_minor,
gchar** name,
gchar** manufacturer)
gp_port *device,
char **model,
char **serial_number,
unsigned char *hardware_version_major,
unsigned char *hardware_version_minor,
unsigned char *software_version_major,
unsigned char *software_version_minor,
unsigned char *testing_software_version_major,
unsigned char *testing_software_version_minor,
char **name,
char **manufacturer)
{
/************************************************/
/* Command to get some information about the */
@@ -636,7 +636,7 @@ k_get_information (
/* 0xXX: Byte 29 of manufacturer */
/************************************************/
unsigned char sb[] = {0x10, 0x90, 0x00, 0x00};
guint i, j;
unsigned int i, j;
unsigned char *rb = NULL;
unsigned int rbs;
@@ -650,14 +650,17 @@ k_get_information (
/* Model */
for (i = 0; i < 4; i++) if (rb[8 + i] == 0) break;
*model = g_new0 (gchar, i + 1);
for (j = 0; j < i; j++) (*model)[j] = rb[8 + j];
*model = malloc (sizeof (char) * (i + 1));
for (j = 0; j < i; j++)
(*model)[j] = rb[8 + j];
(*model)[j] = 0;
/* Serial Number */
for (i = 0; i < 10; i++) if (rb[12 + i] == 0) break;
*serial_number = g_new0 (gchar, i + 1);
*serial_number = malloc (sizeof (char) * (i + 1));
for (j = 0; j < i; j++)
(*serial_number)[j] = rb[12 + j];
(*serial_number)[j] = 0;
/* Versions */
*hardware_version_major = rb[22];
@@ -669,13 +672,17 @@ k_get_information (
/* Name */
for (i = 0; i < 22; i++) if (rb[28 + i] == 0) break;
*name = g_new0 (gchar, i + 1);
for (j = 0; j < i; j++) (*name)[j] = rb[28 + j];
*name = malloc (sizeof (char) * (i + 1));
for (j = 0; j < i; j++)
(*name)[j] = rb[28 + j];
(*name)[j] = 0;
/* Manufacturer */
for (i = 0; i < 30; i++) if (rb[50 + i] == 0) break;
*manufacturer = g_new0 (gchar, i + 1);
for (j = 0; j < i; j++) (*manufacturer)[j] = rb[50 + j];
*manufacturer = malloc (sizeof (char) * (i + 1));
for (j = 0; j < i; j++)
(*manufacturer)[j] = rb[50 + j];
(*manufacturer)[j] = 0;
free (rb);
return (GP_OK);
@@ -1088,13 +1095,13 @@ k_reset_preferences (gp_port *device)
int
k_take_picture (
gp_port* device,
gboolean image_id_long,
unsigned long* image_id,
guint* exif_size,
unsigned char** information_buffer,
guint* information_buffer_size,
gboolean* protected)
gp_port *device,
int image_id_long,
unsigned long *image_id,
unsigned int *exif_size,
unsigned char **information_buffer,
unsigned int *information_buffer_size,
int *protected)
{
/************************************************/
/* Command to take a picture. */

View File

@@ -260,24 +260,24 @@ int k_format_memory_card (gp_port *device);
int k_take_picture (
gp_port *device,
gboolean image_id_long,
int image_id_long,
unsigned long *image_id,
unsigned int *exif_size,
unsigned char **information_buffer,
unsigned int *information_buffer_size,
gboolean *protected);
int *protected);
int k_get_preview (gp_port *device, gboolean thumbnail,
int k_get_preview (gp_port *device, int thumbnail,
unsigned char **image_buffer,
unsigned int *image_buffer_size);
int k_set_protect_status (gp_port *device, gboolean image_id_long,
unsigned long image_id, gboolean protected);
int k_set_protect_status (gp_port *device, int image_id_long,
unsigned long image_id, int protected);
int k_erase_image (gp_port *device, gboolean image_id_long,
int k_erase_image (gp_port *device, int image_id_long,
unsigned long image_id);
@@ -335,17 +335,17 @@ int k_get_information (
int k_get_image_information (
gp_port *device,
gboolean image_id_long,
int image_id_long,
unsigned long image_number,
unsigned long *image_id,
unsigned int *exif_size,
gboolean *protected,
int *protected,
unsigned char **information_buffer,
unsigned int *information_buffer_size);
int k_get_image (
gp_port *device,
gboolean image_id_long,
int image_id_long,
unsigned long image_id,
KImageType image_type,
unsigned char **image_buffer,

View File

@@ -23,7 +23,6 @@
#include <gphoto2-frontend.h>
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <string.h>
#include <time.h>
@@ -49,7 +48,7 @@
#define CHECK(r) {int ret = (r); if (ret < 0) return (ret);}
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
static gchar* konica_results[] = {
static char *konica_results[] = {
/* FOCUSING_ERROR */ N_("Focusing error"),
/* IRIS_ERROR */ N_("Iris error"),
/* STROBE_ERROR */ N_("Strobe error"),
@@ -78,7 +77,7 @@ static gchar* konica_results[] = {
};
static struct {
const gchar *model;
const char *model;
int image_id_long;
int vendor;
int product;
@@ -112,7 +111,7 @@ file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
unsigned int i;
unsigned char *information_buffer = NULL;
unsigned int exif_size, information_buffer_size;
gboolean protected;
int protected;
unsigned long image_id;
char filename[1024];
int result;
@@ -132,7 +131,7 @@ file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
kd->image_id_long, i + 1, &image_id, &exif_size,
&protected, &information_buffer,
&information_buffer_size);
g_free (information_buffer);
free (information_buffer);
information_buffer = NULL;
CHECK (result);
@@ -366,8 +365,8 @@ set_info_func (CameraFilesystem *fs, const char *folder, const char *file,
Camera *camera = data;
KonicaData *kd = camera->camlib_data;
char tmp[7];
gboolean protected;
gulong image_id;
int protected;
unsigned long image_id;
gp_debug_printf (GP_DEBUG_LOW, "konica", "*** Entering set_info_func "
"***");
@@ -405,7 +404,7 @@ get_info_func (CameraFilesystem *fs, const char *folder, const char *file,
unsigned long image_id;
unsigned int information_buffer_size, exif_size;
unsigned char *information_buffer = NULL;
gboolean protected;
int protected;
gp_debug_printf (GP_DEBUG_LOW, "konica", "*** ENTER: get_info_func "
"***");
@@ -414,7 +413,7 @@ get_info_func (CameraFilesystem *fs, const char *folder, const char *file,
gp_filesystem_number (camera->fs, folder, file),
&image_id, &exif_size, &protected,
&information_buffer, &information_buffer_size));
g_free (information_buffer);
free (information_buffer);
info->preview.fields = GP_FILE_INFO_SIZE | GP_FILE_INFO_TYPE;
info->preview.size = information_buffer_size;
@@ -445,7 +444,7 @@ camera_exit (Camera* camera)
}
static int
camera_folder_delete_all (Camera* camera, const gchar* folder)
camera_folder_delete_all (Camera* camera, const char* folder)
{
unsigned int not_erased = 0;
char tmp[1024];
@@ -470,8 +469,8 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
CameraFileType type, CameraFile *file, void *data)
{
Camera *camera = data;
gulong image_id;
gchar* image_id_string;
unsigned long image_id;
char image_id_string[] = {0, 0, 0, 0, 0, 0, 0};
KonicaData *kd = camera->camlib_data;
unsigned char *fdata = NULL;
long int size;
@@ -481,22 +480,21 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
if (strcmp (folder, "/"))
return (GP_ERROR_DIRECTORY_NOT_FOUND);
/* Check if we can get the image id from the filename. */
image_id_string = g_strndup (filename, 6);
image_id = atol (image_id_string);
g_free (image_id_string);
/* Check if we can get the image id from the filename. */
strncpy (image_id_string, filename, 6);
image_id = atol (image_id_string);
/* Get the image. */
switch (type) {
case GP_FILE_TYPE_PREVIEW:
CHECK (k_get_image (camera->port, kd->image_id_long, image_id,
K_THUMBNAIL, (unsigned char **) &fdata,
(guint *) &size));
(unsigned int *) &size));
break;
case GP_FILE_TYPE_NORMAL:
CHECK (k_get_image (camera->port, kd->image_id_long, image_id,
K_IMAGE_EXIF, (unsigned char **) &fdata,
(guint *) &size));
(unsigned int *) &size));
break;
default:
return (GP_ERROR_NOT_SUPPORTED);
@@ -509,7 +507,7 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
}
static int
camera_file_delete (Camera* camera, const gchar* folder, const gchar* filename)
camera_file_delete (Camera* camera, const char *folder, const char *filename)
{
char tmp[] = {0, 0, 0, 0, 0, 0, 0};
unsigned long image_id;
@@ -579,7 +577,8 @@ camera_capture_preview (Camera* camera, CameraFile* file)
unsigned char *data = NULL;
long int size;
CHECK (k_get_preview (camera->port, TRUE, &data, (guint*) &size));
CHECK (k_get_preview (camera->port, TRUE,
&data, (unsigned int *) &size));
CHECK (gp_file_set_data_and_size (file, data, size));
CHECK (gp_file_set_mime_type (file, GP_MIME_JPEG));
@@ -594,8 +593,7 @@ camera_capture (Camera* camera, int type, CameraFilePath* path)
int exif_size;
unsigned char *information_buffer = NULL;
unsigned int information_buffer_size;
gboolean protected;
char *tmp;
int protected;
CHECK_NULL (camera && path);
@@ -610,18 +608,12 @@ camera_capture (Camera* camera, int type, CameraFilePath* path)
&exif_size, &information_buffer, &information_buffer_size,
&protected));
g_free (information_buffer);
tmp = g_strdup_printf ("%06i.jpeg", (int) image_id);
strcpy (path->name, tmp);
g_free (tmp);
strcpy (path->folder, "/");
free (information_buffer);
sprintf (path->name, "%06i.jpeg", (int) image_id);
strcpy (path->folder, "/");
CHECK (gp_filesystem_append (camera->fs, path->folder, path->name));
gp_debug_printf (GP_DEBUG_LOW, "konica",
"*** filename: %s", path->name);
gp_debug_printf (GP_DEBUG_LOW, "konica",
"*** Leaving camera_capture ***");
return (GP_OK);
}
@@ -973,14 +965,14 @@ camera_set_config (Camera *camera, CameraWidget *window)
result = localization_file_read (camera, c,
&data, &data_size);
if (result != GP_OK) {
g_free (data);
free (data);
return (result);
}
/* Go! */
result = k_localization_data_put (camera->port,
data, data_size);
g_free (data);
free (data);
CHECK (result);
}
}
@@ -997,7 +989,7 @@ camera_set_config (Camera *camera, CameraWidget *window)
else if (!strcmp (c, _("Do not display TV menu")))
tv_output_format = K_TV_OUTPUT_FORMAT_HIDE;
else
g_assert_not_reached ();
return (GP_ERROR);
CHECK (k_localization_tv_output_format_set (
camera->port, tv_output_format));
}
@@ -1015,7 +1007,7 @@ camera_set_config (Camera *camera, CameraWidget *window)
else if (!strcmp (c, _("Year/Month/Day")))
date_format = K_DATE_FORMAT_YEAR_MONTH_DAY;
else
g_assert_not_reached ();
return (GP_ERROR);
CHECK (k_localization_date_format_set (camera->port,
date_format));
}
@@ -1195,18 +1187,18 @@ localization_file_read (Camera *camera, const char *file_name,
}
} while (f != EOF);
fclose (file);
/*********************************/
/* Calculate and check checksum. */
/*********************************/
checksum = 0;
g_warning (_("Checksum not implemented!"));
gp_debug_printf (GP_DEBUG_HIGH, "core", "Checksum not implemented!");
/*FIXME: There's a checksum at (*data)[100]. I could not
figure out how it is calculated. */
/*********************************************/
/* Calculate and check frame check sequence. */
/*********************************************/
fcs = 0;
g_warning (_("Frame check sequence not implemented!"));
gp_debug_printf (GP_DEBUG_LOW, "konica", "Frame check sequence "
"not implemented!");
/* FIXME: There's a frame check sequence at (*data)[108]
and (*data)[109]. I could not figure out how it is
calculated. */
@@ -1219,7 +1211,7 @@ int
camera_init (Camera* camera)
{
int i;
gboolean image_id_long;
int image_id_long;
int inep, outep;
KonicaData *kd;
gp_port_settings settings;
@@ -1283,7 +1275,7 @@ camera_init (Camera* camera)
}
/* Store some data we constantly need. */
kd = g_new (KonicaData, 1);
kd = malloc (sizeof (KonicaData));
camera->camlib_data = kd;
kd->image_id_long = image_id_long;

View File

@@ -20,7 +20,6 @@
#include <gphoto2-result.h>
#include <gphoto2-debug.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
@@ -43,8 +42,9 @@
/* Not an ESC quote */
#define EOT 0x04
#define CHECK(r) {int ret = (r); if (ret < 0) return (ret);}
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
#define CHECK(r) {int ret = (r); if (ret < 0) return (ret);}
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
#define CHECK_FREE(r,f) {int ret = (r); if (ret < 0) {free (f); return (ret);}}
int
l_init (gp_port* device)
@@ -223,7 +223,7 @@ l_send (gp_port* device, unsigned char *send_buffer,
/* the checksum byte(s). */
/********************************************************/
sbs = send_buffer_size + 5;
sb = g_new (guchar, sbs);
sb = malloc (sizeof (char) * sbs);
sb[0] = STX;
sb[1] = send_buffer_size;
sb[2] = send_buffer_size >> 8;
@@ -240,7 +240,7 @@ l_send (gp_port* device, unsigned char *send_buffer,
(*send_buffer == NACK) ||
(*send_buffer == ETB ) ||
(*send_buffer == ESC )) {
sb = g_renew (guchar, sb, ++sbs);
sb = realloc (sb, ++sbs * sizeof (char));
sb[ i] = ESC;
sb[++i] = ~*send_buffer;
} else sb[ i] = *send_buffer;
@@ -257,46 +257,36 @@ l_send (gp_port* device, unsigned char *send_buffer,
(checksum == NACK) ||
(checksum == ETB ) ||
(checksum == ESC )) {
sb = g_renew (guchar, sb, ++sbs);
sb = realloc (sb, ++sbs * sizeof (char));
sb[sbs - 2] = ESC;
sb[sbs - 1] = ~checksum;
} else sb[sbs - 1] = checksum;
for (i = 0; ; i++) {
/************************/
/* Write data as above. */
/************************/
if ((result = gp_port_write (device, sb, sbs)) != GP_OK) {
g_free (sb);
return (result);
}
if ((result = gp_port_read (device, &c, 1)) < 1) {
g_free (sb);
return (result);
}
CHECK_FREE (gp_port_write (device, sb, sbs), sb);
CHECK_FREE (gp_port_read (device, &c, 1), sb);
switch (c) {
case ACK:
/******************************************************/
/* ACK received. We can proceed. */
/******************************************************/
g_free (sb);
/****************/
/* ACK received. We can proceed. */
free (sb);
/* Write EOT. */
/****************/
c = EOT;
if ((result = gp_port_write (device, &c, 1)) != GP_OK) return (result);
CHECK (gp_port_write (device, &c, 1));
return (GP_OK);
case NACK:
/******************************************************/
/* NACK received. We'll try up to three times. */
/******************************************************/
/* NACK received. We'll try up to three times. */
if (i == 2) {
g_free (sb);
free (sb);
return (GP_ERROR_CORRUPTED_DATA);
} else break;
default:
/******************************************************/
/* Should not happen. */
/******************************************************/
/* Should not happen. */
return (GP_ERROR_CORRUPTED_DATA);
}
}
@@ -304,10 +294,11 @@ l_send (gp_port* device, unsigned char *send_buffer,
static int
l_receive (gp_port* device, guchar** rb, guint* rbs, guint timeout)
l_receive (gp_port* device, unsigned char **rb, unsigned int *rbs,
unsigned int timeout)
{
unsigned char c, d;
gboolean error_flag;
int error_flag;
unsigned int i, j, rbs_internal;
unsigned char checksum;
int result;
@@ -388,11 +379,14 @@ l_receive (gp_port* device, guchar** rb, guint* rbs, guint timeout)
CHECK (l_esc_read (device, &d));
checksum += d;
rbs_internal = (d << 8) | c;
if (*rbs == 0) *rb = g_new (guchar, rbs_internal);
else *rb = g_renew (guchar, *rb, *rbs + rbs_internal);
if (*rbs == 0)
*rb = malloc (rbs_internal * sizeof (char));
else
*rb = realloc (*rb,
sizeof (char) * (*rbs + rbs_internal));
/* Read 'rbs_internal' bytes data plus ESC quotes. */
error_flag = FALSE;
error_flag = 0;
for (i = 0; i < rbs_internal; i++) {
result = l_esc_read (device, &((*rb)[*rbs + i]));
switch (result) {
@@ -403,7 +397,7 @@ l_receive (gp_port* device, guchar** rb, guint* rbs, guint timeout)
/* plus ESC quotes and reject the */
/* packet. */
/**************************************/
error_flag = TRUE;
error_flag = 1;
break;
case GP_OK:
@@ -450,7 +444,7 @@ l_receive (gp_port* device, guchar** rb, guint* rbs, guint timeout)
CHECK (gp_port_read (device,
&d, 1));
}
error_flag = TRUE;
error_flag = 1;
break;
}
}