std_msgs::ColorRGBA VisualizeDetectedObjects::ParseColor(const std::vector<double> &in_color) { std_msgs::ColorRGBA color; float r,g,b,a; if (in_color.size() == 4) //r,g,b,a { color.r = CheckColor(in_color[0]); color.g = CheckColor(in_color[1]); color.b = CheckColor(in_color[2]); color.a = CheckAlpha(in_color[3]); } return color; }
int main(int argc, string argv[]){ /* Check if a proper keyword is provided */ if (argc != 2 ) { printf("Please indicate a proper keyword\n"); return 1; }else if (CheckAlpha(argv[1]) == 1) { printf("Keyword can only contain letters\n"); return 1; } string keyword = argv[1]; // convert the keyword to a numeric array int len = strlen(keyword); int numberkey[len]; for (int i=0; i<len; i++){ if (isupper(keyword[i])){ numberkey[i] = (int) keyword[i] - 65; }else if(islower(keyword[i])){ numberkey[i] = (int) keyword[i] - 97; } } // start interate the text string text = GetString(); int textlen = strlen(text); int l=-1; // l is used to track where we are in the plaintext excluding the non-characters for (int i=0; i < textlen; i++){ //check if letter is non-alphabet, if it is non-character, printout if (!isalpha(text[i])){ printf("%c", text[i]); }else{ l++; int local_k = numberkey[l%len]; printf("%c", (char) shiftLetter(text[i], local_k)); } } printf("\n"); return 0; }
bool ImageJngFile::Load (uint8 *iBuffer, size_t iSize) { mng_retcode retcode; const int magicSize = 8; const char magicMNG[] = "\x8aMNG\x0d\x0a\x1a\x0a"; const char magicJNG[] = "\x8bJNG\x0d\x0a\x1a\x0a"; // check for magic JNG/MNG bytes. If not correct, we can skip // messing around w/ libmng entirely. if ((iSize < 8) || ((memcmp ((void*)iBuffer, (void*)&magicMNG, magicSize)) && (memcmp ((void*)iBuffer, (void*)&magicJNG, magicSize)))) { return false; } handle = mng_initialize (mng_ptr(this), cb_alloc, cb_free, MNG_NULL); if (!handle) { Report (object_reg, CS_REPORTER_SEVERITY_WARNING, "failed to initialize libmng"); return false; } buffer = iBuffer; bufptr = buffer; bufferSize = iSize; if ((mng_setcb_openstream (handle, cb_openstream) != MNG_NOERROR) || (mng_setcb_closestream (handle, cb_closestream) != MNG_NOERROR) || (mng_setcb_readdata (handle, cb_readdata) != MNG_NOERROR) || (mng_setcb_processheader(handle, cb_processheader) != MNG_NOERROR) || (mng_setcb_getcanvasline(handle, cb_getcanvasline) != MNG_NOERROR) || (mng_setcb_refresh(handle, cb_imagerefresh) != MNG_NOERROR) || (mng_setcb_gettickcount(handle, cb_gettickcount) != MNG_NOERROR) || (mng_setcb_settimer(handle, cb_settimer) != MNG_NOERROR)) { ReportLibmngError (object_reg, handle, "failed to set libmng callbacks"); mng_cleanup (&handle); return false; } retcode = mng_read (handle); if (retcode != MNG_NOERROR) { if (retcode != MNG_INVALIDSIG) // maybe its just not an jng/mng... ReportLibmngError (object_reg, handle, "failed to read data"); mng_cleanup (&handle); return false; } // Don't read PNGs if (mng_get_sigtype (handle) == mng_it_png) { delete[] NewImage; mng_cleanup (&handle); return false; } // Even on still images, libmng issues timer requests. // so, as long as the requests are 'immediate' we continue // displaying. If a delay is requested we end loading. timer = 2; retcode = mng_display (handle); while ((retcode == MNG_NEEDTIMERWAIT) && (timer <= 1)) { retcode = mng_display_resume (handle); } if ((retcode != MNG_NOERROR) && (retcode != MNG_NEEDTIMERWAIT)) { ReportLibmngError (object_reg, handle, "failed to display data"); mng_cleanup (&handle); return false; } doWait = (retcode == MNG_NEEDTIMERWAIT); animated = doWait; if (NewImage) { csRGBpixel *rgbImage = csPackRGBA::CopyUnpackRGBAtoRGBpixel (NewImage, Width*Height); ConvertFromRGBA (rgbImage); // Subsequent images may contain alpha, so don't check if (!doWait) CheckAlpha(); } if (mng_get_sigtype (handle) != mng_it_mng) { delete[] NewImage; NewImage = 0; mng_cleanup (&handle); handle = 0; } return true; }
SEXP do_rgb(SEXP call, SEXP op, SEXP args, SEXP env) { SEXP c, r, g, b, a, nam; int OP, i, l_max, nr, ng, nb, na; Rboolean max_1 = FALSE; double mV = 0.0; /* -Wall */ checkArity(op, args); OP = PRIMVAL(op); if(OP) {/* op == 1: rgb256() :*/ PROTECT(r = coerceVector(CAR(args), INTSXP)); args = CDR(args); PROTECT(g = coerceVector(CAR(args), INTSXP)); args = CDR(args); PROTECT(b = coerceVector(CAR(args), INTSXP)); args = CDR(args); PROTECT(a = coerceVector(CAR(args), INTSXP)); args = CDR(args); } else { PROTECT(r = coerceVector(CAR(args), REALSXP)); args = CDR(args); PROTECT(g = coerceVector(CAR(args), REALSXP)); args = CDR(args); PROTECT(b = coerceVector(CAR(args), REALSXP)); args = CDR(args); PROTECT(a = coerceVector(CAR(args), REALSXP)); args = CDR(args); mV = asReal(CAR(args)); args = CDR(args); max_1 = (mV == 1.); } nr = LENGTH(r); ng = LENGTH(g); nb = LENGTH(b); na = LENGTH(a); if (nr <= 0 || ng <= 0 || nb <= 0 || na <= 0) { UNPROTECT(4); return(allocVector(STRSXP, 0)); } l_max = nr; if (l_max < ng) l_max = ng; if (l_max < nb) l_max = nb; if (l_max < na) l_max = na; PROTECT(nam = coerceVector(CAR(args), STRSXP)); args = CDR(args); if (length(nam) != 0 && length(nam) != l_max) errorcall(call, _("invalid names vector")); PROTECT(c = allocVector(STRSXP, l_max)); #define _R_set_c_RGBA(_R,_G,_B,_A) \ for (i = 0; i < l_max; i++) \ SET_STRING_ELT(c, i, mkChar(RGBA2rgb(_R,_G,_B,_A))) if(OP) { /* OP == 1: rgb256() :*/ _R_set_c_RGBA(CheckColor(INTEGER(r)[i%nr]), CheckColor(INTEGER(g)[i%ng]), CheckColor(INTEGER(b)[i%nb]), CheckAlpha(INTEGER(a)[i%na])); } else if(max_1) { _R_set_c_RGBA(ScaleColor(REAL(r)[i%nr]), ScaleColor(REAL(g)[i%ng]), ScaleColor(REAL(b)[i%nb]), ScaleAlpha(REAL(a)[i%na])); } else { /* maxColorVal not in {1, 255} */ _R_set_c_RGBA(ScaleColor(REAL(r)[i%nr] / mV), ScaleColor(REAL(g)[i%ng] / mV), ScaleColor(REAL(b)[i%nb] / mV), ScaleAlpha(REAL(a)[i%na] / mV)); } if (length(nam) != 0) setAttrib(c, R_NamesSymbol, nam); UNPROTECT(6); return c; }