Skip to content

Commit e8d2a9c

Browse files
Extend ImageFactory.createIo to create a MemIo
1 parent 8710193 commit e8d2a9c

File tree

5 files changed

+429
-9
lines changed

5 files changed

+429
-9
lines changed

src/interface/image.i

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ WINDOWS_PATH(const std::string& path)
8888
%typemap(default) bool enable {$1 = true;}
8989
%ignore Exiv2::enableBMFF();
9090

91+
// Extend ImageFactory to allow creation of a MemIo from a buffer
92+
%extend Exiv2::ImageFactory {
93+
static Exiv2::BasicIo::SMART_PTR createIo(
94+
const Exiv2::byte* data, size_t B) {
95+
#if EXIV2_VERSION_HEX < 0x001c0000
96+
return Exiv2::BasicIo::AutoPtr(new Exiv2::MemIo(data, B));
97+
#else
98+
return std::make_unique<Exiv2::MemIo>(data, B);
99+
#endif
100+
}
101+
}
102+
91103
// Make enableBMFF() function available regardless of exiv2 version
92104
%feature("docstring") enableBMFF "Enable BMFF support.
93105

src/swig-0_27_3/image_wrap.cxx

Lines changed: 161 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4861,6 +4861,80 @@ static PyObject* py_from_enum_Exiv2_ImageType(long value) {
48614861
return result;
48624862
};
48634863

