diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/include/graphs.hpp b/include/graphs.hpp index bf60e15..ddcca32 100644 --- a/include/graphs.hpp +++ b/include/graphs.hpp @@ -16,6 +16,8 @@ unsigned long fresh_screen(int signal); //计算函数声明 void draw_fields(int signal); +int create_fields(int hw); + /************************************************ 颜色的抽象 ***/ diff --git a/include/type.hpp b/include/type.hpp index 0340baf..f642110 100644 --- a/include/type.hpp +++ b/include/type.hpp @@ -1,6 +1,7 @@ #ifndef type_h #define type_h + #include #include #include @@ -11,7 +12,16 @@ #include #include #include +#define _CRT_SECURE_NO_WARNINGS #endif + +#ifdef WIN32 +#include +#include +#pragma warning(disable:4996) +#endif + + #include #include #include diff --git a/include/wav.hpp b/include/wav.hpp index 3a70640..7b34c24 100644 --- a/include/wav.hpp +++ b/include/wav.hpp @@ -9,6 +9,7 @@ using std::string; using std::vector; FILE * readWAVInfo(void); +int init_test_wav(int); struct WAV_Format{ uint32_t ChunkID; /* "RIFF" */ diff --git a/src/fields.cpp b/src/fields.cpp index 7c544fb..3f404ba 100644 --- a/src/fields.cpp +++ b/src/fields.cpp @@ -1 +1,4 @@ #include + + + diff --git a/src/graphs.cpp b/src/graphs.cpp index f62036d..6072dcb 100644 --- a/src/graphs.cpp +++ b/src/graphs.cpp @@ -3,12 +3,34 @@ #include + extern int if_fresh, if_draw; extern vector fields; extern Window *p_nwd; extern WAV twav; extern Shape *p_avg; +#ifdef WIN32 +int gettimeofday(struct timeval *tp, void *tzp) +{ + time_t clock; + struct tm tm; + SYSTEMTIME wtm; + GetLocalTime(&wtm); + tm.tm_year = wtm.wYear - 1900; + tm.tm_mon = wtm.wMonth - 1; + tm.tm_mday = wtm.wDay; + tm.tm_hour = wtm.wHour; + tm.tm_min = wtm.wMinute; + tm.tm_sec = wtm.wSecond; + tm.tm_isdst = -1; + clock = mktime(&tm); + tp->tv_sec = clock; + tp->tv_usec = wtm.wMilliseconds * 1000; + return (0); +} +#endif + void draw_fields(int signal){ if (if_fresh == 1 && if_draw == 0){ timeval timer_a, timer_b; @@ -57,3 +79,17 @@ unsigned long fresh_screen(int signal){ return -1; } +int create_fields(int hw) { + for (int y = 0; y < hw; y++) { + for (int x = 0; x < hw; x++) { + double dx = x / 16.8, dy = y / 16.8; + Field *p_field = new Field({ {-0.9 + dx,0.9 - dy,0},{-(0.848) + dx,(0.848) - dy,0} }); + p_nwd->draw_shape(p_field); + fields.push_back(p_field); + } + } + fields[0]->color.setColor({ 0,0,0 }); + p_avg->setRetangle({ {0.98,-0.98},{0.85,-0.85} }); + p_nwd->draw_shape(p_avg); + return 0; +} diff --git a/src/hsv.cpp b/src/hsv.cpp index bd16bb5..7620173 100644 --- a/src/hsv.cpp +++ b/src/hsv.cpp @@ -2,112 +2,114 @@ #include #include + + hsv rgb2hsv(rgb in) { - hsv out; - double min, max, delta; + hsv out; + double min, max, delta; - min = in.r < in.g ? in.r : in.g; - min = min < in.b ? min : in.b; + min = in.r < in.g ? in.r : in.g; + min = min < in.b ? min : in.b; - max = in.r > in.g ? in.r : in.g; - max = max > in.b ? max : in.b; + max = in.r > in.g ? in.r : in.g; + max = max > in.b ? max : in.b; - out.v = max; // v - delta = max - min; - if (delta < 0.00001) - { - out.s = 0; - out.h = 0; // undefined, maybe nan? - return out; - } - if (max > 0.0) { // NOTE: if Max is == 0, this divide would cause a crash - out.s = (delta / max); // s - } - else { - // if max is 0, then r = g = b = 0 - // s = 0, h is undefined - out.s = 0.0; - out.h = NAN; // its now undefined - return out; - } - if (in.r >= max) // > is bogus, just keeps compilor happy - out.h = (in.g - in.b) / delta; // between yellow & magenta - else - if (in.g >= max) - out.h = 2.0 + (in.b - in.r) / delta; // between cyan & yellow - else - out.h = 4.0 + (in.r - in.g) / delta; // between magenta & cyan + out.v = max; // v + delta = max - min; + if (delta < 0.00001) + { + out.s = 0; + out.h = 0; // undefined, maybe nan? + return out; + } + if (max > 0.0) { // NOTE: if Max is == 0, this divide would cause a crash + out.s = (delta / max); // s + } + else { + // if max is 0, then r = g = b = 0 + // s = 0, h is undefined + out.s = 0.0; + out.h = NAN; // its now undefined + return out; + } + if (in.r >= max) // > is bogus, just keeps compilor happy + out.h = (in.g - in.b) / delta; // between yellow & magenta + else + if (in.g >= max) + out.h = 2.0 + (in.b - in.r) / delta; // between cyan & yellow + else + out.h = 4.0 + (in.r - in.g) / delta; // between magenta & cyan - out.h *= 60.0; // degrees + out.h *= 60.0; // degrees - if (out.h < 0.0) - out.h += 360.0; + if (out.h < 0.0) + out.h += 360.0; - return out; + return out; } rgb hsv2rgb(hsv in) { - double hh, p, q, t, ff; - long i; - rgb out; + double hh, p, q, t, ff; + long i; + rgb out; - if (in.s <= 0.0) { // < is bogus, just shuts up warnings - out.r = in.v; - out.g = in.v; - out.b = in.v; - return out; - } - hh = in.h; - if (hh >= 360.0) hh = 0.0; - hh /= 60.0; - i = (long)hh; - ff = hh - i; - p = in.v * (1.0 - in.s); - q = in.v * (1.0 - (in.s * ff)); - t = in.v * (1.0 - (in.s * (1.0 - ff))); + if (in.s <= 0.0) { // < is bogus, just shuts up warnings + out.r = in.v; + out.g = in.v; + out.b = in.v; + return out; + } + hh = in.h; + if (hh >= 360.0) hh = 0.0; + hh /= 60.0; + i = (long)hh; + ff = hh - i; + p = in.v * (1.0 - in.s); + q = in.v * (1.0 - (in.s * ff)); + t = in.v * (1.0 - (in.s * (1.0 - ff))); - switch (i) { - case 0: - out.r = in.v; - out.g = t; - out.b = p; - break; - case 1: - out.r = q; - out.g = in.v; - out.b = p; - break; - case 2: - out.r = p; - out.g = in.v; - out.b = t; - break; + switch (i) { + case 0: + out.r = in.v; + out.g = t; + out.b = p; + break; + case 1: + out.r = q; + out.g = in.v; + out.b = p; + break; + case 2: + out.r = p; + out.g = in.v; + out.b = t; + break; - case 3: - out.r = p; - out.g = q; - out.b = in.v; - break; - case 4: - out.r = t; - out.g = p; - out.b = in.v; - break; - case 5: - default: - out.r = in.v; - out.g = p; - out.b = q; - break; - } - return out; + case 3: + out.r = p; + out.g = q; + out.b = in.v; + break; + case 4: + out.r = t; + out.g = p; + out.b = in.v; + break; + case 5: + default: + out.r = in.v; + out.g = p; + out.b = q; + break; + } + return out; } /* void addsaturation(hsv &in) { - in.s += 0.1; - in.s > 1 ? 1 : 1; - return; + in.s += 0.1; + in.s > 1 ? 1 : 1; + return; }*/ diff --git a/src/wav.cpp b/src/wav.cpp index 74c96a4..5077e4d 100644 --- a/src/wav.cpp +++ b/src/wav.cpp @@ -1,5 +1,7 @@ #include +extern WAV twav; + FILE * readWAVInfo(void){ FILE *fp = NULL; struct WAV_Format wav; @@ -8,3 +10,10 @@ FILE * readWAVInfo(void){ return fp; } + + +int init_test_wav(int ms) { + twav.getInfo(); + twav.setTimer(ms); + return sqrt(twav.m_pss.step); +} diff --git a/windows/main.cpp b/windows/main.cpp new file mode 100644 index 0000000..9de8492 --- /dev/null +++ b/windows/main.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +int if_fresh = 1, if_draw = 0; +list Window::shapes = {}; +map Window::menus = {}; +vector fields; +unsigned long fresh_screen(int signal); + +FILE *fp; +Window *p_nwd = NULL; + +WAV twav("data/test.wav"); +Shape *p_avg = new Shape(); + +int main(int argc, char * argv[]) { + Window nwd(argc, argv); + p_nwd = &nwd; + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + glutInitWindowPosition(100, 100); + glutInitWindowSize(700, 700); + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + int hw = init_test_wav(60); + create_fields(hw); + nwd.create("Fields"); + nwd.show(); + + return 0; +} \ No newline at end of file