Commit e52c15ae0411910cbd3acfffa74ace5b162063fd

Authored by Josh Klontz
1 parent 397fb860

new universal template format

openbr/universal_template.cpp
... ... @@ -8,14 +8,22 @@
8 8  
9 9 #include "universal_template.h"
10 10  
11   -br_utemplate br_new_utemplate(const int8_t *imageID, const int8_t *templateID, int32_t algorithmID, uint32_t size, const int8_t *data)
  11 +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)
12 12 {
  13 + const uint32_t urlSize = strlen(url) + 1;
  14 + const uint32_t size = urlSize + dataSize;
13 15 br_utemplate utemplate = (br_utemplate) malloc(sizeof(br_universal_template) + size);
14 16 memcpy(utemplate->imageID, imageID, 16);
15   - memcpy(utemplate->templateID, templateID, 16);
  17 + memcpy(utemplate->templateID, QCryptographicHash::hash(QByteArray(data, dataSize), QCryptographicHash::Md5).data(), 16);
16 18 utemplate->algorithmID = algorithmID;
  19 + utemplate->x = x;
  20 + utemplate->y = y;
  21 + utemplate->width = width;
  22 + utemplate->height = height;
  23 + utemplate->urlSize = urlSize;
17 24 utemplate->size = size;
18   - memcpy(utemplate+1, data, size);
  25 + memcpy(reinterpret_cast<char*>(utemplate+1) + 0, url , urlSize);
  26 + memcpy(reinterpret_cast<char*>(utemplate+1) + urlSize, data, dataSize);
19 27 return utemplate;
20 28 }
21 29  
... ... @@ -26,19 +34,7 @@ void br_free_utemplate(br_const_utemplate utemplate)
26 34  
27 35 void br_append_utemplate(FILE *file, br_const_utemplate utemplate)
28 36 {
29   - br_append_utemplate_contents(file, utemplate->imageID, utemplate->templateID, utemplate->algorithmID, utemplate->size, utemplate->data);
30   -}
31   -
32   -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)
33   -{
34   - static QMutex lock;
35   - QMutexLocker locker(&lock);
36   -
37   - fwrite(imageID, 16, 1, file);
38   - fwrite(templateID, 16, 1, file);
39   - fwrite(&algorithmID, 4, 1, file);
40   - fwrite(&size, 4, 1, file);
41   - fwrite(data, 1, size, file);
  37 + fwrite(utemplate, sizeof(br_universal_template) + utemplate->size, 1, file);
42 38 }
43 39  
44 40 void br_iterate_utemplates(br_const_utemplate begin, br_const_utemplate end, br_utemplate_callback callback, br_callback_context context)
... ...
openbr/universal_template.h
... ... @@ -36,10 +36,18 @@ extern &quot;C&quot; {
36 36 struct br_universal_template
37 37 {
38 38 unsigned char imageID[16]; /*!< MD5 hash of the undecoded origin file. */
39   - unsigned char templateID[16]; /*!< MD5 hash of _data_. */
40   - int32_t algorithmID; /*!< type of _data_. */
41   - uint32_t size; /*!< length of _data_. */
42   - unsigned char data[]; /*!< _size_-byte buffer. */
  39 + unsigned char templateID[16]; /*!< MD5 hash of _data_ after _urlSize_. */
  40 + int32_t algorithmID; /*!< interpretation of _data_ after _urlSize_. */
  41 + uint32_t x; /*!< region of interest horizontal offset (pixels). */
  42 + uint32_t y; /*!< region of interest vertical offset (pixels). */
  43 + uint32_t width; /*!< region of interest horizontal size (pixels). */
  44 + uint32_t height; /*!< region of interest vertical size (pixels). */
  45 + uint32_t urlSize; /*!< length of null-terminated URL at the beginning of _data_,
  46 + including the null-terminator character. */
  47 + uint32_t size; /*!< length of _data_. */
  48 + unsigned char data[]; /*!< _size_-byte buffer.
  49 + The first _urlSize_ bytes represent the URL.
  50 + The remaining (_size_ - _urlSize_) bytes represent the template data. */
43 51 };
44 52  
45 53 typedef struct br_universal_template *br_utemplate;
... ... @@ -49,7 +57,7 @@ typedef const struct br_universal_template *br_const_utemplate;
49 57 * \brief br_universal_template constructor.
50 58 * \see br_free_utemplate
51 59 */
52   -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);
  60 +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);
53 61  
54 62 /*!
55 63 * \brief br_universal_template destructor.
... ... @@ -64,12 +72,6 @@ BR_EXPORT void br_free_utemplate(br_const_utemplate utemplate);
64 72 BR_EXPORT void br_append_utemplate(FILE *file, br_const_utemplate utemplate);
65 73  
66 74 /*!
67   - * \brief Serialize a br_universal_template to a file.
68   - * \see br_append_utemplate
69   - */
70   -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);
71   -
72   -/*!
73 75 * \brief br_universal_template iterator callback.
74 76 * \see br_iterate_utemplates
75 77 */
... ...