4864+
4865+
#if defined(LLONG_MAX) && !defined(SWIG_LONG_LONG_AVAILABLE)
4866+
# define SWIG_LONG_LONG_AVAILABLE
4867+
#endif
4868+
4869+
4870+
#ifdef SWIG_LONG_LONG_AVAILABLE
4871+
SWIGINTERN int
4872+
SWIG_AsVal_unsigned_SS_long_SS_long (PyObject *obj, unsigned long long *val)
4873+
{
4874+
int res = SWIG_TypeError;
4875+
if (PyLong_Check(obj)) {
4876+
unsigned long long v = PyLong_AsUnsignedLongLong(obj);
4877+
if (!PyErr_Occurred()) {
4878+
if (val) *val = v;
4879+
return SWIG_OK;
4880+
} else {
4881+
PyErr_Clear();
4882+
res = SWIG_OverflowError;
4883+
}
4884+
} else {
4885+
unsigned long v;
4886+
res = SWIG_AsVal_unsigned_SS_long (obj,&v);
4887+
if (SWIG_IsOK(res)) {
4888+
if (val) *val = v;
4889+
return res;
4890+
}
4891+
}
4892+
#ifdef SWIG_PYTHON_CAST_MODE
4893+
{
4894+
const double mant_max = 1LL << DBL_MANT_DIG;
4895+
double d;
4896+
res = SWIG_AsVal_double (obj,&d);
4897+
if (SWIG_IsOK(res) && !SWIG_CanCastAsInteger(&d, 0, mant_max))
4898+
return SWIG_OverflowError;
4899+
if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, mant_max)) {
4900+
if (val) *val = (unsigned long long)(d);
4901+
return SWIG_AddCast(res);
4902+
}
4903+
res = SWIG_TypeError;
4904+
}
4905+
#endif
4906+
return res;
4907+
}
4908+
#endif
4909+
4910+
4911+
SWIGINTERNINLINE int
4912+
SWIG_AsVal_size_t (PyObject * obj, size_t *val)
4913+
{
4914+
int res = SWIG_TypeError;
4915+
#ifdef SWIG_LONG_LONG_AVAILABLE
4916+
if (sizeof(size_t) <= sizeof(unsigned long)) {
4917+
#endif
4918+
unsigned long v;
4919+
res = SWIG_AsVal_unsigned_SS_long (obj, val ? &v : 0);
4920+
if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v);
4921+
#ifdef SWIG_LONG_LONG_AVAILABLE
4922+
} else if (sizeof(size_t) <= sizeof(unsigned long long)) {
4923+
unsigned long long v;
4924+
res = SWIG_AsVal_unsigned_SS_long_SS_long (obj, val ? &v : 0);
4925+
if (SWIG_IsOK(res) && val) *val = static_cast< size_t >(v);
4926+
}
4927+
#endif
4928+
return res;
4929+
}
4930+
4931+
SWIGINTERN Exiv2::BasicIo::AutoPtr Exiv2_ImageFactory_createIo__SWIG_1(Exiv2::byte const *data,size_t B){
4932+
4933+
return Exiv2::BasicIo::AutoPtr(new Exiv2::MemIo(data, B));
4934+
4935+
4936+
4937+
}
48644938
#ifdef __cplusplus
48654939
extern "C" {
48664940
#endif
@@ -6230,20 +6304,19 @@ SWIGINTERN PyObject *_wrap_Image_imageType(PyObject *self, PyObject *args) {
62306304

62316305
SWIGPY_DESTRUCTOR_CLOSURE(_wrap_delete_Image) /* defines _wrap_delete_Image_destructor_closure */
62326306

6233-
SWIGINTERN PyObject *_wrap_ImageFactory_createIo(PyObject *self, PyObject *args) {
6307+
SWIGINTERN PyObject *_wrap_ImageFactory_createIo__SWIG_0(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) {
62346308
PyObject *resultobj = 0;
62356309
std::string *arg1 = 0 ;
62366310
bool arg2 ;
62376311
int res1 = SWIG_OLDOBJ ;
62386312
bool val2 ;
62396313
int ecode2 = 0 ;
6240-
PyObject *swig_obj[2] ;
62416314
Exiv2::BasicIo::AutoPtr result;
62426315

62436316
{
62446317
arg2 = true;
62456318
}
6246-
if (!SWIG_Python_UnpackTuple(args, "ImageFactory_createIo", 1, 2, swig_obj)) SWIG_fail;
6319+
if ((nobjs < 1) || (nobjs > 2)) SWIG_fail;
62476320
{
62486321
std::string *ptr = (std::string *)0;
62496322
res1 = SWIG_AsPtr_std_string(swig_obj[0], &ptr);
@@ -6858,6 +6931,91 @@ SWIGINTERN PyObject *_wrap_ImageFactory_checkType(PyObject *self, PyObject *args
68586931
}
68596932

68606933

6934+
SWIGINTERN PyObject *_wrap_ImageFactory_createIo__SWIG_1(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) {
6935+
PyObject *resultobj = 0;
6936+
Exiv2::byte *arg1 = (Exiv2::byte *) 0 ;
6937+
size_t arg2 ;
6938+
PyObject *_global_view = NULL ;
6939+
Exiv2::BasicIo::AutoPtr result;
6940+
6941+
if ((nobjs < 1) || (nobjs > 1)) SWIG_fail;
6942+
{
6943+
_global_view = PyMemoryView_GetContiguous(swig_obj[0], PyBUF_READ, 'A');
6944+
if (!_global_view) {
6945+
PyErr_Clear();
6946+
SWIG_exception_fail(SWIG_ArgError(SWIG_TypeError), "in method '" "ImageFactory_createIo" "', argument " "1"" of type '" "bytes-like object""'")
6947+
;
6948+
}
6949+
Py_buffer* buff = PyMemoryView_GET_BUFFER(_global_view);
6950+
arg1 = (Exiv2::byte *) buff->buf;
6951+
arg2 = (size_t) buff->len;
6952+
}
6953+
{
6954+
try {
6955+
result = Exiv2_ImageFactory_createIo__SWIG_1((unsigned char const *)arg1,SWIG_STD_MOVE(arg2));
6956+
}
6957+
catch(std::exception const& e) {
6958+
_set_python_exception();
6959+
SWIG_fail;
6960+
}
6961+
}
6962+
{
6963+
Exiv2::BasicIo* ptr = (&result)->release();
6964+
resultobj = SWIG_NewPointerObj(
6965+
ptr, basicio_subtype(ptr), SWIG_POINTER_OWN);
6966+
}
6967+
6968+
PyObject_SetAttrString(resultobj, "_refers_to", _global_view);
6969+
6970+
6971+
Py_XDECREF(_global_view);
6972+
6973+
return resultobj;
6974+
fail:
6975+
6976+
Py_XDECREF(_global_view);
6977+
6978+
return NULL;
6979+
}
6980+
6981+
6982+
SWIGINTERN PyObject *_wrap_ImageFactory_createIo(PyObject *self, PyObject *args) {
6983+
Py_ssize_t argc;
6984+
PyObject *argv[3] = {
6985+
0
6986+
};
6987+
6988+
(void)self;
6989+
if (!(argc = SWIG_Python_UnpackTuple(args, "ImageFactory_createIo", 0, 2, argv))) SWIG_fail;
6990+
--argc;
6991+
if ((argc >= 1) && (argc <= 2)) {
6992+
int _v = 0;
6993+
{
6994+
int res = SWIG_AsPtr_std_string(argv[0], (std::string**)(0));
6995+
_v = SWIG_CheckState(res);
6996+
}
6997+
if (!_v) goto check_1;
6998+
PyObject *retobj = _wrap_ImageFactory_createIo__SWIG_0(self, argc, argv);
6999+
if (!SWIG_Python_TypeErrorOccurred(retobj)) return retobj;
7000+
SWIG_fail;
7001+
}
7002+
check_1:
7003+
7004+
if (argc == 1) {
7005+
PyObject *retobj = _wrap_ImageFactory_createIo__SWIG_1(self, argc, argv);
7006+
if (!SWIG_Python_TypeErrorOccurred(retobj)) return retobj;
7007+
SWIG_fail;
7008+
}
7009+
7010+
fail:
7011+
SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'ImageFactory_createIo'.\n"
7012+
" Possible C/C++ prototypes are:\n"
7013+
" Exiv2::ImageFactory::createIo(std::string const &,bool)\n"
7014+
" Exiv2::ImageFactory::Exiv2_ImageFactory_createIo__SWIG_1(Exiv2::byte const *,size_t)\n");
7015+
return 0;
7016+
}
7017+
7018+
68617019
SWIGINTERN PyObject *_wrap_delete_ImageFactory(PyObject *self, PyObject *args) {
68627020
PyObject *resultobj = 0;
68637021
Exiv2::ImageFactory *arg1 = (Exiv2::ImageFactory *) 0 ;

0 commit comments

Comments
 (0)