corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmke...@apache.org
Subject [63/92] [abbrv] incubator-corinthia git commit: Determine image dimensions from memory, not a file
Date Wed, 17 Dec 2014 13:29:13 GMT
Determine image dimensions from memory, not a file

Change the DFGetImageDimensions to read image data from memory, rather
than a file. This is because we're abstracting over all direct
filesystem access, so that data can be accessed from other places, e.g.
within a .docx or .odt file (actually a zip archive).

To call DFGetImageDimensions, you must now read the data into memory
(ideally via the DFPackage abstraction), rather than supplying a
physical filesystem path.


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/b584e132
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/b584e132
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/b584e132

Branch: refs/heads/stable
Commit: b584e13267ec15fced85929749daaf1b6c6c9dc2
Parents: c709941
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Fri Dec 5 01:06:29 2014 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Fri Dec 5 01:06:29 2014 +0700

----------------------------------------------------------------------
 .../filters/ooxml/src/word/lenses/WordDrawing.c | 12 +++++++++++-
 DocFormats/platform/headers/DFPlatform.h        |  4 +++-
 DocFormats/platform/src/Apple.c                 | 20 +++++++-------------
 DocFormats/platform/src/Linux.c                 |  5 +++--
 DocFormats/platform/src/Win32.c                 |  6 ++++--
 5 files changed, 28 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/b584e132/DocFormats/filters/ooxml/src/word/lenses/WordDrawing.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/src/word/lenses/WordDrawing.c b/DocFormats/filters/ooxml/src/word/lenses/WordDrawing.c
index 33fc891..f9f2ca0 100644
--- a/DocFormats/filters/ooxml/src/word/lenses/WordDrawing.c
+++ b/DocFormats/filters/ooxml/src/word/lenses/WordDrawing.c
@@ -417,14 +417,24 @@ static int getImageFile(WordConverter *converter, const char *src, PixelSize
*si
     size->widthPx = 0;
     size->heightPx = 0;
 
+    int ok = 0;
+    char *ext = DFPathExtension(src);
     char *unescapedSrc = DFRemovePercentEncoding(src);
     char *abstractPathSlash = DFFormatString("%s/",converter->abstractPath);
     char *newSrcPath = DFPathResolveAbsolute(abstractPathSlash,unescapedSrc);
 
-    int ok = DFGetImageDimensions(newSrcPath,&size->widthPx,&size->heightPx,error);
+    DFBuffer *imageData = DFBufferReadFromFile(newSrcPath,error);
+    if (imageData == NULL)
+        goto end;
+
+    ok = DFGetImageDimensions(imageData->data,imageData->len,ext,&size->widthPx,&size->heightPx,error);
+
+end:
     free(abstractPathSlash);
     free(unescapedSrc);
     free(newSrcPath);
+    free(ext);
+    DFBufferRelease(imageData);
     return ok;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/b584e132/DocFormats/platform/headers/DFPlatform.h
----------------------------------------------------------------------
diff --git a/DocFormats/platform/headers/DFPlatform.h b/DocFormats/platform/headers/DFPlatform.h
index 5b98050..238a09f 100755
--- a/DocFormats/platform/headers/DFPlatform.h
+++ b/DocFormats/platform/headers/DFPlatform.h
@@ -17,10 +17,12 @@
 
 #include "DFError.h"
 #include "DFArray.h"
+#include <stddef.h>
 
 int DFMkdirIfAbsent(const char *path, DFError **error);
 int DFAddDirContents(const char *absPath, const char *relPath, int recursive, DFArray *array,
DFError **error);
-int DFGetImageDimensions(const char *path, unsigned int *width, unsigned int *height, DFError
**error);
+int DFGetImageDimensions(const void *data, size_t len, const char *ext,
+                         unsigned int *width, unsigned int *height, DFError **error);
 
 #define DF_ONCE_INIT 0
 typedef int DFOnce;

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/b584e132/DocFormats/platform/src/Apple.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Apple.c b/DocFormats/platform/src/Apple.c
index 8e5b319..6de1b38 100644
--- a/DocFormats/platform/src/Apple.c
+++ b/DocFormats/platform/src/Apple.c
@@ -21,22 +21,16 @@
 
 #include <ImageIO/ImageIO.h>
 
-int DFGetImageDimensions(const char *path, unsigned int *width, unsigned int *height, DFError
**error)
+int DFGetImageDimensions(const void *data, size_t len, const char *ext,
+                         unsigned int *width, unsigned int *height, DFError **error)
 {
-    CFStringRef srcPath = CFStringCreateWithBytes(kCFAllocatorDefault,(const UInt8 *)path,
-                                                  strlen(path),kCFStringEncodingUTF8,0);
-    if (srcPath == NULL)
-        return 0;
+    // FIXME: Should use ext here to determine the UTI, and pass that in the options directory
+    // (the second parameter to CGImageSourceCreateWithData)
 
-    CFURLRef srcURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,srcPath,kCFURLPOSIXPathStyle,0);
-    CFRelease(srcPath);
-    if (srcURL == NULL) {
-        CFRelease(srcPath);
-        return 0;
-    }
+    CFDataRef cfdata = CFDataCreate(NULL,data,len);
+    CGImageSourceRef imageSrc = CGImageSourceCreateWithData(cfdata,NULL);
+    CFRelease(cfdata);
 
-    CGImageSourceRef imageSrc = CGImageSourceCreateWithURL(srcURL,NULL);
-    CFRelease(srcURL);
     if (imageSrc == NULL)
         return 0;
 

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/b584e132/DocFormats/platform/src/Linux.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Linux.c b/DocFormats/platform/src/Linux.c
index 7937320..774908d 100644
--- a/DocFormats/platform/src/Linux.c
+++ b/DocFormats/platform/src/Linux.c
@@ -22,9 +22,10 @@
 
 #include <SDL2/SDL_image.h>
 
-int DFGetImageDimensions(const char *path, unsigned int *width, unsigned int *height, DFError
**error)
+int DFGetImageDimensions(const void *data, size_t len, const char *ext,
+                         unsigned int *width, unsigned int *height, DFError **error)
 {
-    SDL_Surface *image = IMG_Load(path);
+    SDL_Surface *image = IMG_Load_RW(SDL_RWFromMem((void *)data,len),1);
     if (image == NULL) {
         DFErrorFormat(error,"%s",IMG_GetError());
         return 0;

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/b584e132/DocFormats/platform/src/Win32.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Win32.c b/DocFormats/platform/src/Win32.c
index bcf2251..6e680ff 100755
--- a/DocFormats/platform/src/Win32.c
+++ b/DocFormats/platform/src/Win32.c
@@ -23,6 +23,7 @@
 
 #include <windows.h>
 #include <SDL_image.h>
+#include <stdio.h>
 
 void DFErrorSetWin32(DFError **error, DWORD code)
 {
@@ -117,9 +118,10 @@ int DFAddDirContents(const char *absPath, const char *relPath, int recursive,
DF
     return ok;
 }
 
-int DFGetImageDimensions(const char *path, unsigned int *width, unsigned int *height, DFError
**error)
+int DFGetImageDimensions(const void *data, size_t len, const char *ext,
+                         unsigned int *width, unsigned int *height, DFError **error)
 {
-    SDL_Surface *image = IMG_Load(path);
+    SDL_Surface *image = IMG_Load_RW(SDL_RWFromMem((void *)data,len),1);
     if (image == NULL) {
         DFErrorFormat(error,"%s",IMG_GetError());
         return 0;


Mime
View raw message