Skip to content
Browse files

changed ccv_unserialize/ccv_serialize to a more sensible name

ccv_read/ccv_write. added a class of macros so that I don't have
to write 4 lines of code in every function just to generate proper
signature for each matrix.
  • Loading branch information...
1 parent b3591e0 commit dca50ebbe3b60c540a2304973dff722b56787ea2 @liuliu committed Mar 14, 2012
View
2 bin/bbfcreate.c
@@ -21,7 +21,7 @@ int main(int argc, char** argv)
{
char buf[1024];
rt = fscanf(pf, "%s", buf);
- ccv_unserialize(buf, &posimg[i], CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
+ ccv_read(buf, &posimg[i], CCV_IO_GRAY | CCV_IO_ANY_FILE);
}
fclose(pf);
int negnum = atoi(argv[4]);
View
4 bin/bbfdetect.c
@@ -16,7 +16,7 @@ int main(int argc, char** argv)
ccv_enable_default_cache();
ccv_dense_matrix_t* image = 0;
ccv_bbf_classifier_cascade_t* cascade = ccv_load_bbf_classifier_cascade(argv[2]);
- ccv_unserialize(argv[1], &image, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
+ ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
if (image != 0)
{
unsigned int elapsed_time = get_current_time();
@@ -45,7 +45,7 @@ int main(int argc, char** argv)
len--;
file[len] = '\0';
image = 0;
- ccv_unserialize(file, &image, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
+ ccv_read(file, &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
ccv_bbf_param_t params = { .interval = 5, .min_neighbors = 2, .flags = 0, .size = ccv_size(24, 24) };
ccv_array_t* seq = ccv_bbf_detect_objects(image, &cascade, 1, params);
for (i = 0; i < seq->rnum; i++)
View
6 bin/convert.c
@@ -5,7 +5,7 @@ int main(int argc, char** argv)
ccv_dense_matrix_t* image = 0;
assert(argc == 3);
ccv_enable_default_cache();
- ccv_unserialize(argv[1], &image, CCV_SERIAL_ANY_FILE);
+ ccv_read(argv[1], &image, CCV_IO_ANY_FILE);
char* suffix = strrchr(argv[2], '.');
ccv_dense_matrix_t* representable = 0;
if (!(image->type & CCV_8U))
@@ -17,9 +17,9 @@ int main(int argc, char** argv)
}
if (strncmp(suffix, ".png", 4) == 0)
{
- ccv_serialize(image, argv[2], 0, CCV_SERIAL_PNG_FILE, 0);
+ ccv_write(image, argv[2], 0, CCV_IO_PNG_FILE, 0);
} else if (strncmp(suffix, ".jpg", 4) == 0) {
- ccv_serialize(image, argv[2], 0, CCV_SERIAL_JPEG_FILE, 0);
+ ccv_write(image, argv[2], 0, CCV_IO_JPEG_FILE, 0);
}
ccv_matrix_free(image);
if (representable != 0)
View
2 bin/dpmdetect.c
@@ -15,7 +15,7 @@ int main(int argc, char** argv)
int i;
ccv_enable_default_cache();
ccv_dense_matrix_t* image = 0;
- ccv_unserialize(argv[1], &image, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
+ ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
ccv_dpm_root_classifier_t* root_classifier = ccv_load_dpm_root_classifier(argv[2]);
if (image != 0)
{
View
4 bin/siftmatch.c
@@ -14,8 +14,8 @@ int main(int argc, char** argv)
ccv_enable_default_cache();
ccv_dense_matrix_t* object = 0;
ccv_dense_matrix_t* image = 0;
- ccv_unserialize(argv[1], &object, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
- ccv_unserialize(argv[2], &image, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
+ ccv_read(argv[1], &object, CCV_IO_GRAY | CCV_IO_ANY_FILE);
+ ccv_read(argv[2], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
unsigned int elapsed_time = get_current_time();
ccv_sift_param_t param;
param.noctaves = 3;
View
2 bin/swtcreate.c
@@ -65,7 +65,7 @@ int main(int argc, char** argv)
char file[1000];
fscanf(r, "%s", file);
aof[i] = 0;
- ccv_unserialize(file, aof + i, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
+ ccv_read(file, aof + i, CCV_IO_GRAY | CCV_IO_ANY_FILE);
int locations;
fscanf(r, "%d", &locations);
int j;
View
6 bin/swtdetect.c
@@ -11,10 +11,10 @@ unsigned int get_current_time()
int main(int argc, char** argv)
{
- ccv_swt_param_t params = { .size = 5, .low_thresh = 93, .high_thresh = 279, .max_height = 300, .min_height = 10, .aspect_ratio = 10, .variance_ratio = 0.5, .thickness_ratio = 2, .height_ratio = 2, .intensity_thresh = 29, .distance_ratio = 3, .intersect_ratio = 2, .letter_thresh = 3, .elongate_ratio = 1.3, .breakdown = 1, .breakdown_ratio = 12.8 };
+ ccv_swt_param_t params = { .size = 3, .low_thresh = 175, .high_thresh = 320, .max_height = 300, .min_height = 10, .aspect_ratio = 10, .variance_ratio = 0.5, .thickness_ratio = 1.5, .height_ratio = 2, .intensity_thresh = 30, .distance_ratio = 3, .intersect_ratio = 2, .letter_thresh = 3, .elongate_ratio = 1.3, .breakdown = 1, .breakdown_ratio = 12.8 };
ccv_enable_default_cache();
ccv_dense_matrix_t* image = 0;
- ccv_unserialize(argv[1], &image, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
+ ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
if (image != 0)
{
unsigned int elapsed_time = get_current_time();
@@ -43,7 +43,7 @@ int main(int argc, char** argv)
len--;
file[len] = '\0';
image = 0;
- ccv_unserialize(file, &image, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
+ ccv_read(file, &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
ccv_array_t* words = ccv_swt_detect_words(image, params);
int i;
printf("%s\n%d\n", file, words->rnum);
View
2 js/index.html
@@ -7,7 +7,7 @@
</head>
<body>
<div id="container">
- <div id="header"><div class="title">A Not-so-slow Javascript Face Detector</div><div class="subtitle">For Source Code, Visit <a href="https://github.com/liuliu/ccv/tree/unstable/js">Github</a>; For More Discussions, Visit <a href="http://liuliu.me">liuliu.me</a>; Or Paste Your Photo at <a href="http://imgur.com">imgur.com</a></div></div>
+ <div id="header"><div class="title">A Not-so-slow JavaScript Face Detector</div><div class="subtitle">For Source Code, Visit <a href="https://github.com/liuliu/ccv/tree/unstable/js">Github</a>; For More Discussions, Visit <a href="http://liuliu.me">liuliu.me</a>; Or Paste Your Photo at <a href="http://imgur.com">imgur.com</a></div></div>
<div id="content">
<div id="urlbox"><div id="detect"><input id="url-detect" type="button" value="Detect"></div><div class="paragraph">URL: </div><div id="url"><div id="url-hint">Paste an image URL here</div><input class="no-border" id="url-image" type="text"></div></div>
<div id="stats">Stats: Web Worker - <a id="webworker-switch" href="#">Off</a>, Load Time: <span id="load-time">None</span>, Detection Time: <span id="detection-time">None</span>, <span id="num-faces">?</span> Faces Found at <span id="image-dim">?x?</span></div>
View
0 lib/3rdparty/sha1.c → lib/3rdparty/sha1/sha1.c
File renamed without changes.
View
0 lib/3rdparty/sha1.h → lib/3rdparty/sha1/sha1.h
File renamed without changes.
View
132 lib/ccv.h
@@ -179,9 +179,81 @@ ccv_dense_matrix_t* ccv_dense_matrix_renew(ccv_dense_matrix_t* x, int rows, int
ccv_dense_matrix_t* ccv_dense_matrix_new(int rows, int cols, int type, void* data, uint64_t sig);
ccv_dense_matrix_t ccv_dense_matrix(int rows, int cols, int type, void* data, uint64_t sig);
ccv_sparse_matrix_t* ccv_sparse_matrix_new(int rows, int cols, int type, int major, uint64_t sig);
-uint64_t ccv_matrix_generate_signature(const char* msg, int len, uint64_t sig_start, ...);
void ccv_matrix_free_immediately(ccv_matrix_t* mat);
void ccv_matrix_free(ccv_matrix_t* mat);
+/* the following 9 lines to generate unique name was taken from Catch: https://github.com/philsquared/Catch
+ * here is the licence:
+ * Boost Software License - Version 1.0 - August 17th, 2003
+ *
+ * Permission is hereby granted, free of charge, to any person or organization
+ * obtaining a copy of the software and accompanying documentation covered by
+ * this license (the "Software") to use, reproduce, display, distribute,
+ * execute, and transmit the Software, and to prepare derivative works of the
+ * Software, and to permit third-parties to whom the Software is furnished to
+ * do so, all subject to the following:
+ *
+ * The copyright notices in the Software and this entire statement, including
+ * the above license grant, this restriction and the following disclaimer,
+ * must be included in all copies of the Software, in whole or in part, and
+ * all derivative works of the Software, unless such copies or derivative
+ * works are solely in the form of machine-executable object code generated by
+ * a source language processor.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+ * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+ * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE. */
+#ifndef INTERNAL_CATCH_UNIQUE_NAME_LINE2
+#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
+#endif
+#ifndef INTERNAL_CATCH_UNIQUE_NAME_LINE
+#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
+#endif
+#ifndef INTERNAL_CATCH_UNIQUE_NAME
+#define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
+#endif
+
+#define ccv_sign_with_literal(string) \
+ char INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_)[] = (string); \
+ size_t INTERNAL_CATCH_UNIQUE_NAME(_ccv_string_size_) = sizeof(INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_));
+
+#define ccv_sign_with_format(size, string, ...) \
+ char INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_)[(size)]; \
+ memset(INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_), 0, (size)); \
+ snprintf(INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_), (size), (string), ##__VA_ARGS__); \
+ size_t INTERNAL_CATCH_UNIQUE_NAME(_ccv_string_size_) = (size);
+
+#define ccv_declare_matrix_signature(var, cond, submacro, ...) \
+ submacro; \
+ uint64_t var = (cond) ? ccv_matrix_generate_signature(INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_), INTERNAL_CATCH_UNIQUE_NAME(_ccv_string_size_), __VA_ARGS__) : 0;
+
+#define ccv_sign_if(cond, ...) \
+ if (cond) { \
+ INTERNAL_CATCH_UNIQUE_NAME(_ccv_temp_sig_) = ccv_matrix_generate_signature(INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_), INTERNAL_CATCH_UNIQUE_NAME(_ccv_string_size_), __VA_ARGS__); \
+ }
+
+#define INTERNAL_EXPAND_MACRO_ARGUMENT_TO_LINE_N(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32,_33,_34,_35,_36,_37,_38,_39,_40,_41,_42,_43,_44,_45,_46,_47,_48,_49,_50,_51,_52,_53,_54,_55,_56,_57,_58,_59,_60,_61,_62,_63,...) \
+ _1;_2;_3;_4;_5;_6;_7;_8;_9;_10;_11;_12;_13;_14;_15;_16;_17;_18;_19;_20;_21;_22;_23;_24;_25;_26;_27;_28;_29;_30;_31;_32;_33;_34;_35;_36;_37;_38;_39;_40;_41;_42;_43;_44;_45;_46;_47;_48;_49;_50;_51;_52;_53;_54;_55;_56;_57;_58;_59;_60;_61;_62;_63
+#define INTERNAL_EXPAND_MACRO_ARGUMENT_TO_LINE(...) INTERNAL_EXPAND_MACRO_ARGUMENT_TO_LINE_N(__VA_ARGS__)
+
+#define INTERNAL_SEQ_PADDING_LINE() ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+
+#define ccv_declare_matrix_signature_case(var, submacro, ...) \
+ submacro; \
+ uint64_t INTERNAL_CATCH_UNIQUE_NAME(_ccv_temp_sig_) = 0; \
+ INTERNAL_EXPAND_MACRO_ARGUMENT_TO_LINE(__VA_ARGS__, INTERNAL_SEQ_PADDING_LINE()); \
+ uint64_t var = INTERNAL_CATCH_UNIQUE_NAME(_ccv_temp_sig_);
+
+/* with the help of the above macros, there is rare that you need to use ccv_matrix_generate_signature
+ * directly. Here is how you can use above macro to generate signature from function input parameters:
+ * ccv_declare_matrix_signature(sig,
+ * ccv_sign_with_format(64, "function_name(%f,%f,%f)", a_parameter, b_parameter, c_parameter),
+ * da->sig, 0);
+ * However, there is one gotcha, you cannot separate line as above. */
+uint64_t ccv_matrix_generate_signature(const char* msg, int len, uint64_t sig_start, ...);
#define CCV_DEFAULT_CACHE_SIZE (1024 * 1024 * 64)
@@ -190,17 +262,17 @@ void ccv_disable_cache(void);
void ccv_enable_default_cache(void);
void ccv_enable_cache(size_t size);
-#define ccv_get_dense_matrix_cell(x, row, col) \
- ((((x)->type) & CCV_32S) ? (void*)((x)->data.i + (row) * (x)->cols + (col)) : \
- ((((x)->type) & CCV_32F) ? (void*)((x)->data.fl+ (row) * (x)->cols + (col)) : \
- ((((x)->type) & CCV_64F) ? (void*)((x)->data.db + (row) * (x)->cols + (col)) : \
- (void*)((x)->data.ptr + (row) * (x)->step + (col)))))
+#define ccv_get_dense_matrix_cell(x, row, col, ch) \
+ ((((x)->type) & CCV_32S) ? (void*)((x)->data.i + ((row) * (x)->cols + (col)) * CCV_GET_CHANNEL((x)->type) + (ch)) : \
+ ((((x)->type) & CCV_32F) ? (void*)((x)->data.fl+ ((row) * (x)->cols + (col)) * CCV_GET_CHANNEL((x)->type) + (ch)) : \
+ ((((x)->type) & CCV_64F) ? (void*)((x)->data.db + ((row) * (x)->cols + (col)) * CCV_GET_CHANNEL((x)->type) + (ch)) : \
+ (void*)((x)->data.ptr + (row) * (x)->step + (col) * CCV_GET_CHANNEL((x)->type) + (ch)))))
-#define ccv_get_dense_matrix_cell_value(x, row, col) \
- ((((x)->type) & CCV_32S) ? (x)->data.i[(row) * (x)->cols + (col)] : \
- ((((x)->type) & CCV_32F) ? (x)->data.fl[(row) * (x)->cols + (col)] : \
- ((((x)->type) & CCV_64F) ? (x)->data.db[(row) * (x)->cols + (col)] : \
- (x)->data.ptr[(row) * (x)->step + (col)])))
+#define ccv_get_dense_matrix_cell_value(x, row, col, ch) \
+ ((((x)->type) & CCV_32S) ? (x)->data.i[((row) * (x)->cols + (col)) * CCV_GET_CHANNEL((x)->type) + (ch)] : \
+ ((((x)->type) & CCV_32F) ? (x)->data.fl[((row) * (x)->cols + (col)) * CCV_GET_CHANNEL((x)->type) + (ch)] : \
+ ((((x)->type) & CCV_64F) ? (x)->data.db[((row) * (x)->cols + (col)) * CCV_GET_CHANNEL((x)->type) + (ch)] : \
+ (x)->data.ptr[(row) * (x)->step + (col) * CCV_GET_CHANNEL((x)->type) + (ch)])))
#define ccv_get_value(type, ptr, i) \
(((type) & CCV_32S) ? ((int*)(ptr))[(i)] : \
@@ -359,28 +431,29 @@ void ccv_enable_cache(size_t size);
/* basic io */
enum {
- CCV_SERIAL_GRAY = 0x100,
- CCV_SERIAL_COLOR = 0x300,
- CCV_SERIAL_ANY_STREAM = 0x010,
- CCV_SERIAL_PLAIN_STREAM = 0x011,
- CCV_SERIAL_DEFLATE_STREAM = 0x012,
- CCV_SERIAL_JPEG_STREAM = 0x013,
- CCV_SERIAL_PNG_STREAM = 0x014,
- CCV_SERIAL_ANY_FILE = 0x020,
- CCV_SERIAL_BMP_FILE = 0x021,
- CCV_SERIAL_JPEG_FILE = 0x022,
- CCV_SERIAL_PNG_FILE = 0x023,
- CCV_SERIAL_BINARY_FILE = 0x024,
+ CCV_IO_GRAY = 0x100,
+ CCV_IO_COLOR = 0x300,
+ CCV_IO_ANY_STREAM = 0x010,
+ CCV_IO_PLAIN_STREAM = 0x011,
+ CCV_IO_DEFLATE_STREAM = 0x012,
+ CCV_IO_JPEG_STREAM = 0x013,
+ CCV_IO_PNG_STREAM = 0x014,
+ CCV_IO_ANY_FILE = 0x020,
+ CCV_IO_BMP_FILE = 0x021,
+ CCV_IO_JPEG_FILE = 0x022,
+ CCV_IO_PNG_FILE = 0x023,
+ CCV_IO_BINARY_FILE = 0x024,
};
enum {
- CCV_SERIAL_CONTINUE = 0x01,
- CCV_SERIAL_FINAL,
- CCV_SERIAL_ERROR,
+ CCV_IO_FINAL = 0x00,
+ CCV_IO_CONTINUE,
+ CCV_IO_ERROR,
+ CCV_IO_ATTEMPTED,
};
-void ccv_unserialize(const char* in, ccv_dense_matrix_t** x, int type);
-int ccv_serialize(ccv_dense_matrix_t* mat, char* out, int* len, int type, void* conf);
+int ccv_read(const char* in, ccv_dense_matrix_t** x, int type);
+int ccv_write(ccv_dense_matrix_t* mat, char* out, int* len, int type, void* conf);
/* basic algebra algorithm */
double ccv_trace(ccv_matrix_t* mat);
@@ -529,6 +602,8 @@ void ccv_gradient(ccv_dense_matrix_t* a, ccv_dense_matrix_t** theta, int ttype,
void ccv_hog(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int size);
void ccv_canny(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int size, double low_thresh, double high_thresh);
+#define CCV_FILTER_NONE (INFINITY)
+
enum {
CCV_INTER_AREA = 0x01,
CCV_INTER_LINEAR = 0X02,
@@ -599,6 +674,7 @@ void ccv_sift(ccv_dense_matrix_t* a, ccv_array_t** keypoints, ccv_dense_matrix_t
/* swt related method: stroke width transform is relatively new, typically used in text detection */
typedef struct {
+ int up2x;
int direction;
/* canny parameters */
int size;
View
16 lib/ccv_algebra.c
@@ -17,10 +17,7 @@ double ccv_normalize(ccv_matrix_t* a, ccv_matrix_t** b, int btype, int l_type)
{
ccv_dense_matrix_t* da = ccv_get_dense_matrix(a);
assert(CCV_GET_CHANNEL(da->type) == CCV_C1);
- char identifier[20];
- memset(identifier, 0, 20);
- snprintf(identifier, 20, "ccv_normalize(%d)", l_type);
- uint64_t sig = (da->sig == 0) ? 0 : ccv_matrix_generate_signature(identifier, 20, da->sig, 0);
+ ccv_declare_matrix_signature(sig, da->sig != 0, ccv_sign_with_format(20, "ccv_normalize(%d)", l_type), da->sig, 0);
btype = (btype == 0) ? CCV_GET_DATA_TYPE(da->type) | CCV_C1 : CCV_GET_DATA_TYPE(btype) | CCV_C1;
ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, da->rows, da->cols, CCV_ALL_DATA_TYPE | CCV_C1, btype, sig);
ccv_cache_return(db, 0);
@@ -75,6 +72,10 @@ double ccv_normalize(ccv_matrix_t* a, ccv_matrix_t** b, int btype, int l_type)
return sum;
}
+void ccv_sat(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type)
+{
+}
+
double ccv_sum(ccv_matrix_t* mat)
{
ccv_dense_matrix_t* dmt = ccv_get_dense_matrix(mat);
@@ -104,7 +105,7 @@ void ccv_substract(ccv_matrix_t* a, ccv_matrix_t* b, ccv_matrix_t** c, int type)
ccv_dense_matrix_t* da = ccv_get_dense_matrix(a);
ccv_dense_matrix_t* db = ccv_get_dense_matrix(b);
assert(da->rows == db->rows && da->cols == db->cols && CCV_GET_DATA_TYPE(da->type) == CCV_GET_DATA_TYPE(db->type) && CCV_GET_CHANNEL(da->type) == CCV_GET_CHANNEL(db->type));
- uint64_t sig = ccv_matrix_generate_signature("ccv_substract", 13, da->sig, db->sig, 0);
+ ccv_declare_matrix_signature(sig, da->sig != 0 && db->sig != 0, ccv_sign_with_literal("ccv_substract"), da->sig, db->sig, 0);
int no_8u_type = (da->type & CCV_8U) ? CCV_32S : da->type;
type = (type == 0) ? CCV_GET_DATA_TYPE(no_8u_type) | CCV_GET_CHANNEL(da->type) : CCV_GET_DATA_TYPE(type) | CCV_GET_CHANNEL(da->type);
ccv_dense_matrix_t* dc = *c = ccv_dense_matrix_renew(*c, da->rows, da->cols, CCV_ALL_DATA_TYPE | CCV_GET_CHANNEL(da->type), type, sig);
@@ -139,10 +140,7 @@ void ccv_gemm(ccv_matrix_t* a, ccv_matrix_t* b, double alpha, ccv_matrix_t* c, d
if (dc != 0)
assert(CCV_GET_DATA_TYPE(dc->type) == CCV_GET_DATA_TYPE(da->type) && CCV_GET_CHANNEL(dc->type) == 1 && ((transpose & CCV_A_TRANSPOSE) ? da->cols : da->rows) == dc->rows && ((transpose & CCV_B_TRANSPOSE) ? db->rows : db->cols) == dc->cols);
- char identifier[20];
- memset(identifier, 0, 20);
- snprintf(identifier, 20, "ccv_gemm(%d)", transpose);
- uint64_t sig = (dc == 0) ? ((da->sig == 0 || db->sig == 0) ? 0 : ccv_matrix_generate_signature(identifier, 20, da->sig, db->sig, 0)) : ((da->sig == 0 || db->sig == 0 || dc->sig == 0) ? 0 : ccv_matrix_generate_signature(identifier, 20, da->sig, db->sig, dc->sig, 0));
+ ccv_declare_matrix_signature_case(sig, ccv_sign_with_format(20, "ccv_gemm(%d)", transpose), ccv_sign_if(dc == 0 && da->sig != 0 && db->sig != 0, da->sig, db->sig, 0), ccv_sign_if(dc != 0 && da->sig != 0 && db->sig != 0 && dc->sig != 0, da->sig, db->sig, dc->sig, 0));
type = CCV_GET_DATA_TYPE(da->type) | CCV_GET_CHANNEL(da->type);
ccv_dense_matrix_t* dd = *d = ccv_dense_matrix_renew(*d, (transpose & CCV_A_TRANSPOSE) ? da->cols : da->rows, (transpose & CCV_B_TRANSPOSE) ? db->rows : db->cols, type, type, sig);
ccv_cache_return(dd, );
View
39 lib/ccv_basic.c
@@ -5,10 +5,7 @@
void ccv_sobel(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int dx, int dy)
{
assert(a->type & CCV_C1);
- char identifier[64];
- memset(identifier, 0, 64);
- snprintf(identifier, 64, "ccv_sobel(%d,%d)", dx, dy);
- uint64_t sig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature(identifier, 64, a->sig, 0);
+ ccv_declare_matrix_signature(sig, a->sig != 0, ccv_sign_with_format(64, "ccv_sobel(%d,%d)", dx, dy), a->sig, 0);
type = (type == 0) ? CCV_32S | CCV_C1 : CCV_GET_DATA_TYPE(type) | CCV_C1;
ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, a->rows, a->cols, CCV_C1 | CCV_ALL_DATA_TYPE, type, sig);
ccv_cache_return(db, );
@@ -248,8 +245,8 @@ static void _ccv_atan2(float* x, float* y, float* angle, float* mag, int len)
void ccv_gradient(ccv_dense_matrix_t* a, ccv_dense_matrix_t** theta, int ttype, ccv_dense_matrix_t** m, int mtype, int dx, int dy)
{
assert(a->type & CCV_C1);
- uint64_t tsig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature("ccv_gradient_theta", 18, a->sig, 0);
- uint64_t msig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature("ccv_gradient_m", 14, a->sig, 0);
+ ccv_declare_matrix_signature(tsig, a->sig != 0, ccv_sign_with_literal("ccv_gradient_theta"), a->sig, 0);
+ ccv_declare_matrix_signature(msig, a->sig != 0, ccv_sign_with_literal("ccv_gradient_m"), a->sig, 0);
ccv_dense_matrix_t* dtheta = *theta = ccv_dense_matrix_renew(*theta, a->rows, a->cols, CCV_32F | CCV_C1, CCV_32F | CCV_C1, tsig);
ccv_dense_matrix_t* dm = *m = ccv_dense_matrix_renew(*m, a->rows, a->cols, CCV_32F | CCV_C1, CCV_32F | CCV_C1, msig);
if ((dtheta->type & CCV_GARBAGE) && (dm->type & CCV_GARBAGE))
@@ -273,7 +270,7 @@ void ccv_hog(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int size)
{
assert(a->type & CCV_C1);
int border_size = size / 2;
- uint64_t sig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature("ccv_hog", 7, a->sig, 0);
+ ccv_declare_matrix_signature(sig, a->sig != 0, ccv_sign_with_literal("ccv_hog"), a->sig, 0);
type = (type == 0) ? CCV_32S | CCV_C1 : CCV_GET_DATA_TYPE(type) | CCV_C1;
ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, a->rows - border_size * 2, (a->cols - border_size * 2) * 8, CCV_C1 | CCV_ALL_DATA_TYPE, type, sig);
ccv_cache_return(db, );
@@ -324,10 +321,7 @@ void ccv_hog(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int size)
void ccv_canny(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int size, double low_thresh, double high_thresh)
{
assert(a->type & CCV_C1);
- char identifier[64];
- memset(identifier, 0, 64);
- snprintf(identifier, 64, "ccv_canny(%d,%lf,%lf)", size, low_thresh, high_thresh);
- uint64_t sig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature(identifier, 64, a->sig, 0);
+ ccv_declare_matrix_signature(sig, a->sig != 0, ccv_sign_with_format(64, "ccv_canny(%d,%lf,%lf)", size, low_thresh, high_thresh), a->sig, 0);
type = (type == 0) ? CCV_8U | CCV_C1 : CCV_GET_DATA_TYPE(type) | CCV_C1;
ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, a->rows, a->cols, CCV_C1 | CCV_ALL_DATA_TYPE, type, sig);
ccv_cache_return(db, );
@@ -661,10 +655,7 @@ static void _ccv_resample_area(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b)
void ccv_resample(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int btype, int rows, int cols, int type)
{
- char identifier[64];
- memset(identifier, 0, 64);
- snprintf(identifier, 64, "ccv_resample(%d,%d,%d)", rows, cols, type);
- uint64_t sig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature(identifier, 64, a->sig, 0);
+ ccv_declare_matrix_signature(sig, a->sig != 0, ccv_sign_with_format(64, "ccv_resample(%d,%d,%d)", rows, cols, type), a->sig, 0);
btype = (btype == 0) ? CCV_GET_DATA_TYPE(a->type) | CCV_GET_CHANNEL(a->type) : CCV_GET_DATA_TYPE(btype) | CCV_GET_CHANNEL(a->type);
ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, rows, cols, CCV_ALL_DATA_TYPE | CCV_GET_CHANNEL(a->type), btype, sig);
ccv_cache_return(db, );
@@ -702,10 +693,7 @@ void ccv_resample(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int btype, int
void ccv_sample_down(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int src_x, int src_y)
{
assert(src_x >= 0 && src_y >= 0);
- char identifier[64];
- memset(identifier, 0, 64);
- snprintf(identifier, 64, "ccv_sample_down(%d,%d)", src_x, src_y);
- uint64_t sig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature(identifier, 64, a->sig, 0);
+ ccv_declare_matrix_signature(sig, a->sig != 0, ccv_sign_with_format(64, "ccv_sample_down(%d,%d)", src_x, src_y), a->sig, 0);
type = (type == 0) ? CCV_GET_DATA_TYPE(a->type) | CCV_GET_CHANNEL(a->type) : CCV_GET_DATA_TYPE(type) | CCV_GET_CHANNEL(a->type);
ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, a->rows / 2, a->cols / 2, CCV_ALL_DATA_TYPE | CCV_GET_CHANNEL(a->type), type, sig);
ccv_cache_return(db, );
@@ -770,10 +758,7 @@ void ccv_sample_down(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, in
void ccv_sample_up(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, int src_x, int src_y)
{
assert(src_x >= 0 && src_y >= 0);
- char identifier[64];
- memset(identifier, 0, 64);
- snprintf(identifier, 64, "ccv_sample_up(%d,%d)", src_x, src_y);
- uint64_t sig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature(identifier, 64, a->sig, 0);
+ ccv_declare_matrix_signature(sig, a->sig != 0, ccv_sign_with_format(64, "ccv_sample_up(%d,%d)", src_x, src_y), a->sig, 0);
type = (type == 0) ? CCV_GET_DATA_TYPE(a->type) | CCV_GET_CHANNEL(a->type) : CCV_GET_DATA_TYPE(type) | CCV_GET_CHANNEL(a->type);
ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, a->rows * 2, a->cols * 2, CCV_ALL_DATA_TYPE | CCV_GET_CHANNEL(a->type), type, sig);
ccv_cache_return(db, );
@@ -892,6 +877,7 @@ void _ccv_flip_x_self(ccv_dense_matrix_t* a)
void ccv_flip(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int btype, int type)
{
+ /* this is the special case where ccv_declare_matrix_signature_* macros cannot handle properly */
uint64_t sig = a->sig;
if (type & CCV_FLIP_Y)
sig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature("ccv_flip_y", 10, sig, 0);
@@ -901,7 +887,7 @@ void ccv_flip(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int btype, int type
if (b == 0)
{
db = a;
- if (!(a->sig == 0))
+ if (a->sig != 0)
{
btype = CCV_GET_DATA_TYPE(a->type) | CCV_GET_CHANNEL(a->type);
sig = ccv_matrix_generate_signature((const char*)&btype, sizeof(int), sig, 0);
@@ -921,10 +907,7 @@ void ccv_flip(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int btype, int type
void ccv_blur(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, double sigma)
{
- char identifier[64];
- memset(identifier, 0, 64);
- snprintf(identifier, 64, "ccv_blur(%lf)", sigma);
- uint64_t sig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature(identifier, 64, a->sig, 0);
+ ccv_declare_matrix_signature(sig, a->sig != 0, ccv_sign_with_format(64, "ccv_blur(%lf)", sigma), a->sig, 0);
type = (type == 0) ? CCV_GET_DATA_TYPE(a->type) | CCV_GET_CHANNEL(a->type) : CCV_GET_DATA_TYPE(type) | CCV_GET_CHANNEL(a->type);
ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, a->rows, a->cols, CCV_ALL_DATA_TYPE | CCV_GET_CHANNEL(a->type), type, sig);
ccv_cache_return(db, );
View
2 lib/ccv_bbf.c
@@ -143,7 +143,7 @@ static int _ccv_prepare_background_data(ccv_bbf_classifier_cascade_t* cascade, c
{
negperbg = (t < 2) ? (negnum - negtotal) / (bgnum - i) + 1 : negnum - negtotal;
ccv_dense_matrix_t* image = 0;
- ccv_unserialize(bgfiles[i], &image, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
+ ccv_read(bgfiles[i], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
assert((image->type & CCV_C1) && (image->type & CCV_8U));
if (image == 0)
{
View
53 lib/ccv_io.c
@@ -14,87 +14,88 @@
#include "io/_ccv_io_bmp.c"
#include "io/_ccv_io_binary.c"
-void ccv_unserialize(const char* in, ccv_dense_matrix_t** x, int type)
+int ccv_read(const char* in, ccv_dense_matrix_t** x, int type)
{
FILE* fd = 0;
int ctype = (type & 0xF00) ? CCV_8U | ((type & 0xF00) >> 8) : 0;
- if (type & CCV_SERIAL_ANY_FILE)
+ if (type & CCV_IO_ANY_FILE)
{
fd = fopen(in, "rb");
assert(fd != 0);
}
- if ((type & 0XFF) == CCV_SERIAL_ANY_FILE)
+ if ((type & 0XFF) == CCV_IO_ANY_FILE)
{
unsigned char sig[8];
(void) fread(sig, 1, 8, fd);
if (memcmp(sig, "\x89\x50\x4e\x47\xd\xa\x1a\xa", 8) == 0)
- type = CCV_SERIAL_PNG_FILE;
+ type = CCV_IO_PNG_FILE;
else if (memcmp(sig, "\xff\xd8\xff", 3) == 0)
- type = CCV_SERIAL_JPEG_FILE;
+ type = CCV_IO_JPEG_FILE;
else if (memcmp(sig, "BM", 2) == 0)
- type = CCV_SERIAL_BMP_FILE;
+ type = CCV_IO_BMP_FILE;
else if (memcmp(sig, "CCVBINDM", 8) == 0)
- type = CCV_SERIAL_BINARY_FILE;
+ type = CCV_IO_BINARY_FILE;
fseek(fd, 0, SEEK_SET);
}
switch (type & 0XFF)
{
#ifdef HAVE_LIBJPEG
- case CCV_SERIAL_JPEG_FILE:
- _ccv_unserialize_jpeg_fd(fd, x, ctype);
+ case CCV_IO_JPEG_FILE:
+ _ccv_read_jpeg_fd(fd, x, ctype);
break;
#endif
#ifdef HAVE_LIBPNG
- case CCV_SERIAL_PNG_FILE:
- _ccv_unserialize_png_fd(fd, x, ctype);
+ case CCV_IO_PNG_FILE:
+ _ccv_read_png_fd(fd, x, ctype);
break;
#endif
- case CCV_SERIAL_BMP_FILE:
- _ccv_unserialize_bmp_fd(fd, x, ctype);
+ case CCV_IO_BMP_FILE:
+ _ccv_read_bmp_fd(fd, x, ctype);
break;
- case CCV_SERIAL_BINARY_FILE:
- _ccv_unserialize_binary_fd(fd, x, ctype);
+ case CCV_IO_BINARY_FILE:
+ _ccv_read_binary_fd(fd, x, ctype);
}
if (*x != 0)
{
(*x)->sig = ccv_matrix_generate_signature((char*) (*x)->data.ptr, (*x)->rows * (*x)->step, 0);
(*x)->type &= ~CCV_REUSABLE;
}
- if (type & CCV_SERIAL_ANY_FILE)
+ if (type & CCV_IO_ANY_FILE)
fclose(fd);
+ return CCV_IO_FINAL;
}
-int ccv_serialize(ccv_dense_matrix_t* mat, char* out, int* len, int type, void* conf)
+int ccv_write(ccv_dense_matrix_t* mat, char* out, int* len, int type, void* conf)
{
FILE* fd = 0;
- if (type & CCV_SERIAL_ANY_FILE)
+ if (type & CCV_IO_ANY_FILE)
{
fd = fopen(out, "wb");
assert(fd != 0);
}
switch (type)
{
#ifdef HAVE_LIBJPEG
- case CCV_SERIAL_JPEG_FILE:
- _ccv_serialize_jpeg_fd(mat, fd, conf);
+ case CCV_IO_JPEG_FILE:
+ _ccv_write_jpeg_fd(mat, fd, conf);
if (len != 0)
*len = 0;
break;
#endif
#ifdef HAVE_LIBPNG
- case CCV_SERIAL_PNG_FILE:
- _ccv_serialize_png_fd(mat, fd, conf);
+ case CCV_IO_PNG_FILE:
+ _ccv_write_png_fd(mat, fd, conf);
if (len != 0)
*len = 0;
break;
#endif
- case CCV_SERIAL_BINARY_FILE:
- _ccv_serialize_binary_fd(mat, fd, conf);
+ case CCV_IO_BINARY_FILE:
+ _ccv_write_binary_fd(mat, fd, conf);
if (len != 0)
*len = 0;
break;
}
- if (type & CCV_SERIAL_ANY_FILE)
+ if (type & CCV_IO_ANY_FILE)
fclose(fd);
- return CCV_SERIAL_FINAL;
+ return CCV_IO_FINAL;
}
View
2 lib/ccv_memory.c
@@ -1,5 +1,5 @@
#include "ccv.h"
-#include "3rdparty/sha1.h"
+#include "3rdparty/sha1/sha1.h"
static ccv_cache_t ccv_cache;
View
55 lib/ccv_numeric.c
@@ -1,6 +1,6 @@
#include "ccv.h"
-#ifdef HAVE_FFTW3
#include <complex.h>
+#ifdef HAVE_FFTW3
#include <fftw3.h>
#endif
@@ -471,20 +471,27 @@ static int _ccv_get_optimal_fft_size(int size)
#ifdef HAVE_FFTW3
static void _ccv_filter_fftw(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b, ccv_dense_matrix_t* d)
{
+ int ch = CCV_GET_CHANNEL(a->type);
int rows = ccv_min(a->rows, _ccv_get_optimal_fft_size(b->rows * 3));
int cols = ccv_min(a->cols, _ccv_get_optimal_fft_size(b->cols * 3));
int cols_2c = 2 * (cols / 2 + 1);
- double* fftw_a = (double*)fftw_malloc(rows * cols_2c * sizeof(double));
- double* fftw_b = (double*)fftw_malloc(rows * cols_2c * sizeof(double));
- memset(fftw_b, 0, rows * cols_2c * sizeof(double));
- double* fftw_d = (double*)fftw_malloc(rows * cols * sizeof(double));
+ double* fftw_a = (double*)fftw_malloc(rows * cols_2c * ch * sizeof(double));
+ double* fftw_b = (double*)fftw_malloc(rows * cols_2c * ch * sizeof(double));
+ memset(fftw_b, 0, rows * cols_2c * ch * sizeof(double));
+ double* fftw_d = (double*)fftw_malloc(rows * cols * ch * sizeof(double));
fftw_complex* fftw_ac = (fftw_complex*)fftw_a;
fftw_complex* fftw_bc = (fftw_complex*)fftw_b;
fftw_complex* fftw_dc = (fftw_complex*)fftw_malloc(rows * (cols / 2 + 1) * sizeof(fftw_complex));
fftw_plan p, pinv;
double scale = 1.0 / (rows * cols);
- p = fftw_plan_dft_r2c_2d(rows, cols, 0, 0, FFTW_ESTIMATE);
- pinv = fftw_plan_dft_c2r_2d(rows, cols, fftw_dc, fftw_d, FFTW_ESTIMATE);
+ if (ch == 1) {
+ p = fftw_plan_dft_r2c_2d(rows, cols, 0, 0, FFTW_ESTIMATE);
+ pinv = fftw_plan_dft_c2r_2d(rows, cols, fftw_dc, fftw_d, FFTW_ESTIMATE);
+ } else {
+ const int n[] = {rows, cols};
+ p = fftw_plan_many_dft_r2c(2, n, ch, 0, 0, ch, 1, 0, 0, ch, 1, FFTW_ESTIMATE);
+ pinv = fftw_plan_many_dft_c2r(2, n, ch, fftw_dc, 0, ch, 1, fftw_d, 0, ch, 1, FFTW_ESTIMATE);
+ }
double* fftw_ptr;
unsigned char* m_ptr;
@@ -498,7 +505,7 @@ static void _ccv_filter_fftw(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b, ccv_d
* a more classic way to do this is to pad both a and b to be a->rows + b->rows - 1,
* a->cols + b->cols - 1, but it is too expensive. In the way we introduced here, we also assume
* a border padding pattern in periodical way: |cd{BORDER}|abcd|{BORDER}ab|. */
- int i, j;
+ int i, j, k;
if (b->rows > rows || b->cols > cols)
{ /* reverse lookup */
fftw_ptr = fftw_b;
@@ -508,9 +515,10 @@ static void _ccv_filter_fftw(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b, ccv_d
for (j = 0; j < cols; j++)
{
int x = (j + cols / 2) % cols - cols / 2 + b->cols / 2;
- fftw_ptr[j] = (y >= 0 && y < b->rows && x >= 0 && x < b->cols) ? ccv_get_dense_matrix_cell_value(b, y, x) : 0;
+ for (k = 0; k < ch; k++)
+ fftw_ptr[j * ch + k] = (y >= 0 && y < b->rows && x >= 0 && x < b->cols) ? ccv_get_dense_matrix_cell_value(b, y, x, k) : 0;
}
- fftw_ptr += cols_2c;
+ fftw_ptr += cols_2c * ch;
}
} else { /* forward lookup */
int rows_bc = rows - b->rows / 2;
@@ -519,7 +527,8 @@ static void _ccv_filter_fftw(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b, ccv_d
{
int y = (i + rows_bc) % rows;
for (j = 0; j < b->cols; j++)
- fftw_b[y * cols_2c + (j + cols_bc) % cols] = ccv_get_dense_matrix_cell_value(b, i, j);
+ for (k = 0; i < ch; k++)
+ fftw_b[y * cols_2c * ch + ((j + cols_bc) % cols) * ch + k] = ccv_get_dense_matrix_cell_value(b, i, j, k);
}
}
fftw_execute_dft_r2c(p, fftw_b, fftw_bc);
@@ -532,16 +541,16 @@ static void _ccv_filter_fftw(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b, ccv_d
for (j = 0; j < tile_x; j++) \
{ \
int x, y; \
- memset(fftw_a, 0, rows * cols * sizeof(double)); \
+ memset(fftw_a, 0, rows * cols * ch * sizeof(double)); \
int iy = ccv_min(i * (rows - b->rows), a->rows - rows); \
int ix = ccv_min(j * (cols - b->cols), a->cols - cols); \
fftw_ptr = fftw_a; \
- m_ptr = (unsigned char*)ccv_get_dense_matrix_cell(a, iy, ix); \
+ m_ptr = (unsigned char*)ccv_get_dense_matrix_cell(a, iy, ix, 0); \
for (y = 0; y < rows; y++) \
{ \
- for (x = 0; x < cols; x++) \
+ for (x = 0; x < cols * ch; x++) \
fftw_ptr[x] = _for_get(m_ptr, x, 0); \
- fftw_ptr += cols_2c; \
+ fftw_ptr += cols_2c * ch; \
m_ptr += a->step; \
} \
fftw_execute_dft_r2c(p, fftw_a, fftw_ac); \
@@ -551,13 +560,13 @@ static void _ccv_filter_fftw(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b, ccv_d
fftw_ptr = fftw_d + (i > 0) * b->rows / 2 * cols + (j > 0) * b->cols / 2; \
int end_y = ccv_min(d->rows - iy, (rows - b->rows) + (i == 0) * b->rows / 2 + (i + 1 == tile_y) * (b->rows + 1) / 2); \
int end_x = ccv_min(d->cols - ix, (cols - b->cols) + (j == 0) * b->cols / 2 + (j + 1 == tile_x) * (b->cols + 1) / 2); \
- m_ptr = (unsigned char*)ccv_get_dense_matrix_cell(d, iy + (i > 0) * b->rows / 2, ix + (j > 0) * b->cols / 2); \
+ m_ptr = (unsigned char*)ccv_get_dense_matrix_cell(d, iy + (i > 0) * b->rows / 2, ix + (j > 0) * b->cols / 2, 0); \
for (y = 0; y < end_y; y++) \
{ \
- for (x = 0; x < end_x; x++) \
+ for (x = 0; x < end_x * ch; x++) \
_for_set(m_ptr, x, fftw_ptr[x], 0); \
m_ptr += d->step; \
- fftw_ptr += cols; \
+ fftw_ptr += cols * ch; \
} \
}
ccv_matrix_setter(d->type, ccv_matrix_getter, a->type, for_block);
@@ -569,6 +578,10 @@ static void _ccv_filter_fftw(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b, ccv_d
fftw_free(fftw_d);
fftw_free(fftw_dc);
}
+#else
+static void _ccv_filter_kissfft(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b, ccv_dense_matrix_t* d)
+{
+}
#endif
void _ccv_filter_direct_8u(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b, ccv_dense_matrix_t* d)
@@ -583,7 +596,7 @@ void _ccv_filter_direct_8u(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b, ccv_den
for (i = 0; i < b->rows; i++)
for (j = 0; j < b->cols; j++)
{
- coeff[nz] = (int)(ccv_get_dense_matrix_cell_value(b, i, j) * scale + 0.5);
+ coeff[nz] = (int)(ccv_get_dense_matrix_cell_value(b, i, j, 0) * scale + 0.5);
if (coeff[nz] == 0)
continue;
cy[nz] = i;
@@ -617,7 +630,7 @@ void _ccv_filter_direct_8u(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b, ccv_den
for (i = 0; i < b->rows; i++)
for (j = 0; j < b->cols; j++)
{
- coeff[k] = (int)(ccv_get_dense_matrix_cell_value(b, i, j) * scale + 0.5);
+ coeff[k] = (int)(ccv_get_dense_matrix_cell_value(b, i, j, 0) * scale + 0.5);
k++;
}
for (i = 0; i < d->rows; i++)
@@ -667,6 +680,8 @@ void ccv_filter(ccv_matrix_t* a, ccv_matrix_t* b, ccv_matrix_t** d, int type)
} else {
#ifdef HAVE_FFTW3
_ccv_filter_fftw(da, db, dd);
+#else
+ _ccv_filter_kissfft(da, db, dd);
#endif
}
}
View
5 lib/ccv_swt.c
@@ -44,10 +44,7 @@ static inline int _ccv_median(int* buf, int low, int high)
void ccv_swt(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, ccv_swt_param_t params)
{
assert(a->type & CCV_C1);
- char identifier[64];
- memset(identifier, 0, 64);
- snprintf(identifier, 64, "ccv_swt(%d,%d,%lf,%lf)", params.direction, params.size, params.low_thresh, params.high_thresh);
- uint64_t sig = (a->sig == 0) ? 0 : ccv_matrix_generate_signature(identifier, 64, a->sig, 0);
+ ccv_declare_matrix_signature(sig, a->sig != 0, ccv_sign_with_format(64, "ccv_swt(%d,%d,%lf,%lf)", params.direction, params.size, params.low_thresh, params.high_thresh), a->sig, 0);
type = (type == 0) ? CCV_32S | CCV_C1 : CCV_GET_DATA_TYPE(type) | CCV_C1;
ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, a->rows, a->cols, CCV_C1 | CCV_ALL_DATA_TYPE, type, sig);
ccv_cache_return(db, );
View
15 lib/ccv_util.c
@@ -21,10 +21,7 @@ ccv_sparse_matrix_t* ccv_get_sparse_matrix(ccv_matrix_t* mat)
void ccv_shift(ccv_matrix_t* a, ccv_matrix_t** b, int type, int lr, int rr)
{
ccv_dense_matrix_t* da = ccv_get_dense_matrix(a);
- char identifier[64];
- memset(identifier, 0, 64);
- snprintf(identifier, 64, "ccv_shift(%d,%d)", lr, rr);
- uint64_t sig = ccv_matrix_generate_signature(identifier, 64, da->sig, 0);
+ ccv_declare_matrix_signature(sig, da->sig != 0, ccv_sign_with_format(64, "ccv_shift(%d,%d)", lr, rr), da->sig, 0);
type = (type == 0) ? CCV_GET_DATA_TYPE(da->type) | CCV_GET_CHANNEL(da->type) : CCV_GET_DATA_TYPE(type) | CCV_GET_CHANNEL(da->type);
ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, da->rows, da->cols, CCV_ALL_DATA_TYPE | CCV_GET_CHANNEL(da->type), type, sig);
ccv_cache_return(db, );
@@ -404,10 +401,7 @@ void ccv_slice(ccv_matrix_t* a, ccv_matrix_t** b, int btype, int y, int x, int r
{
ccv_dense_matrix_t* da = ccv_get_dense_matrix(a);
assert(y >= 0 && y + rows <= da->rows && x >= 0 && x + cols <= da->cols);
- char identifier[128];
- memset(identifier, 0, 128);
- snprintf(identifier, 128, "ccv_slice(%d,%d,%d,%d)", y, x, rows, cols);
- uint64_t sig = (da->sig == 0) ? 0 : ccv_matrix_generate_signature(identifier, 128, da->sig, 0);
+ ccv_declare_matrix_signature(sig, da->sig != 0, ccv_sign_with_format(128, "ccv_slice(%d,%d,%d,%d)", y, x, rows, cols), da->sig, 0);
btype = (btype == 0) ? CCV_GET_DATA_TYPE(da->type) | CCV_GET_CHANNEL(da->type) : CCV_GET_DATA_TYPE(btype) | CCV_GET_CHANNEL(da->type);
ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, rows, cols, CCV_ALL_DATA_TYPE | CCV_GET_CHANNEL(da->type), btype, sig);
ccv_cache_return(db, );
@@ -436,10 +430,7 @@ void ccv_move(ccv_matrix_t* a, ccv_matrix_t** b, int btype, int y, int x)
if (type & CCV_MATRIX_DENSE)
{
ccv_dense_matrix_t* da = ccv_get_dense_matrix(a);
- char identifier[128];
- memset(identifier, 0, 128);
- snprintf(identifier, 128, "ccv_move(%d,%d)", y, x);
- uint64_t sig = (da->sig == 0) ? 0 : ccv_matrix_generate_signature(identifier, 128, da->sig, 0);
+ ccv_declare_matrix_signature(sig, da->sig != 0, ccv_sign_with_format(64, "ccv_move(%d,%d)", y, x), da->sig, 0);
btype = (btype == 0) ? CCV_GET_DATA_TYPE(da->type) | CCV_GET_CHANNEL(da->type) : CCV_GET_DATA_TYPE(btype) | CCV_GET_CHANNEL(da->type);
ccv_dense_matrix_t* db = *b = ccv_dense_matrix_renew(*b, da->rows, da->cols, CCV_ALL_DATA_TYPE | CCV_GET_CHANNEL(da->type), btype, sig);
ccv_cache_return(db, );
View
4 lib/io/_ccv_io_binary.c
@@ -1,4 +1,4 @@
-static void _ccv_serialize_binary_fd(ccv_dense_matrix_t* mat, FILE* fd, void* conf)
+static void _ccv_write_binary_fd(ccv_dense_matrix_t* mat, FILE* fd, void* conf)
{
fwrite("CCVBINDM", 1, 8, fd);
int ctype = mat->type & 0xFFFFF;
@@ -9,7 +9,7 @@ static void _ccv_serialize_binary_fd(ccv_dense_matrix_t* mat, FILE* fd, void* co
fflush(fd);
}
-static void _ccv_unserialize_binary_fd(FILE* in, ccv_dense_matrix_t** x, int type)
+static void _ccv_read_binary_fd(FILE* in, ccv_dense_matrix_t** x, int type)
{
fseek(in, 8, SEEK_SET);
fread(&type, 1, 4, in);
View
2 lib/io/_ccv_io_bmp.c
@@ -1,4 +1,4 @@
-static void _ccv_unserialize_bmp_fd(FILE* in, ccv_dense_matrix_t** x, int type)
+static void _ccv_read_bmp_fd(FILE* in, ccv_dense_matrix_t** x, int type)
{
fseek(in, 10, SEEK_SET);
int offset;
View
4 lib/io/_ccv_io_libjpeg.c
@@ -144,7 +144,7 @@ static int _ccv_jpeg_load_dht(struct jpeg_decompress_struct *info, unsigned char
* based on a message of Laurent Pinchart on the video4linux mailing list
***************************************************************************/
-static void _ccv_unserialize_jpeg_fd(FILE* in, ccv_dense_matrix_t** x, int type)
+static void _ccv_read_jpeg_fd(FILE* in, ccv_dense_matrix_t** x, int type)
{
struct jpeg_decompress_struct cinfo;
struct ccv_jpeg_error_mgr_t jerr;
@@ -277,7 +277,7 @@ static void _ccv_unserialize_jpeg_fd(FILE* in, ccv_dense_matrix_t** x, int type)
jpeg_destroy_decompress(&cinfo);
}
-static void _ccv_serialize_jpeg_fd(ccv_dense_matrix_t* mat, FILE* fd, void* conf)
+static void _ccv_write_jpeg_fd(ccv_dense_matrix_t* mat, FILE* fd, void* conf)
{
struct jpeg_compress_struct cinfo;
struct ccv_jpeg_error_mgr_t jerr;
View
4 lib/io/_ccv_io_libpng.c
@@ -1,4 +1,4 @@
-static void _ccv_unserialize_png_fd(FILE* in, ccv_dense_matrix_t** x, int type)
+static void _ccv_read_png_fd(FILE* in, ccv_dense_matrix_t** x, int type)
{
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
png_infop info_ptr = png_create_info_struct(png_ptr);
@@ -38,7 +38,7 @@ static void _ccv_unserialize_png_fd(FILE* in, ccv_dense_matrix_t** x, int type)
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
}
-static void _ccv_serialize_png_fd(ccv_dense_matrix_t* mat, FILE* fd, void* conf)
+static void _ccv_write_png_fd(ccv_dense_matrix_t* mat, FILE* fd, void* conf)
{
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
png_infop info_ptr = png_create_info_struct(png_ptr);
View
8 lib/makefile
@@ -1,14 +1,16 @@
CC = clang
-# CFLAGS = -Wall -D HAVE_LIBJPEG -D HAVE_CBLAS -D HAVE_GSL -D HAVE_LIBPNG -D HAVE_FFTW3
CFLAGS = -O3 -msse2 -Wall -D HAVE_LIBJPEG -D HAVE_CBLAS -D HAVE_GSL -D HAVE_LIBPNG -D HAVE_FFTW3 # -fopenmp -D USE_OPENMP # -D USE_OPENCL -I"/opt/ati-stream-sdk/include/"
all: libccv.a
clean:
- rm -f *.o 3rdparty/*.o libccv.a
+ rm -f *.o 3rdparty/sha1/*.o 3rdparty/kissfft/*.o libccv.a
-libccv.a: ccv_cache.o ccv_memory.o 3rdparty/sha1.o ccv_io.o ccv_numeric.o ccv_algebra.o ccv_util.o ccv_basic.o ccv_daisy.o ccv_sift.o ccv_bbf.o ccv_swt.o
+libccv.a: ccv_cache.o ccv_memory.o 3rdparty/sha1/sha1.o ccv_io.o ccv_numeric.o ccv_algebra.o ccv_util.o ccv_basic.o ccv_daisy.o ccv_sift.o ccv_bbf.o ccv_swt.o
ar rcs $@ $^
+ccv_io.o: ccv_io.c ccv.h io/*.c
+ $(CC) $(INCFLAGS) $< -o $@ -c $(CFLAGS)
+
%.o: %.c ccv.h
$(CC) $(INCFLAGS) $< -o $@ -c $(CFLAGS)
View
14 test/basic.tests.c
@@ -5,7 +5,7 @@
TEST_CASE("sobel operation")
{
ccv_dense_matrix_t* image = 0;
- ccv_unserialize("../samples/chessbox.png", &image, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
+ ccv_read("../samples/chessbox.png", &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
ccv_dense_matrix_t* x = 0;
ccv_sobel(image, &x, 0, 0, 1);
REQUIRE_MATRIX_FILE_EQ(x, "data/chessbox.sobel.x.bin", "should be sobel of partial derivative on x");
@@ -36,7 +36,7 @@ TEST_CASE("sobel operation")
TEST_CASE("resample operation of CCV_INTER_AREA")
{
ccv_dense_matrix_t* image = 0;
- ccv_unserialize("../samples/chessbox.png", &image, CCV_SERIAL_ANY_FILE);
+ ccv_read("../samples/chessbox.png", &image, CCV_IO_ANY_FILE);
ccv_dense_matrix_t* x = 0;
ccv_resample(image, &x, 0, image->rows / 5, image->cols / 5, CCV_INTER_AREA);
REQUIRE_MATRIX_FILE_EQ(x, "data/chessbox.resample.bin", "should be a image of color dot");
@@ -47,7 +47,7 @@ TEST_CASE("resample operation of CCV_INTER_AREA")
TEST_CASE("sample down operation with source offset (10, 10)")
{
ccv_dense_matrix_t* image = 0;
- ccv_unserialize("../samples/chessbox.png", &image, CCV_SERIAL_ANY_FILE);
+ ccv_read("../samples/chessbox.png", &image, CCV_IO_ANY_FILE);
ccv_dense_matrix_t* x = 0;
ccv_sample_down(image, &x, 0, 10, 10);
REQUIRE_MATRIX_FILE_EQ(x, "data/chessbox.sample_down.bin", "should be down sampled (/2) image with offset from source (10, 10)");
@@ -58,7 +58,7 @@ TEST_CASE("sample down operation with source offset (10, 10)")
TEST_CASE("sample up operation with source offset (10, 10)")
{
ccv_dense_matrix_t* image = 0;
- ccv_unserialize("../samples/chessbox.png", &image, CCV_SERIAL_ANY_FILE);
+ ccv_read("../samples/chessbox.png", &image, CCV_IO_ANY_FILE);
ccv_dense_matrix_t* x = 0;
ccv_sample_up(image, &x, 0, 10, 10);
REQUIRE_MATRIX_FILE_EQ(x, "data/chessbox.sample_up.bin", "should be down sampled (/2) image with offset from source (10, 10)");
@@ -69,7 +69,7 @@ TEST_CASE("sample up operation with source offset (10, 10)")
TEST_CASE("blur operation with sigma 10")
{
ccv_dense_matrix_t* image = 0;
- ccv_unserialize("../samples/nature.png", &image, CCV_SERIAL_ANY_FILE);
+ ccv_read("../samples/nature.png", &image, CCV_IO_ANY_FILE);
ccv_dense_matrix_t* x = 0;
ccv_blur(image, &x, 0, sqrt(10));
REQUIRE_MATRIX_FILE_EQ(x, "data/nature.blur.bin", "should be image applied with Gaussian filter with sigma sqrt(10)");
@@ -80,7 +80,7 @@ TEST_CASE("blur operation with sigma 10")
TEST_CASE("flip operation")
{
ccv_dense_matrix_t* image = 0;
- ccv_unserialize("../samples/chessbox.png", &image, CCV_SERIAL_ANY_FILE);
+ ccv_read("../samples/chessbox.png", &image, CCV_IO_ANY_FILE);
ccv_dense_matrix_t* x = 0;
ccv_flip(image, &x, 0, CCV_FLIP_X);
REQUIRE_MATRIX_FILE_EQ(x, "data/chessbox.flip_x.bin", "flipped x-axis (around y-axis)");
@@ -99,7 +99,7 @@ TEST_CASE("flip operation")
TEST_CASE("canny edge detector")
{
ccv_dense_matrix_t* image = 0;
- ccv_unserialize("../samples/blackbox.png", &image, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
+ ccv_read("../samples/blackbox.png", &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
ccv_dense_matrix_t* x = 0;
ccv_canny(image, &x, 0, 3, 36, 36 * 3);
REQUIRE_MATRIX_FILE_EQ(x, "data/blackbox.canny.bin", "Canny edge detector on artificial image");
View
40 test/case.c
@@ -1,40 +0,0 @@
-#include "case.h"
-
-TEST_CASE("fail test")
-{
- REQUIRE_EQ(1, 2, "should fail %d", 1024);
-}
-
-TEST_CASE("fail array test")
-{
- int a[3] = {1,2,3};
- int b[3] = {1,3,3};
- REQUIRE_ARRAY_EQ(int, a, b, 3, "a / b should be not equal");
-}
-
-TEST_CASE("tolerance test")
-{
- double a = 1.0 / 3.0;
- REQUIRE_EQ_WITH_TOLERANCE(1, a * 2.999, 0.001, "should fail");
-}
-
-TEST_CASE("array tolerance test")
-{
- double a[3] = {1,2,3};
- double b[3] = {1,2.001,3};
- REQUIRE_ARRAY_EQ_WITH_TOLERANCE(double, a, b, 3, 0.01, "a / b should be not equal");
-}
-
-TEST_CASE("pass test")
-{
- REQUIRE_EQ(1, 1, "should pass");
-}
-
-TEST_CASE("pass array test")
-{
- int a[3] = {1,2,3};
- int b[3] = {1,2,3};
- REQUIRE_ARRAY_EQ(int, a, b, 3, "a / b should be equal");
-}
-
-#include "case_main.h"
View
26 test/case.h
@@ -4,7 +4,7 @@
#include <stdio.h>
#include <stdint.h>
-/* the following 3 lines to generate unique name was taken from Catch: https://github.com/philsquared/Catch
+/* the following 9 lines to generate unique name was taken from Catch: https://github.com/philsquared/Catch
* here is the licence:
* Boost Software License - Version 1.0 - August 17th, 2003
*
@@ -29,9 +29,15 @@
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. */
+#ifndef INTERNAL_CATCH_UNIQUE_NAME_LINE2
#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
+#endif
+#ifndef INTERNAL_CATCH_UNIQUE_NAME_LINE
#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
+#endif
+#ifndef INTERNAL_CATCH_UNIQUE_NAME
#define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
+#endif
typedef void (*case_f)(char*, int*);
@@ -51,14 +57,14 @@ static void INTERNAL_CATCH_UNIQUE_NAME(__test_case_driver__) (char* __case_name_
#define REQUIRE(a, err, ...) { \
if (!(a)) \
{ \
- printf("\n\t\033[0;31mREQUIRE\033[0;30m: %s:%d: %s is not true, " err, __FILE__, __LINE__, #a, ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE\033[0;0m: %s:%d: %s is not true, " err, __FILE__, __LINE__, #a, ##__VA_ARGS__); \
ABORT_CASE; \
} }
#define REQUIRE_EQ(a, b, err, ...) { \
if ((a) != (b)) \
{ \
- printf("\n\t\033[0;31mREQUIRE_EQ\033[0;30m: %s:%d: %s(%lg) != %s(%lg), " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_EQ\033[0;0m: %s:%d: %s(%lg) != %s(%lg), " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), ##__VA_ARGS__); \
ABORT_CASE; \
} }
@@ -67,14 +73,14 @@ int __case_i__; \
for (__case_i__ = 0; __case_i__ < (len); __case_i__++) \
if (((type*)(a))[__case_i__] != ((type*)(b))[__case_i__]) \
{ \
- printf("\n\t\033[0;31mREQUIRE_ARRAY_EQ\033[0;30m: %s:%d: %s[%d](%lg) != %s[%d](%lg), " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_ARRAY_EQ\033[0;0m: %s:%d: %s[%d](%lg) != %s[%d](%lg), " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], ##__VA_ARGS__); \
ABORT_CASE; \
} }
#define REQUIRE_EQ_WITH_TOLERANCE(a, b, t, err, ...) { \
if ((double)((a) - (b)) > (t) || (double)((a) - (b)) < -(t)) \
{ \
- printf("\n\t\033[0;31mREQUIRE_EQ_WITH_TOLERANCE\033[0;30m: %s:%d: %s(%lg) != %s(%lg) | +-%lg, " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), (double)(t), ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_EQ_WITH_TOLERANCE\033[0;0m: %s:%d: %s(%lg) != %s(%lg) | +-%lg, " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), (double)(t), ##__VA_ARGS__); \
ABORT_CASE; \
} }
@@ -83,14 +89,14 @@ int __case_i__; \
for (__case_i__ = 0; __case_i__ < (len); __case_i__++) \
if ((double)(((type*)(a))[__case_i__] - ((type*)(b))[__case_i__]) > (t) || (double)(((type*)(a))[__case_i__] - ((type*)(b))[__case_i__]) < -(t)) \
{ \
- printf("\n\t\033[0;31mREQUIRE_ARRAY_EQ_WITH_TOLERANCE\033[0;30m: %s:%d: %s[%d](%lg) != %s[%d](%lg) | +-%lg, " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], (double)(t), ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_ARRAY_EQ_WITH_TOLERANCE\033[0;0m: %s:%d: %s[%d](%lg) != %s[%d](%lg) | +-%lg, " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], (double)(t), ##__VA_ARGS__); \
ABORT_CASE; \
} }
#define REQUIRE_NOT_EQ(a, b, err, ...) { \
if ((a) == (b)) \
{ \
- printf("\n\t\033[0;31mREQUIRE_NOT_EQ\033[0;30m: %s:%d: %s(%lg) == %s(%lg), " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_NOT_EQ\033[0;0m: %s:%d: %s(%lg) == %s(%lg), " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), ##__VA_ARGS__); \
ABORT_CASE; \
} }
@@ -99,14 +105,14 @@ int __case_i__; \
for (__case_i__ = 0; __case_i__ < (len); __case_i__++) \
if (((type*)(a))[__case_i__] == ((type*)(b))[__case_i__]) \
{ \
- printf("\n\t\033[0;31mREQUIRE_ARRAY_NOT_EQ\033[0;30m: %s:%d: %s[%d](%lg) == %s[%d](%lg), " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_ARRAY_NOT_EQ\033[0;0m: %s:%d: %s[%d](%lg) == %s[%d](%lg), " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], ##__VA_ARGS__); \
ABORT_CASE; \
} }
#define REQUIRE_NOT_EQ_WITH_TOLERANCE(a, b, t, err, ...) { \
if ((double)((a) - (b)) <= (t) && (double)((a) - (b)) >= -(t)) \
{ \
- printf("\n\t\033[0;31mREQUIRE_NOT_EQ_WITH_TLERANCE\033[0;30m: %s:%d: %s(%lg) == %s(%lg) | +-%lg, " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), (double)(t), ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_NOT_EQ_WITH_TLERANCE\033[0;0m: %s:%d: %s(%lg) == %s(%lg) | +-%lg, " err, __FILE__, __LINE__, #a, (double)(a), #b, (double)(b), (double)(t), ##__VA_ARGS__); \
ABORT_CASE; \
} }
@@ -115,7 +121,7 @@ int __case_i__; \
for (__case_i__ = 0; __case_i__ < (len); __case_i__++) \
if ((double)(((type*)(a))[__case_i__] - ((type*)(b))[__case_i__]) <= (t) && (double)(((type*)(a))[__case_i__] - ((type*)(b))[__case_i__]) >= -(t)) \
{ \
- printf("\n\t\033[0;31mREQUIRE_ARRAY_NOT_EQ_WITH_TOLERANCE\033[0;30m: %s:%d: %s[%d](%lg) == %s[%d](%lg) | +-%lg, " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], (double)(t), ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_ARRAY_NOT_EQ_WITH_TOLERANCE\033[0;0m: %s:%d: %s[%d](%lg) == %s[%d](%lg) | +-%lg, " err, __FILE__, __LINE__, #a, __case_i__, (double)((type*)(a))[__case_i__], #b, __case_i__, (double)((type*)(b))[__case_i__], (double)(t), ##__VA_ARGS__); \
ABORT_CASE; \
} }
View
10 test/case_main.h
@@ -258,24 +258,24 @@ int main(int argc, char** argv)
case_t* test_suite = (case_t*)(start_pointer + i);
if (test_suite->sig == 0x883253372849284B)
{
- printf("\033[0;34m[%d/%d]\033[0;30m \033[1;33m[RUN]\033[0;30m %s ...", j, total, test_suite->name);
+ printf("\033[0;34m[%d/%d]\033[0;0m \033[1;33m[RUN]\033[0;0m %s ...", j, total, test_suite->name);
int result = 0;
test_suite->driver(test_suite->name, &result);
if (result == 0)
{
pass++;
- printf("\r\033[0;34m[%d/%d]\033[0;30m \033[1;32m[PASS]\033[0;30m %s \n", j, total, test_suite->name);
+ printf("\r\033[0;34m[%d/%d]\033[0;0m \033[1;32m[PASS]\033[0;0m %s \n", j, total, test_suite->name);
} else {
fail++;
- printf("\n\033[0;34m[%d/%d]\033[0;30m \033[1;31m[FAIL]\033[0;30m %s\n", j, total, test_suite->name);
+ printf("\n\033[0;34m[%d/%d]\033[0;0m \033[1;31m[FAIL]\033[0;0m %s\n", j, total, test_suite->name);
}
j++;
}
}
if (fail == 0)
- printf("\033[0;32mall test case(s) passed, congratulations!\033[0;30m\n");
+ printf("\033[0;32mall test case(s) passed, congratulations!\033[0;0m\n");
else
- printf("\033[0;31m%d of %d test case(s) passed\033[0;30m\n", pass, fail + pass);
+ printf("\033[0;31m%d of %d test case(s) passed\033[0;0m\n", pass, fail + pass);
return fail;
}
View
6 test/ccv_case.h
@@ -4,16 +4,16 @@
#define REQUIRE_MATRIX_EQ(a, b, err, ...) { \
if (ccv_matrix_eq(a, b) != 0) \
{ \
- printf("\n\t\033[0;31mREQUIRE_MATRIX_EQ\033[0;30m: %s:%d: %s != %s, " err, __FILE__, __LINE__, #a, #b, ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_MATRIX_EQ\033[0;0m: %s:%d: %s != %s, " err, __FILE__, __LINE__, #a, #b, ##__VA_ARGS__); \
ABORT_CASE; \
} }
#define REQUIRE_MATRIX_FILE_EQ(a, f, err, ...) { \
ccv_dense_matrix_t* __case_b__ = 0; \
-ccv_unserialize(f, &__case_b__, CCV_SERIAL_ANY_FILE); \
+ccv_read(f, &__case_b__, CCV_IO_ANY_FILE); \
if (ccv_matrix_eq(a, __case_b__) != 0) \
{ \
- printf("\n\t\033[0;31mREQUIRE_MATRIX_FILE_EQ\033[0;30m: %s:%d: %s != %s, " err, __FILE__, __LINE__, #a, #f, ##__VA_ARGS__); \
+ printf("\n\t\033[0;31mREQUIRE_MATRIX_FILE_EQ\033[0;0m: %s:%d: %s != %s, " err, __FILE__, __LINE__, #a, #f, ##__VA_ARGS__); \
ccv_matrix_free(__case_b__); \
ABORT_CASE; \
} \
View
2 test/numeric.tests.c
@@ -48,7 +48,7 @@ double gaussian(double x, double y, void* data)
TEST_CASE("FFTW-based filter on Gaussian kernel")
{
ccv_dense_matrix_t* image = 0;
- ccv_unserialize("../samples/nature.png", &image, CCV_SERIAL_GRAY | CCV_SERIAL_ANY_FILE);
+ ccv_read("../samples/nature.png", &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
ccv_dense_matrix_t* gray = 0;ccv_dense_matrix_new(image->rows, image->cols, CCV_32F | CCV_C1, 0, 0);
ccv_shift(image, (ccv_matrix_t**)&gray, CCV_32F | CCV_C1, 0, 0);
ccv_dense_matrix_t* kernel = ccv_dense_matrix_new(10, 10, CCV_32F | CCV_C1, 0, 0);
View
2 test/util.tests.c
@@ -122,7 +122,7 @@ TEST_CASE("compress sparse matrix")
TEST_CASE("matrix slice")
{
ccv_dense_matrix_t* image = 0;
- ccv_unserialize("../samples/chessbox.png", &image, CCV_SERIAL_ANY_FILE);
+ ccv_read("../samples/chessbox.png", &image, CCV_IO_ANY_FILE);
ccv_dense_matrix_t* b = 0;
ccv_slice(image, (ccv_matrix_t**)&b, 0, 33, 41, 111, 91);
REQUIRE_MATRIX_FILE_EQ(b, "data/chessbox.slice.bin", "should have data/chessbox.png sliced at (33, 41) with 111 x 91");

0 comments on commit dca50eb

Please sign in to comment.
Something went wrong with that request. Please try again.