summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMarcus Meissner <marcus@jet.franken.de>2015-10-04 14:56:03 +0200
committerMarcus Meissner <marcus@jet.franken.de>2015-10-04 14:56:03 +0200
commitf59e7fdfd114d3c72c8d8a640f33bd823e20dc17 (patch)
tree812c6d35b768942c8ce08b64e94e69dc8758f338 /examples
parent1e3a5bbc3cb7813eeb2959c6a97a84ff7590a530 (diff)
downloadlibmtp-f59e7fdfd114d3c72c8d8a640f33bd823e20dc17.tar.gz
simplify the reader logic, there is no 16 bit entity involved
we just copy around the data directly
Diffstat (limited to 'examples')
-rw-r--r--examples/thumb.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/examples/thumb.c b/examples/thumb.c
index 2718a0c..3dc360e 100644
--- a/examples/thumb.c
+++ b/examples/thumb.c
@@ -47,7 +47,7 @@ int main (int argc, char **argv) {
int fd;
uint32_t id = 0;
uint64_t filesize;
- uint8_t *imagedata = NULL;
+ char *imagedata = NULL;
char *path = NULL;
char *rest;
struct stat statbuff;
@@ -81,8 +81,8 @@ int main (int argc, char **argv) {
perror("stat");
exit(1);
}
- filesize = (uint64_t) statbuff.st_size;
- imagedata = malloc(filesize * sizeof(uint16_t));
+ filesize = statbuff.st_size;
+ imagedata = malloc(filesize);
#ifdef __WIN32__
if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
@@ -91,9 +91,9 @@ int main (int argc, char **argv) {
#endif
printf("Couldn't open image file %s (%s)\n",path,strerror(errno));
return 1;
- }
- else {
- read(fd, imagedata, filesize);
+ } else {
+ ret = read(fd, imagedata, filesize);
+ if (ret == -1) perror("read thumb data");
close(fd);
}
@@ -105,16 +105,9 @@ int main (int argc, char **argv) {
}
LIBMTP_filesampledata_t *thumb = LIBMTP_new_filesampledata_t();
-
- int i;
- thumb->data = malloc(sizeof(uint16_t) * filesize);
- for (i = 0; i < filesize; i++) {
- thumb->data[i] = imagedata[i];
- }
-
+ thumb->data = imagedata;
thumb->size = filesize;
thumb->filetype = LIBMTP_FILETYPE_JPEG;
-
ret = LIBMTP_Send_Representative_Sample(device,id,thumb);
if (ret != 0) {
printf("Couldn't send thumbnail\n");
@@ -122,7 +115,6 @@ int main (int argc, char **argv) {
LIBMTP_Clear_Errorstack(device);
}
- free(imagedata);
LIBMTP_destroy_filesampledata_t(thumb);
LIBMTP_Release_Device(device);