void GameSwitcher::loadFPS() { // Load FPS rendering settings FileParser infile; // @CLASS GameSwitcher: FPS counter|Description of menus/fps.txt if (infile.open("menus/fps.txt")) { while(infile.next()) { // @ATTR position|x (integer), y (integer), align (alignment)|Position of the fps counter. if(infile.key == "position") { fps_position.x = popFirstInt(infile.val); fps_position.y = popFirstInt(infile.val); fps_corner = parse_alignment(popFirstString(infile.val)); } // @ATTR color|r (integer), g (integer), b (integer)|Color of the fps counter text. else if(infile.key == "color") { fps_color = toRGB(infile.val); } else { infile.error("GameSwitcher: '%s' is not a valid key.", infile.key.c_str()); } } infile.close(); } // this is a dummy string used to approximate the fps position when aligned to the right font->setFont("font_regular"); fps_position.w = font->calc_width("00 fps"); fps_position.h = font->getLineHeight(); // Delete the label object if it exists (we'll recreate this with showFPS()) if (label_fps) { delete label_fps; label_fps = NULL; } }
SDLFontEngine::SDLFontEngine() : FontEngine(), active_font(NULL) { // Initiate SDL_ttf if(!TTF_WasInit() && TTF_Init()==-1) { logError("SDLFontEngine: TTF_Init: %s", TTF_GetError()); Exit(2); } // load the fonts // @CLASS SDLFontEngine: Font settings|Description of engine/font_settings.txt FileParser infile; if (infile.open("engine/font_settings.txt")) { while (infile.next()) { if (infile.new_section) { SDLFontStyle f; f.name = infile.section; font_styles.push_back(f); } if (font_styles.empty()) continue; SDLFontStyle *style = &(font_styles.back()); if ((infile.key == "default" && style->path == "") || infile.key == LANGUAGE) { // @ATTR $STYLE.default, $STYLE.$LANGUAGE|filename (string), point size (integer), blending (boolean)|Filename, point size, and blend mode of the font to use for this language. $STYLE can be something like "font_normal" or "font_bold". $LANGUAGE can be a 2-letter region code. style->path = popFirstString(infile.val); style->ptsize = popFirstInt(infile.val); style->blend = toBool(popFirstString(infile.val)); style->ttfont = TTF_OpenFont(mods->locate("fonts/" + style->path).c_str(), style->ptsize); if(style->ttfont == NULL) { logError("FontEngine: TTF_OpenFont: %s", TTF_GetError()); } else { int lineskip = TTF_FontLineSkip(style->ttfont); style->line_height = lineskip; style->font_height = lineskip; } } } infile.close(); } // set the font colors Color color; if (infile.open("engine/font_colors.txt")) { while (infile.next()) { // @ATTR menu_normal, menu_bonus, menu_penalty, widget_normal, widget_disabled|r (integer), g (integer), b (integer)|Colors for menus and widgets // @ATTR combat_givedmg, combat_takedmg, combat_crit, combat_buff, combat_miss|r (integer), g (integer), b (integer)|Colors for combat text // @ATTR requirements_not_met, item_bonus, item_penalty, item_flavor|r (integer), g (integer), b (integer)|Colors for tooltips // @ATTR item_$QUALITY|r (integer), g (integer), b (integer)|Colors for item quality. $QUALITY should match qualities used in items/items.txt color_map[infile.key] = toRGB(infile.val); } infile.close(); } // Attempt to set the default active font setFont("font_regular"); if (!active_font) { logError("FontEngine: Unable to determine default font!"); Exit(1); } }
bool GUI::updateFrame() { frame = camera->getFrame(); rgbFrame = toRGB(frame); image = Gdk::Pixbuf::create_from_data((const guint8*) rgbFrame.data, Gdk::COLORSPACE_RGB, false, 8, (int) rgbFrame.width, (int) rgbFrame.height, (int) rgbFrame.width * 3); window->getImageArea()->queue_draw(); return true; }
void setFormat(Image * I, int type_) { transfer(I,1); if(I->type == type_) return; else if(type_ == HSVTYPE) toHSV(I); else if(type_ == RGBTYPE) toRGB(I); I->type = type_; }
RGB addRGB(iRGB c1, iRGB c2) { iRGB sum; sum.r = c1.r + c2.r; sum.g = c1.g + c2.g; sum.b = c1.b + c2.b; return toRGB(sum); };
bool MainWindow::updateFrame() { if (!playing) { return false; } frame = camera->getFrame(); rgbFrame = toRGB(frame); imageBeforeArea.updateFrame(&frame, &rgbFrame); imageAfterArea.updateFrame(&frame, &rgbFrame); return true; }
COLORREF CColorWnd::HLS_To_RGB(float H, float L, float S) { float p1, p2, R, G, B; if (L <= 0.5) p2 = L * (1 + S); else p2 = L + S - (L * S); p1 = 2 * L - p2; if (S == 0) { R = L; G = L; B = L; } else { R = toRGB(p1, p2, H + 120); G = toRGB(p1, p2, H); B = toRGB(p1, p2, H - 120); } return RGB(R * 255, G * 255, B * 255); }
/* Writes a Portable PixMap, requires all file name to have ext .ppm to work. */ bool writeImage(char* name, unsigned int* img, int height, int width) { /** This function is a C ported verions of Dr.Bebis' code. It now handles colors.**/ FILE* fptr; //Sets write mode to binary fptr = fopen(name, "w"); if (!fptr) { printf("Can't open file: %s", name); exit(1); } //PPM in binary mode is P6 fprintf(fptr, "P3\n"); fprintf(fptr, "%d %d\n", width, height); fprintf(fptr, "255\n"); for (int idx = 0; idx < height * width; idx++) { //Convert to RGB Color* color = toRGB(img[idx]); unsigned int red = color->red; unsigned int green = color->green; unsigned int blue = color->blue; //Print the RGB fprintf(fptr, "%3u %3u %3u", red, green, blue); //Figure out if need a new line or white space int len = idx + 1; if (len % width == 0) { fprintf(fptr, "\n"); } else { fprintf(fptr, " "); } } fclose(fptr); return true; }
void KColourProc::gammaCorrect( int& r, int& g, int& b ) const { double dr = (double)r; double dg = (double)g; double db = (double)b; if( toHSV( dr, dg, db ) == false ) return; db = _gammat [ (int) (db * MAX_GAMMA) ]; toRGB( dr, dg, db ); r = (int)dr; g = (int)dg; b = (int)db; }
int hsi(IplImage* img) { int *huearr; float *intarr, *satarr; int width = img->width; int height = img->height; int depth = img->depth; int nchannels = img->nChannels; //cvShowImage("RGB-Image(Original)",img); IplImage *intensity = cvCreateImage( cvSize(width,height), depth, 1); IplImage *saturation = cvCreateImage(cvSize(width,height), depth, 1); IplImage *hue = cvCreateImage(cvSize(width,height), depth, 1); IplImage *hsiimg = cvCreateImage(cvSize(width, height), depth, nchannels); huearr = (int*)malloc(width*height*sizeof(int)); satarr = (float*)malloc(width*height*sizeof(int)); intarr = (float*)malloc(width*height*sizeof(int)); toIntensity(img, intensity, intarr); toSaturation(img, saturation, satarr); toHue(img, hue, huearr); segmentation(huearr, satarr, intarr, height, width); toRGB(hsiimg, huearr, satarr, intarr); //cvShowImage("Intensity-Image", intensity); //cvShowImage("Saturation-Image", saturation); //cvShowImage("Hue-Image", hue); cvShowImage("HSI2RGB-Image", hsiimg); //cvNamedWindow("RGB-Image(Original)",CV_WINDOW_AUTOSIZE); //cvNamedWindow("HSI-Image",CV_WINDOW_AUTOSIZE); //cvMoveWindow("RGB-Image(Original)",100,100); //cvMoveWindow("HSI-Image",100,500); //cvDestroyWindow("Image"); cvReleaseImage(&intensity); cvReleaseImage(&saturation); cvReleaseImage(&hsiimg); return 0; }
/** * Load a specific item qualities file * * @param filename The (full) path and name of the file to load */ void ItemManager::loadQualities(const std::string& filename, bool locateFileName) { FileParser infile; // @CLASS ItemManager: Qualities|Definition of a item qualities, items/types.txt... if (infile.open(filename, locateFileName)) { while (infile.next()) { if (infile.new_section) { if (infile.section == "quality") { // check if the previous quality and remove it if there is no identifier if (!item_qualities.empty() && item_qualities.back().id == "") { item_qualities.pop_back(); } item_qualities.resize(item_qualities.size()+1); } } if (item_qualities.empty() || infile.section != "quality") continue; // @ATTR quality.id|string|Item quality identifier. if (infile.key == "id") item_qualities.back().id = infile.val; // @ATTR quality.name|string|Item quality name. else if (infile.key == "name") item_qualities.back().name = infile.val; // @ATTR quality.color|r (integer), g (integer), b (integer)|Item quality color. else if (infile.key == "color") item_qualities.back().color = toRGB(infile.val); else infile.error("ItemManager: '%s' is not a valid key.", infile.key.c_str()); } infile.close(); // check if the last quality and remove it if there is no identifier if (!item_qualities.empty() && item_qualities.back().id == "") { item_qualities.pop_back(); } } }
static int vidcap_testcard_init(const struct vidcap_params *params, void **state) { struct testcard_state *s; char *filename; const char *strip_fmt = NULL; FILE *in = NULL; unsigned int i, j; unsigned int rect_size = COL_NUM; codec_t codec = RGBA; int aligned_x; char *save_ptr = NULL; if (vidcap_params_get_fmt(params) == NULL || strcmp(vidcap_params_get_fmt(params), "help") == 0) { printf("testcard options:\n"); printf("\t-t testcard:<width>:<height>:<fps>:<codec>[:filename=<filename>][:p][:s=<X>x<Y>][:i|:sf][:still][:pattern=bars|blank|noise]\n"); printf("\t<filename> - use file named filename instead of default bars\n"); printf("\tp - pan with frame\n"); printf("\ts - split the frames into XxY separate tiles\n"); printf("\ti|sf - send as interlaced or segmented frame (if none of those is set, progressive is assumed)\n"); printf("\tstill - send still image\n"); printf("\tpattern - pattern to use\n"); show_codec_help("testcard", codecs_8b, codecs_10b); return VIDCAP_INIT_NOERR; } s = new testcard_state(); if (!s) return VIDCAP_INIT_FAIL; s->frame = vf_alloc(1); char *fmt = strdup(vidcap_params_get_fmt(params)); char *tmp; int h_align = 0; double bpp = 0; if (strlen(fmt) == 0) { free(fmt); fmt = strdup(DEFAULT_FORMAT); } tmp = strtok_r(fmt, ":", &save_ptr); if (!tmp) { fprintf(stderr, "Wrong format for testcard '%s'\n", fmt); goto error; } vf_get_tile(s->frame, 0)->width = atoi(tmp); tmp = strtok_r(NULL, ":", &save_ptr); if (!tmp) { fprintf(stderr, "Wrong format for testcard '%s'\n", fmt); goto error; } vf_get_tile(s->frame, 0)->height = atoi(tmp); tmp = strtok_r(NULL, ":", &save_ptr); if (!tmp) { fprintf(stderr, "Wrong format for testcard '%s'\n", fmt); goto error; } s->frame->fps = atof(tmp); tmp = strtok_r(NULL, ":", &save_ptr); if (!tmp) { fprintf(stderr, "Wrong format for testcard '%s'\n", fmt); goto error; } codec = get_codec_from_name(tmp); if (codec == VIDEO_CODEC_NONE) { fprintf(stderr, "Unknown codec '%s'\n", tmp); goto error; } { const codec_t *sets[] = {codecs_8b, codecs_10b}; bool supported = false; for (int i = 0; i < 2; ++i) { const codec_t *it = sets[i]; while (*it != VIDEO_CODEC_NONE) { if (codec == *it++) { supported = true; } } } if (!supported) { log_msg(LOG_LEVEL_ERROR, "Unsupported codec '%s'\n", tmp); goto error; } } h_align = get_halign(codec); bpp = get_bpp(codec); s->frame->color_spec = codec; s->still_image = FALSE; if(bpp == 0) { fprintf(stderr, "Unsupported codec '%s'\n", tmp); goto error; } aligned_x = vf_get_tile(s->frame, 0)->width; if (h_align) { aligned_x = (aligned_x + h_align - 1) / h_align * h_align; } rect_size = (vf_get_tile(s->frame, 0)->width + rect_size - 1) / rect_size; s->frame_linesize = aligned_x * bpp; s->frame->interlacing = PROGRESSIVE; s->size = aligned_x * vf_get_tile(s->frame, 0)->height * bpp; filename = NULL; tmp = strtok_r(NULL, ":", &save_ptr); while (tmp) { if (strcmp(tmp, "p") == 0) { s->pan = 48; } else if (strncmp(tmp, "filename=", strlen("filename=")) == 0) { filename = tmp + strlen("filename="); in = fopen(filename, "r"); if (!in) { perror("fopen"); goto error; } fseek(in, 0L, SEEK_END); long filesize = ftell(in); assert(filesize >= 0); fseek(in, 0L, SEEK_SET); s->data = (char *) malloc(s->size * bpp * 2); if (s->size != filesize) { fprintf(stderr, "Error wrong file size for selected " "resolution and codec. File size %ld, " "computed size %d\n", filesize, s->size); goto error; } if (!in || fread(s->data, filesize, 1, in) == 0) { fprintf(stderr, "Cannot read file %s\n", filename); goto error; } fclose(in); in = NULL; memcpy(s->data + s->size, s->data, s->size); vf_get_tile(s->frame, 0)->data = s->data; } else if (strncmp(tmp, "s=", 2) == 0) { strip_fmt = tmp; } else if (strcmp(tmp, "i") == 0) { s->frame->interlacing = INTERLACED_MERGED; } else if (strcmp(tmp, "sf") == 0) { s->frame->interlacing = SEGMENTED_FRAME; } else if (strcmp(tmp, "still") == 0) { s->still_image = TRUE; } else if (strncmp(tmp, "pattern=", strlen("pattern=")) == 0) { const char *pattern = tmp + strlen("pattern="); if (strcmp(pattern, "bars") == 0) { s->pattern = image_pattern::BARS; } else if (strcmp(pattern, "blank") == 0) { s->pattern = image_pattern::BLANK; } else if (strcmp(pattern, "noise") == 0) { s->pattern = image_pattern::NOISE; } else { fprintf(stderr, "[testcard] Unknown pattern!\n");; goto error; } } else { fprintf(stderr, "[testcard] Unknown option: %s\n", tmp); goto error; } tmp = strtok_r(NULL, ":", &save_ptr); } if (!filename) { struct testcard_rect r; int col_num = 0; s->pixmap.w = aligned_x; s->pixmap.h = vf_get_tile(s->frame, 0)->height * 2; int pixmap_len = s->pixmap.w * s->pixmap.h * 4; // maximal size (RGBA/r10k - has 4 bpp) s->pixmap.data = malloc(pixmap_len); if (s->pattern == image_pattern::BLANK) { memset(s->pixmap.data, 0, pixmap_len); } else if (s->pattern == image_pattern::NOISE) { uint8_t *sample = (uint8_t *) s->pixmap.data; for (int i = 0; i < pixmap_len; ++i) { *sample++ = rand() % 0xff; } } else { assert (s->pattern == image_pattern::BARS); for (j = 0; j < vf_get_tile(s->frame, 0)->height; j += rect_size) { int grey = 0xff010101; if (j == rect_size * 2) { r.w = vf_get_tile(s->frame, 0)->width; r.h = rect_size / 4; r.x = 0; r.y = j; testcard_fillRect(&s->pixmap, &r, 0xffffffff); r.h = rect_size - (rect_size * 3 / 4); r.y = j + rect_size * 3 / 4; testcard_fillRect(&s->pixmap, &r, 0xff000000); } for (i = 0; i < vf_get_tile(s->frame, 0)->width; i += rect_size) { r.w = rect_size; r.h = rect_size; r.x = i; r.y = j; printf("Fill rect at %d,%d\n", r.x, r.y); if (j != rect_size * 2) { testcard_fillRect(&s->pixmap, &r, rect_colors[col_num]); col_num = (col_num + 1) % COL_NUM; } else { r.h = rect_size / 2; r.y += rect_size / 4; testcard_fillRect(&s->pixmap, &r, grey); grey += 0x00010101 * (255 / COL_NUM); } } } } s->data = (char *) s->pixmap.data; if (codec == UYVY || codec == v210) { rgb2yuv422((unsigned char *) s->data, aligned_x, vf_get_tile(s->frame, 0)->height); } if (codec == v210) { s->data = (char *)tov210((unsigned char *) s->data, aligned_x, aligned_x, vf_get_tile(s->frame, 0)->height, bpp); free(s->pixmap.data); } if (codec == R10k) { toR10k((unsigned char *) s->data, vf_get_tile(s->frame, 0)->width, vf_get_tile(s->frame, 0)->height); } if(codec == RGB) { s->data = (char *)toRGB((unsigned char *) s->data, vf_get_tile(s->frame, 0)->width, vf_get_tile(s->frame, 0)->height); free(s->pixmap.data); } tmp = filename; vf_get_tile(s->frame, 0)->data = (char *) malloc(2 * s->size); memcpy(vf_get_tile(s->frame, 0)->data, s->data, s->size); memcpy(vf_get_tile(s->frame, 0)->data + s->size, vf_get_tile(s->frame, 0)->data, s->size); free(s->data); s->data = vf_get_tile(s->frame, 0)->data; } s->count = 0; s->last_frame_time = std::chrono::steady_clock::now(); printf("Testcard capture set to %dx%d, bpp %f\n", vf_get_tile(s->frame, 0)->width, vf_get_tile(s->frame, 0)->height, bpp); vf_get_tile(s->frame, 0)->data_len = s->size; if(strip_fmt != NULL) { if(configure_tiling(s, strip_fmt) != 0) { goto error; } } if(vidcap_params_get_flags(params) & VIDCAP_FLAG_AUDIO_EMBEDDED) { s->grab_audio = TRUE; if(configure_audio(s) != 0) { s->grab_audio = FALSE; fprintf(stderr, "[testcard] Disabling audio output. " "SDL-mixer missing, running on Mac or other problem.\n"); } } else { s->grab_audio = FALSE; } free(fmt); *state = s; return VIDCAP_INIT_OK; error: free(fmt); free(s->data); vf_free(s->frame); if (in) fclose(in); delete s; return VIDCAP_INIT_FAIL; }
/** * Load a specific item sets file * * @param filename The (full) path and name of the file to load */ void ItemManager::loadSets(const std::string& filename, bool locateFileName) { FileParser infile; // @CLASS ItemManager: Sets|Definition of a item sets, items/sets.txt... if (!infile.open(filename, locateFileName)) return; bool clear_bonus = true; int id = 0; bool id_line; while (infile.next()) { if (infile.key == "id") { // @ATTR id|integer|A uniq id for the item set. id_line = true; id = toInt(infile.val); if (id > 0) { size_t new_size = id+1; if (item_sets.size() <= new_size) item_sets.resize(new_size); } clear_bonus = true; } else id_line = false; if (id < 1) { if (id_line) infile.error("ItemManager: Item set index out of bounds 1-%d, skipping set.", INT_MAX); continue; } if (id_line) continue; assert(item_sets.size() > std::size_t(id)); if (infile.key == "name") { // @ATTR name|string|Name of the item set. item_sets[id].name = msg->get(infile.val); } else if (infile.key == "items") { // @ATTR items|[item_id,...]|List of item id's that is part of the set. item_sets[id].items.clear(); std::string item_id = infile.nextValue(); while (item_id != "") { int temp_id = toInt(item_id); if (temp_id > 0 && temp_id < static_cast<int>(items.size())) { items[temp_id].set = id; item_sets[id].items.push_back(temp_id); } else { const int maxsize = static_cast<int>(items.size()-1); infile.error("ItemManager: Item index out of bounds 1-%d, skipping item.", maxsize); } item_id = infile.nextValue(); } } else if (infile.key == "color") { // @ATTR color|color|A specific of color for the set. item_sets[id].color = toRGB(infile.val); } else if (infile.key == "bonus") { // @ATTR bonus|[requirements (integer), bonus stat (string), bonus (integer)]|Bonus to append to items in the set. if (clear_bonus) { item_sets[id].bonus.clear(); clear_bonus = false; } Set_bonus bonus; bonus.requirement = toInt(infile.nextValue()); parseBonus(bonus, infile); item_sets[id].bonus.push_back(bonus); } else { infile.error("ItemManager: '%s' is not a valid key.", infile.key.c_str()); } } infile.close(); }
SDLFontEngine::SDLFontEngine() : FontEngine(), active_font(NULL) { // Initiate SDL_ttf if(!TTF_WasInit() && TTF_Init()==-1) { logError("SDLFontEngine: TTF_Init: %s", TTF_GetError()); Exit(2); } // load the fonts // @CLASS SDLFontEngine: Font settings|Description of engine/font_settings.txt FileParser infile; if (infile.open("engine/font_settings.txt")) { while (infile.next()) { if (infile.new_section && infile.section == "font") { SDLFontStyle f; f.name = infile.section; font_styles.push_back(SDLFontStyle()); } if (font_styles.empty()) continue; SDLFontStyle *style = &(font_styles.back()); if (infile.key == "id") { // @ATTR font.id|string|An identifier used to reference this font. style->name = infile.val; } else if (infile.key == "style") { // @ATTR font.style|repeatable(["default", predefined_string], filename, int, bool) : Language, Font file, Point size, Blending|Filename, point size, and blend mode of the font to use for this language. Language can be "default" or a 2-letter region code. std::string lang = popFirstString(infile.val); if ((lang == "default" && style->path == "") || lang == LANGUAGE) { style->path = popFirstString(infile.val); style->ptsize = popFirstInt(infile.val); style->blend = toBool(popFirstString(infile.val)); style->ttfont = TTF_OpenFont(mods->locate("fonts/" + style->path).c_str(), style->ptsize); if(style->ttfont == NULL) { logError("FontEngine: TTF_OpenFont: %s", TTF_GetError()); } else { int lineskip = TTF_FontLineSkip(style->ttfont); style->line_height = lineskip; style->font_height = lineskip; } } } } infile.close(); } // set the font colors Color color; if (infile.open("engine/font_colors.txt")) { while (infile.next()) { // @ATTR menu_normal|color|Basic menu text color. Recommended: white. // @ATTR menu_bonus|color|Positive menu text color. Recommended: green. // @ATTR menu_penalty|color|Negative menu text color. Recommended: red. // @ATTR widget_normal|color|Basic widget text color. Recommended: white. // @ATTR widget_disabled|color|Disabled widget text color. Recommended: grey. // @ATTR combat_givedmg|color|Enemy damage text color. Recommended: white. // @ATTR combat_takedmg|color|Player damage text color. Recommended: red. // @ATTR combat_crit|color|Enemy critical damage text color. Recommended: yellow. // @ATTR requirements_no_met|color|Unmet requirements text color. Recommended: red. // @ATTR item_bonus|color|Item bonus text color. Recommended: green. // @ATTR item_penalty|color|Item penalty text color. Recommended: red. // @ATTR item_flavor|color|Item flavor text color. Recommended: grey. color_map[infile.key] = toRGB(infile.val); } infile.close(); } // Attempt to set the default active font setFont("font_regular"); if (!active_font) { logError("FontEngine: Unable to determine default font!"); Exit(1); } }
HSV toHSV(YCbCr ycbcr) { RGB rgb = toRGB(ycbcr); return toHSV(rgb); }
YCbCr toYCbCr(HSV hsv) { RGB rgb = toRGB(hsv); return toYCbCr(rgb); }
bool operator==(const cocos2d::Color3B& a, const cocos2d::extension::HSV& b) { return (a == toRGB (b)); }
void serve_led_request(int client, char *query) { char buf[1024]; int numchars = 1; char *token; char *split; int r = -1; int g = -1; int b = -1; int pattern = 0; int option = 0; buf[0] = 'A'; buf[1] = '\0'; while ((numchars > 0) && strcmp("\n", buf)) /* read & discard headers */ { numchars = get_line(client, buf, sizeof(buf)); } token = strtok(query, "&"); while( token != NULL ) { split=strchr(token,'='); switch(token[0]) { case 'r': r = toRGB(split+1); break; case 'g': g = toRGB(split+1); break; case 'b': b = toRGB(split+1); break; case 'p': pattern = toRGB(split+1); break; case 'o': option = toRGB(split+1); break; } token = strtok(NULL, "&"); } if ( (r == -1 || g == -1 || b == -1) && pattern == 0) { logMessage (LOG_DEBUG,"Received BAD LED query:- Red=%d Green=%d, Blue=%d\n",r,g,b); cannot_execute(client); return; } else { int index = 0; lpd8806worker(&_gpioconfig_.lpd8806cfg[index], (uint8_t*)&pattern, (uint8_t*)&option, (uint8_t*)&r, (uint8_t*)&g, (uint8_t*)&b ); sprintf(buf, "{ \"title\" : \"%s\",\r\n\"name\" : \"%s\",\r\n", _gpioconfig_.name, _gpioconfig_.name); send(client, buf, strlen(buf), 0); sprintf(buf, "\"led\" : {\"r\" : %d, \"g\" : %d, \"b\" : %d, \"p\" : %d}\r\n}\r\n", r,g,b,pattern); /* This one is more accurate and should be used over the above next debug session */ /* sprintf(buf, "\"led\" : {\"name\" : \"%s\", \"r\" : %d, \"g\" : %d, \"b\" : %d, \"p\" : %d}\r\n}\r\n", _gpioconfig_.lpd8806cfg[index].name, _gpioconfig_.lpd8806cfg[index].red, _gpioconfig_.lpd8806cfg[index].green, _gpioconfig_.lpd8806cfg[index].blue, _gpioconfig_.lpd8806cfg[index].pattern);*/ send(client, buf, strlen(buf), 0); } }
inline XYZ::operator rgb() const { return toRGB(); };
//----------------------------------------------------------------------------// RGB_Colour ColourPickerConversions::toRGB(const Lab_Colour& colour) { return toRGB(colour.L, colour.a, colour.b); }
RGB incRGB(iRGB &accum, iRGB delta) { accum = addiRGB(accum, delta); // increment the accum return toRGB(accum); }
int main(int argc, char **argv) { // instantiate a model manager: ModelManager manager("test VRD Boundary Detection"); // Instantiate our various ModelComponents: nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); manager.addSubComponent(ifs); nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager)); manager.addSubComponent(ofs); rutz::shared_ptr<ContourBoundaryDetector> cbd(new ContourBoundaryDetector()); manager.exportOptions(MC_RECURSE); // Parse command-line: if (manager.parseCommandLine(argc, argv, "[window_size] ", 0, 1) == false) return(1); // get the operation mode int r = 8; if(manager.numExtraArgs() > 0) r = manager.getExtraArgAs<uint>(0); // let's do it! manager.start(); ifs->updateNext(); Image<PixRGB<byte> > ima = ifs->readRGB(); // ima = Image<PixRGB<byte> >(ima.getDims(),ZEROS); // drawFilledRect(ima, // Rectangle(Point2D<int>(180, 100), Dims(100, 100)), // PixRGB<byte>(255,0,0)); Image<float> fIma(luminance(ima)); Image<float> tempFIma = fIma; inplaceNormalize(tempFIma, 0.0f,255.0f); Image<byte> bIma(tempFIma); Timer timer(1000000); timer.reset(); cbd->computeContourBoundary(ima,r); Image<float> boundaryMap = cbd->getVarianceRidgeBoundaryMap(); LINFO("time: %f ms", timer.get()/1000.0); // get non-max suppressed boundary map image float mVal = 32; float bVal = 255 - mVal; inplaceNormalize(boundaryMap, 0.0f,bVal); Image<byte> dBmapc(boundaryMap); Image<byte> dImaR, dImaG, dImaB; getComponents(ima, dImaR, dImaG, dImaB); inplaceNormalize(dImaR, byte(0), byte(mVal)); inplaceNormalize(dImaG, byte(0), byte(mVal)); inplaceNormalize(dImaB, byte(0), byte(mVal)); Image<PixRGB<byte> > dBmap = toRGB(dBmapc); Image<PixRGB<byte> > dIma = makeRGB(dImaR,dImaG,dImaB); // the non-max suppressed boundary map image Image<float> dBmapNMStemp = cbd->getNmsBoundaryMap(); inplaceNormalize(dBmapNMStemp, 0.0F, 255.0F); Image<PixRGB<byte> > dBmapNMS = toRGB(Image<byte>(dBmapNMStemp)); // the contour boundary map image Image<float> dCBmapTemp = cbd->getEdgelBoundaryMap(); inplaceNormalize(dCBmapTemp, 0.0F, bVal); Image<PixRGB<byte> > dCBmap = toRGB(Image<byte>(dCBmapTemp)); // setup the display map uint w = ima.getWidth(); uint h = ima.getHeight(); Image<PixRGB<byte> > dispIma(4*w,2*h,ZEROS); inplacePaste(dispIma, ima, Point2D<int>(0,0)); inplacePaste(dispIma, Image<PixRGB<byte> >(dBmap), Point2D<int>(w,0)); //inplacePaste(dispIma, Image<PixRGB<byte> >(dIma+dBmap), Point2D<int>(w,0)); inplacePaste(dispIma, dBmapNMS, Point2D<int>(0,h)); inplacePaste(dispIma, Image<PixRGB<byte> >(dIma+dCBmap), Point2D<int>(w,h)); inplacePaste(dispIma, cbd->getContourBoundaryMap(), Point2D<int>(2*w,0)); // angle at 4th param: 0 degrees //Image<float> gaborImg = getGabor(fIma, 0.0, 2.50, 1.0, 5); // Image<float> gaborImg = getGabor(fIma,0,7,1,9); // -------------- // Image<float> gaborImg = getCanny(fIma); // inplaceNormalize(gaborImg, 0.0F, 255.0F); // Image<PixRGB<byte> > dGaborImg = toRGB(Image<byte>(gaborImg)); // inplacePaste(dispIma, Image<PixRGB<byte> >(dGaborImg), // Point2D<int>(w*2,h)); // Image<float> rDir0 = itsRDirMax[0]; // inplaceNormalize(rDir0, 0.0F, 255.0F); // Image<PixRGB<byte> > dRDir0 = toRGB(Image<byte>(rDir0)); // inplacePaste(dispIma, dRDir0, Point2D<int>(2*w,0)); // Image<float> rDir1 = itsRDirMax[1]; // inplaceNormalize(rDir1, 0.0F, 255.0F); // Image<PixRGB<byte> > dRDir1 = toRGB(Image<byte>(rDir1)); // inplacePaste(dispIma, dRDir1, Point2D<int>(3*w,0)); // Image<float> rDir2 = itsRDirMax[2]; // inplaceNormalize(rDir2, 0.0F, 255.0F); // Image<PixRGB<byte> > dRDir2 = toRGB(Image<byte>(rDir2)); // inplacePaste(dispIma, dRDir2, Point2D<int>(2*w,h)); // Image<float> rDir3 = itsRDirMax[3]; // inplaceNormalize(rDir3, 0.0F, 255.0F); // Image<PixRGB<byte> > dRDir3 = toRGB(Image<byte>(rDir3)); // inplacePaste(dispIma, dRDir3, Point2D<int>(3*w,h)); // 300, 140 /* drawRect(dispIma, Rectangle(Point2D<int>(w+156, 68), Dims(8, 8)), PixRGB<byte>(255,0,0)); drawRect(dispIma, Rectangle(Point2D<int>(w+152, 64), Dims(16, 16)), PixRGB<byte>(255,255,0)); drawRect(dispIma, Rectangle(Point2D<int>(156, h+68), Dims(8, 8)), PixRGB<byte>(255,0,0)); drawRect(dispIma, Rectangle(Point2D<int>(152, h+64), Dims(16, 16)), PixRGB<byte>(255,255,0)); */ //ofs->writeRGB(boundaryMap, "VRD Boundary Detection"); ofs->writeRGB(dispIma, "VRD Boundary Detection"); ofs->updateNext(); Raster::waitForKey(); return 0; }