Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Unified Diff: examples/thumb.c

Issue 2364793002: Revert "Uprev libmtp to 1.1.12" (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libmtp@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/sendtr.c ('k') | examples/tracks.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/thumb.c
diff --git a/examples/thumb.c b/examples/thumb.c
index 3dc360e3a1ef036df3d84ac9caefbe5bc9575e1d..2718a0c44468e493c72d4409a0b545ed60b9fbed 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;
- char *imagedata = NULL;
+ uint8_t *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 = statbuff.st_size;
- imagedata = malloc(filesize);
+ filesize = (uint64_t) statbuff.st_size;
+ imagedata = malloc(filesize * sizeof(uint16_t));
#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 {
- ret = read(fd, imagedata, filesize);
- if (ret == -1) perror("read thumb data");
+ }
+ else {
+ read(fd, imagedata, filesize);
close(fd);
}
@@ -105,9 +105,16 @@ int main (int argc, char **argv) {
}
LIBMTP_filesampledata_t *thumb = LIBMTP_new_filesampledata_t();
- thumb->data = imagedata;
+
+ int i;
+ thumb->data = malloc(sizeof(uint16_t) * filesize);
+ for (i = 0; i < filesize; i++) {
+ thumb->data[i] = imagedata[i];
+ }
+
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");
@@ -115,6 +122,7 @@ int main (int argc, char **argv) {
LIBMTP_Clear_Errorstack(device);
}
+ free(imagedata);
LIBMTP_destroy_filesampledata_t(thumb);
LIBMTP_Release_Device(device);
« no previous file with comments | « examples/sendtr.c ('k') | examples/tracks.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698