diff --git a/openbr/universal_template.cpp b/openbr/universal_template.cpp index f4f2484..59feea4 100644 --- a/openbr/universal_template.cpp +++ b/openbr/universal_template.cpp @@ -8,14 +8,22 @@ #include "universal_template.h" -br_utemplate br_new_utemplate(const int8_t *imageID, const int8_t *templateID, int32_t algorithmID, uint32_t size, const int8_t *data) +br_utemplate br_new_utemplate(const int8_t *imageID, int32_t algorithmID, size_t x, size_t y, size_t width, size_t height, const char *url, const char *data, uint32_t dataSize) { + const uint32_t urlSize = strlen(url) + 1; + const uint32_t size = urlSize + dataSize; br_utemplate utemplate = (br_utemplate) malloc(sizeof(br_universal_template) + size); memcpy(utemplate->imageID, imageID, 16); - memcpy(utemplate->templateID, templateID, 16); + memcpy(utemplate->templateID, QCryptographicHash::hash(QByteArray(data, dataSize), QCryptographicHash::Md5).data(), 16); utemplate->algorithmID = algorithmID; + utemplate->x = x; + utemplate->y = y; + utemplate->width = width; + utemplate->height = height; + utemplate->urlSize = urlSize; utemplate->size = size; - memcpy(utemplate+1, data, size); + memcpy(reinterpret_cast(utemplate+1) + 0, url , urlSize); + memcpy(reinterpret_cast(utemplate+1) + urlSize, data, dataSize); return utemplate; } @@ -26,19 +34,7 @@ void br_free_utemplate(br_const_utemplate utemplate) void br_append_utemplate(FILE *file, br_const_utemplate utemplate) { - br_append_utemplate_contents(file, utemplate->imageID, utemplate->templateID, utemplate->algorithmID, utemplate->size, utemplate->data); -} - -void br_append_utemplate_contents(FILE *file, const unsigned char *imageID, const unsigned char *templateID, int32_t algorithmID, uint32_t size, const unsigned char *data) -{ - static QMutex lock; - QMutexLocker locker(&lock); - - fwrite(imageID, 16, 1, file); - fwrite(templateID, 16, 1, file); - fwrite(&algorithmID, 4, 1, file); - fwrite(&size, 4, 1, file); - fwrite(data, 1, size, file); + fwrite(utemplate, sizeof(br_universal_template) + utemplate->size, 1, file); } void br_iterate_utemplates(br_const_utemplate begin, br_const_utemplate end, br_utemplate_callback callback, br_callback_context context) diff --git a/openbr/universal_template.h b/openbr/universal_template.h index ada0a31..61cf741 100644 --- a/openbr/universal_template.h +++ b/openbr/universal_template.h @@ -36,10 +36,18 @@ extern "C" { struct br_universal_template { unsigned char imageID[16]; /*!< MD5 hash of the undecoded origin file. */ - unsigned char templateID[16]; /*!< MD5 hash of _data_. */ - int32_t algorithmID; /*!< type of _data_. */ - uint32_t size; /*!< length of _data_. */ - unsigned char data[]; /*!< _size_-byte buffer. */ + unsigned char templateID[16]; /*!< MD5 hash of _data_ after _urlSize_. */ + int32_t algorithmID; /*!< interpretation of _data_ after _urlSize_. */ + uint32_t x; /*!< region of interest horizontal offset (pixels). */ + uint32_t y; /*!< region of interest vertical offset (pixels). */ + uint32_t width; /*!< region of interest horizontal size (pixels). */ + uint32_t height; /*!< region of interest vertical size (pixels). */ + uint32_t urlSize; /*!< length of null-terminated URL at the beginning of _data_, + including the null-terminator character. */ + uint32_t size; /*!< length of _data_. */ + unsigned char data[]; /*!< _size_-byte buffer. + The first _urlSize_ bytes represent the URL. + The remaining (_size_ - _urlSize_) bytes represent the template data. */ }; typedef struct br_universal_template *br_utemplate; @@ -49,7 +57,7 @@ typedef const struct br_universal_template *br_const_utemplate; * \brief br_universal_template constructor. * \see br_free_utemplate */ -BR_EXPORT br_utemplate br_new_utemplate(const int8_t *imageID, const int8_t *templateID, int32_t algorithmID, uint32_t size, const int8_t *data); +BR_EXPORT br_utemplate br_new_utemplate(const int8_t *imageID, int32_t algorithmID, size_t x, size_t y, size_t width, size_t height, const char *url, const char *data, uint32_t dataSize); /*! * \brief br_universal_template destructor. @@ -64,12 +72,6 @@ BR_EXPORT void br_free_utemplate(br_const_utemplate utemplate); BR_EXPORT void br_append_utemplate(FILE *file, br_const_utemplate utemplate); /*! - * \brief Serialize a br_universal_template to a file. - * \see br_append_utemplate - */ -BR_EXPORT void br_append_utemplate_contents(FILE *file, const unsigned char *imageID, const unsigned char *templateID, int32_t algorithmID, uint32_t size, const unsigned char *data); - -/*! * \brief br_universal_template iterator callback. * \see br_iterate_utemplates */