Exemple #1
0
void solveCommand(field f, location to) {
  location robot[4];
  move moves[100];
  moves->c = 0;
  moves->d = 0;
  for (int i = 1; i <= 4; i++) {
    int r = findColor(f, i);
    if (r<0) {
        printf("could not find robot %d\n", i);
        exit(-1);
    }
    robot[i - 1] = r;
  }
  for (int depth = 1; depth < 20; depth++) {
    if (solve(f, robot, to, depth, moves)) {
      for (move *m = moves + 1; m->d; m++) {
        printf("%d: %s\n%s\n", m->c, prettyDirection(m->d), prettyPrint(f));
        doMove(f, findColor(f, m->c), m->d);
      }
      printf("Final position:\n%s\n", prettyPrint(f));
      break;
    } else {
      printf("No solution at depth %d!\n", depth);
    }
  }
}
 void Scene::multiThreadAntialiasePart(
         std::function<void(int, int, ColorCRef)> paint, std::vector< std::vector <ColorFloat> > &m,
         int level, int taskNo, int taskCount) {
     for (int i = 0; i < 11; i++) {
         for (int x = 1; x + 1 < screen.width; x++) {
             for (int y = 1; y + 1 < screen.height; y++)
                 if (x % 6 + y % 6 == i && x % taskCount == taskNo){
                 int badness = 0;
                 for (int dx : {-1, 1})
                     for (int dy : {-1, 1})
                         badness += (m[x][y] - m[x + dx][y + dy]).norm();
                 if (badness > badnessLimit) {
                     double d = 1.0 / (double)level;
                     ColorFloat sum(0, 0, 0);
                     for (double fx = (double)x - 0.5 + d / 2.0; fx < (double)x + 0.5; fx += d)
                         for (double fy = (double)y - 0.5 + d / 2.0; fy < (double)y + 0.5; fy += d)
                             sum = sum + findColor(
                                     Ray::rayFromAB(spectator, screen.pixelCoordinatesToPoint(fx, fy)),
                                     deflectionRate
                             );
                     paint(x, y, sum * (1.0 / (level * level)));
                 }
             }
         }
     }
 }
Exemple #3
0
bool
ColorList::addColor(const char *color)
{
    assert(_colors.size() > 0);
    assert(_colors.last()->_scale == false);
    return findColor(color);
}
//this is a private worker thread function. Each thread picks the next ungenerated
//row of pixels, generates it, then starts the next one
void MandelbrotViewer::genLine() {

    int iter, row, column;
    sf::Vector2<double> point;
    double x_inc = interpolate(area.width, res_width);
    double y_inc = interpolate(area.height, res_height);
    sf::Color color;

    while(!restart_gen) {

        //the mutex avoids multiple threads writing to variables at the same time,
        //which can corrupt the data
        mutex1.lock();
        row = nextLine++; //get the next ungenerated line
        mutex1.unlock();

        //return when it finishes the last row
        if (row >= res_height) break;

        for (column = 0; column < res_width; column++) {
            iter = escape(row, column);

            //mutex this too so that the image is not accessed multiple times simultaneously
            mutex2.lock();
            image.setPixel(column, row, findColor(iter));
            image_array[row][column] = iter;
            mutex2.unlock();
        }
    }
}
//regenerates the image with the new color multiplier, without regenerating
//the mandelbrot. Does not update the image (use updateImage())
void MandelbrotViewer::changeColor() {
    for (int i=0; i<res_height; i++) {
        for (int j=0; j<res_width; j++) {
            image.setPixel(j, i, findColor(image_array[i][j]));
        }
    }
}
Exemple #6
0
void updateColor(int sq, Display *disp, Window wind, int x, int y, int dx, int dy)
//sq :: 1 - 64. 
{
	XImage *i =
	XGetImage(disp, wind, x, y, dx, dy, AllPlanes, XYPixmap);
	
	int j;
	int k;

	unsigned long findColor();
	unsigned long px;
	unsigned long cl;

	for (j = 0; j < 26; j++){
		for(k = 0; k < 26; k++){	
	
			px = XGetPixel(i, 10 + 2*j, 10 + 2*k);
			cl = findColor(px);
			
			if(cl != 0){
				colArr[sq] = cl;
				XDestroyImage(i);
				return;
			}
		}
	}

	XDestroyImage(i);

	colArr[sq] = UNK;
	return;
}
Exemple #7
0
/* converts a Plus! tag to a Pango markup tag
 * tag must not contains trailing [ and ] */
static char *convert_tag(const char *ptag)
{
	const char *p = ptag;
	char *color = NULL;
	const char *pretag = NULL;
	if(*p == '/') p++;
	if(*p == 'b' || *p == 'B' || *p == 'i' || *p == 'I' || *p == 'u' || *p == 'U' || *p == 's' || *p == 'S')
	{
		return g_strdup_printf("<%s>",ptag);
	}
	else if(*ptag == '/' && (*p == 'c' || *p == 'C' || *p == 'a' || *p == 'A'))
	{
		return g_strdup("</span>");
	}
	if(*++p == '=')
	{
		p++;
		color = findColor(p);
		if(*ptag == 'c' || *ptag == 'C') pretag = "foreground";
		if(*ptag == 'a' || *ptag == 'A') pretag = "background";
		if(pretag) {
			char *tmp = g_strdup_printf("<span %s=\"#%s\">", pretag, color);
			g_free(color);
			return tmp;
		}
	}
	return NULL;
}
Exemple #8
0
Color StyleColor::colorFromKeyword(CSSValueID keyword)
{
    if (const char* valueName = getValueName(keyword)) {
        if (const NamedColor* namedColor = findColor(valueName, strlen(valueName)))
            return Color(namedColor->ARGBValue);
    }
    return RenderTheme::defaultTheme()->systemColor(keyword);
}
Exemple #9
0
void findCommand(field f, color c) {
  int loc = findColor(f, c);
  if (loc < 0) {
    printf("Not Found.\n");
  } else {
    printf("Color %d is at %d\n", c, loc);
  }
}
Exemple #10
0
void Color::setNamedColor(const String& name)
{
    DeprecatedString dname = name.deprecatedString();
    const NamedColor* foundColor = dname.isAllASCII() ? findColor(dname.latin1(), dname.length()) : 0;
    color = foundColor ? foundColor->RGBValue : 0;
    color |= 0xFF000000;
    valid = foundColor;
}
Exemple #11
0
void Process::step()
{
    QTime time;
    time.start();

    switch (mode) {
    case ProcessNone:
        break;

    case ProcessColor:
        findColor();
        findClusters(hitImage, areas);
        transform2DAreas(areas);
        findSeqAreas(areas, seqAreas);
        filterSeqAreas(seqAreas, seqAreasBuffer);
        break;

    case ProcessMotion:
        findMotion();
        findClusters(hitImage, areas);
        transform2DAreas(areas);
        findSeqAreas(areas, seqAreas);
        filterSeqAreas(seqAreas, seqAreasBuffer);
        cvCopy(image, prevImage);
        break;

    case ProcessHaar:
        findHaar();
        findSeqAreas(areas, seqAreas);
        filterSeqAreas(seqAreas, seqAreasBuffer);
        break;

    case ProcessContour:
        findContours();
        findClusters(hitImage, areas);
        transform2DAreas(areas);
        findSeqAreas(areas, seqAreas);
        filterSeqAreas(seqAreas, seqAreasBuffer);
        break;

    case ProcessHoughCircles:
        findHoughCircles();
        findSeqAreas(areas, seqAreas);
        filterSeqAreas(seqAreas, seqAreasBuffer);
        break;

    }

    timeMean += time.elapsed();
    timeNum++;

    if ( timeNum == 10 ) {
        //qDebug() << "Process time:" << timeMean/10;
        timeMean = 0;
        timeNum = 0;
    }

}
Color::Color(const char* name)
{
    if (name[0] == '#')
        m_valid = parseHexColor(&name[1], m_color);
    else {
        const NamedColor* foundColor = findColor(name, strlen(name));
        m_color = foundColor ? foundColor->ARGBValue : 0;
        m_valid = foundColor;
    }
}
Exemple #13
0
Color::Color(const char* name)
{
    if (name[0] == '#')
        valid = parseHexColor(&name[1], color);
    else {
        const NamedColor* foundColor = findColor(name, strlen(name));
        color = foundColor ? foundColor->RGBValue : 0;
        color |= 0xFF000000;
        valid = foundColor;
    }
}
Exemple #14
0
bool
ColorList::addColor(const char *color, double max)
{
    bool result;

    assert(_colors.size() > 0);
    assert(_colors.last()->_scale == true);
    result = findColor(color);
    if (result)
	_colors.last()->_max.append(max);
    return result;
}
    Color Scene::findColor(RayCRef ray, int prior) {
        PARIntersection intersection = findNearestObstacle(ray);

        if (intersection.isNan())
            return Color::nan();
        Color ans = intersection.getBackgroundComponent();
        Point X = intersection.X;
        if (intersection.isLightSourcesImportant()) {
            for (LightSourceCRef ls : lightSources) {
                Ray toLS = Ray::rayFromAB(X, ls);
                PARIntersection obstacle = findNearestObstacle(toLS, toLS.dirLen);
                if (obstacle.isNan()) {
                    double odistLS = 1.0 / toLS.dirLen;
                    Ray deflLight = intersection.getDeflected(toLS);
                    double koefDefl = (intersection.norm * toLS.dir) * pow3(odistLS), cosGla;
                    if (koefDefl < 0.0) {
                        koefDefl = (intersection.refractive > 0 ? -koefDefl : (double)0.0);
                        cosGla = max(0.0, (ray.dir * toLS.dir) / (ray.dirLen * toLS.dirLen));
                    }
                    else {
                        cosGla = max(0.0, (ray.dir * deflLight.dir) / (ray.dirLen * deflLight.dirLen));
                    }
                    //cerr << cosGla << " " << glareCoefficient * sqr(odistLS) << " " << koefDefl <<  endl;
                    ans = ans + intersection.getDispersiveComponent(ls, koefDefl);
                    ans = ans + intersection.getGlareComponent(ls, cosGla, glareCoefficient * sqr(odistLS));
                }
            }
        }
        if (prior > 0 && intersection.deflective > 0) {
            Ray deflRay = intersection.getDeflected();
            Color deflColor = findColor(deflRay, prior - 1);
            ans = ans + intersection.getDeflectiveComponent(deflColor);
        }
        if (prior > 0 && intersection.refractive > 0 && intersection.refractiveIndex > 0) {
            Ray refrRay = intersection.getRefracted();
            Color refrColor = findColor(refrRay, prior - 1);
            ans = ans + intersection.getRefractiveComponent(refrColor);
        }
        return ans;
    }
Exemple #16
0
static inline const NamedColor* findNamedColor(const String& name)
{
    char buffer[64]; // easily big enough for the longest color name
    unsigned length = name.length();
    if (length > sizeof(buffer) - 1)
        return 0;
    for (unsigned i = 0; i < length; ++i) {
        UChar c = name[i];
        if (!c || c > 0x7F)
            return 0;
        buffer[i] = toASCIILower(static_cast<char>(c));
    }
    buffer[length] = '\0';
    return findColor(buffer, length);
}
Exemple #17
0
//--------------------------------------------------------------
int Vision::getOrigami(int obstacleNum){	
    hsb = colorImg;               //now we stuff the colorImg into our HSB image
    hsb.convertRgbToHsv();        //now we convert the colorImg inside colorImgHSV into HSV
    
    hsb.convertToGrayscalePlanarImages(hue, sat, bri); //distribute the hue, saturation and brightness to hueImg, satImg,
    
    colorOrigami = obstacleNum;
    
    switch (colorOrigami) {
        case 1:
            contourBlue = findColor(blueHue);
            break;
        case 2:
            contourRed = findColor(redHue);
            break;
        case 3:
            contourGreen = findColor(greenHue);
            break;
        default:
            break;
    }
    
    return origamiDetection();
}
 void Scene::multiThreadComputePartOfColors(
         std::function<void(int, int, ColorCRef)> paint, int taskNo, int taskCount) {
     cerr << "task No" << taskNo << " started" << endl;
     for (int i = 0; i < 11; i++) {
         for (int x = 0; x < screen.width; x++) {
             for (int y = 0; y < screen.height; y++) {
                 if (x % taskCount == taskNo && x % 6 + y % 6 == i)
                     paint(x, y, findColor(
                             Ray::rayFromAB(spectator, screen.pixelCoordinatesToPoint(x, y)),
                             deflectionRate
                     ));
             }
         }
     }
     cerr << "task No" << taskNo << " finished" << endl;
 }
Exemple #19
0
void GuiColorPickerCtrl::setSelectorPos(const ColorF & color)
{
   if (mBitmap && !mPositionChanged)
   {
      Point2I resolution = getRoot() ? getRoot()->getExtent() : Point2I(1024, 768);
      RectI rect(getGlobalBounds());
      Point2I pos = findColor(color, rect.point, resolution, *mBitmap);
      mSetColor = mSetColor.BLACK;
      mSelectColor = false;

      setSelectorPos(pos);
   }
   else
   {
      mSetColor = color;
      mSelectColor = true;
      mPositionChanged = true;
   }
}
Exemple #20
0
//Uses opengl calls to create the I
void drawI()
{
	//Plot the 5 Different parts of the I
	glColor3f(0, 0, 1);
	
	for(int j = 0; j <= numberTriangleStrips; j++)
        {
            glBegin(GL_TRIANGLE_STRIP);
            for (int i = 0; i <= numberVerticesInStrips; i++)
            {	
		float x = iDoubleVertices[iDoubleTriangleStrips[j][i]][0];
		float y = iDoubleVertices[iDoubleTriangleStrips[j][i]][1];
		// Calculates the offsets used to make the I wiggle and dance
		float offsetx =  (float) (0.1f * sin(dance + 5*y));
                float offsety =  (float) (0.01f * cos(dance + 1*x));

		findColor(x, y);
		glColor3fv(color);		
                glVertex2f(x + offsetx,y + offsety);
            }
            glEnd();
        }
}
Exemple #21
0
void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
{
   if (mStateBlock.isNull())
   {
      GFXStateBlockDesc desc;
      desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);
      desc.setZReadWrite(false);
      desc.zWriteEnable = false;
      desc.setCullMode(GFXCullNone);
      mStateBlock = GFX->createStateBlock(desc);
   }

   RectI boundsRect(offset, getExtent());
   renderColorBox(boundsRect);

   if (mPositionChanged || mBitmap == NULL)
   {
      bool nullBitmap = false;

      if (mPositionChanged == false && mBitmap == NULL)
         nullBitmap = true;

      mPositionChanged = false;
      Point2I extent = getRoot()->getExtent();

      // If we are anything but a pallete, change the pick color
      if (mDisplayMode != pPallet)
      {
         Point2I resolution = getRoot()->getExtent();

         U32 buf_x = offset.x + mSelectorPos.x + 1;
         U32 buf_y = resolution.y - (extent.y - (offset.y + mSelectorPos.y + 1));

         GFXTexHandle bb( resolution.x, resolution.y, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__) );

         Point2I tmpPt(buf_x, buf_y);

         GFXTarget *targ = GFX->getActiveRenderTarget();
         targ->resolveTo(bb);

         if (mBitmap)
         {
            delete mBitmap;
            mBitmap = NULL;
         }

         mBitmap = new GBitmap(bb.getWidth(), bb.getHeight());

         bb.copyToBmp(mBitmap);

         if (!nullBitmap)
         {
            if (mSelectColor)
            {
               Point2I pos = findColor(mSetColor, offset, resolution, *mBitmap);
               mSetColor = mSetColor.BLACK;
               mSelectColor = false;
               setSelectorPos(pos);
            }
            else
            {
               ColorI tmp;
               mBitmap->getColor(buf_x, buf_y, tmp);

               mPickColor = (ColorF)tmp;

               // Now do onAction() if we are allowed
               if (mActionOnMove)
                  onAction();
            }
         }
      }
   }

   //render the children
   renderChildControls(offset, updateRect);
}
Exemple #22
0
static char *plus_nick_changed_cb(PurpleBuddy *buddy)
{
	char * ret = NULL;
	gboolean setting;
	purple_debug_misc("plusblist","Screename is \"%s\", server alias is \"%s\"\n",buddy->name,buddy->server_alias);

	setting = purple_blist_node_get_bool(&buddy->node, "disable_plus");
	if(!setting)
	{
		/* get an escaped version of the alias */
		char *esc, *p;
		GString *buf;
		int gradientIndexFG, gradientIndexBG, ncharsFG, ncharsBG;
		int begColorFG[3], endColorFG[3], deltaColorFG[3];
		int begColorBG[3], endColorBG[3], deltaColorBG[3];
		unsigned char gradientBG, gradientFG, insideTag;

		/* Colorization on alias, if set. */
		if (buddy->alias != NULL)
			esc = g_strdup(buddy->alias);
		else
			esc = g_strdup(buddy->server_alias);

		purple_debug_misc("plusblist","Parsing tags to \"%s\"\n",esc);
		if(!esc) return NULL;	/* oops... */

		gradientBG = gradientFG = insideTag = FALSE;
		ncharsBG = ncharsFG = gradientIndexBG = gradientIndexFG = 0;
		p = esc;

		/* Ciclo di lettura caratteri */
		buf = g_string_new("");
		for (;*p;p = g_utf8_next_char(p)) {
			if (*p == '[') {
				/* Controllo tag */

				/* Faccio un fast forward per cercare il corrispondente ],
				 * determinando quindi se si tratta di un tag oppure no. */
				int i;
				for(i = 1; i < 12; i++) {
					if (p[i] == ']') {
						char *replace;
						char tagCharLowerCase, tagCharUpperCase;
						char gradientTag = FALSE;

						/* Ho trovato la fine del tag, sono dentro! */

						/* Controllo gradiente */

						/* Try to unificate c/a*/
						tagCharLowerCase = tagCharUpperCase = 0;
						if (p[1] == 'c' || p[1] == 'C') {
							tagCharLowerCase = 'c';
							tagCharUpperCase = 'C';
						}
						else if (p[1] == 'a' || p[1] == 'A') {
							tagCharLowerCase = 'a';
							tagCharUpperCase = 'A';
						}
						else if (p[1] == 'b' || p[1] == 'B' || p[1] == 'i' || p[1] == 'I' ||
							p[1] == 'u' || p[1] == 'U' || p[1] == 's' || p[1] == 'S' || p[1] == '/') {
							/* sarebbe carino fargli skippare la parte di controllo gradiente */
						}
						else {
							break;
						}
						insideTag = TRUE;

						if ((p[1] == tagCharLowerCase || p[1] == tagCharUpperCase) && p[2] == '=') {
							gchar *iter = p + i + 1;
							char insideTagFastForward = FALSE;
							int fastForwardCharCounter = 0;

							if (tagCharLowerCase == 'c') {
								gradientFG = FALSE; /* TODO: necessario? */
								ncharsFG = 0;
							}
							else {
								gradientBG = FALSE; /* TODO: necessario? */
								ncharsBG = 0;
							}

							/* Vado avanti e cerco il finale corrispondente */
							for (;*iter;iter = g_utf8_next_char(iter)) {

								if (iter[0] == '[' && iter[1] == '/' &&
									(iter[2] == tagCharLowerCase || iter[2] == tagCharUpperCase)
								) {
									purple_debug_misc("plusblist", "Gradient end found.\n");
									if (iter[3] == '=') {
										char *initialColor, *finalColor;
										int j;

										gradientTag = TRUE;
										/*  */
										initialColor = findColor(p + 3);
										finalColor = findColor(iter + 4);
										if (!initialColor || !finalColor) break;

										purple_debug_misc("plusblist", "Beginning color: %s\n", initialColor);

										for (j = 0;j <= 2;j++) {
											if (tagCharLowerCase == 'c') {
												begColorFG[j] = hexDec(initialColor + 2 * j, 2);
												endColorFG[j] = hexDec(finalColor + 2 * j, 2);
												deltaColorFG[j] = endColorFG[j] - begColorFG[j];
											}
											else {
												begColorBG[j] = hexDec(initialColor + 2 * j, 2);
												endColorBG[j] = hexDec(finalColor + 2 * j, 2);
												deltaColorBG[j] = endColorBG[j] - begColorBG[j];
											}
										}

										purple_debug_misc("plusblist", "Ending color: %s\n", finalColor);
										g_free(initialColor);
										g_free(finalColor);

										if (tagCharLowerCase == 'c') {
											gradientFG = TRUE;
											gradientIndexFG = 0;
											purple_debug_misc("plusblist", "Number of chars inside the gradient: %i\n", ncharsFG);
										}
										else {
											gradientBG = TRUE;
											gradientIndexBG = 0;
											purple_debug_misc("plusblist", "Number of chars inside the gradient: %i\n", ncharsBG);
										}
										/* Calcolare il numero di caratteri effettivi (escludendo i tag),
										 * e suddividere il Delta R, G, B diviso il numero di caratteri,
										 * ottenendo l'incremento da aggiungere (o sottrarre)
										 * ad ogni carattere.
										 * Subito PRIMA dell'ultimo carattere, mettere il colore finale.
										 */
									}
									break;
								}
								else {
									if (tagCharLowerCase == 'c') ncharsFG++;
									else ncharsBG++;

								}

								if (iter[0] == '[') {
									/* sono FORSE all'interno di un tag*/
									if (iter[1] == 'b' || iter[1] == 'B' ||
										iter[1] == 'i' || iter[1] == 'I' ||
										iter[1] == 'u' || iter[1] == 'U' ||
										iter[1] == 's' || iter[1] == 'S' ||
										iter[1] == 'a' || iter[1] == 'A' ||
										iter[1] == 'c' || iter[1] == 'C' ||
										iter[1] == '/') {
											insideTagFastForward = TRUE; /* TODO: non e' vero, limite massimo caratteri */
											fastForwardCharCounter = 0;
									}
								}
								else if (iter[0] == ']' && insideTagFastForward) {
									/* ero all'interno di un tag ed ora l'ho chiuso */
									insideTagFastForward = FALSE;
									if (tagCharLowerCase == 'c')
										ncharsFG -= (fastForwardCharCounter + 2); /* 2 = squares []*/
									else
										ncharsBG -=  (fastForwardCharCounter + 2); /* 2 = squares []*/
								}
								else if (insideTagFastForward) {
									fastForwardCharCounter++;
								}

							}
						} /* fine controllo gradiente */

						/* Non devo tradurre il tag di fine gradiente: */
						if (p[1] == '/' && p[3] == '=') {
							gradientTag = TRUE;
							if (tagCharLowerCase == 'c')
								gradientFG = FALSE;
							else if (tagCharLowerCase == 'a')
								gradientBG = FALSE;
						}

						/* Tag convertito ed aggiunto solo se non sono in un gradiente.
						 * Infatti in questo caso viene gestito dopo. */
						if (!gradientTag) {
							purple_debug_misc("plusblist", "Translating tag %s\n", g_strndup(p + 1, i - 1));
							replace = convert_tag(g_strndup(p + 1, i - 1));
							if (replace) {
								g_string_append(buf, replace);
							}
							g_free(replace);
						}
						break; /* Ne ho trovata una, non cerco le seguenti. */
					} /* Fine if p = ] */
				} /* Fine ciclo for per cercare la fine del tag ] */





			}
			else if (*p == ']' && insideTag) {
				insideTag = FALSE;
				continue;
			}

			if (!insideTag) {
				/* Get the next character (using utf-8) */
				gchar *thischar_unescaped, *thischar;
				thischar_unescaped = g_new0(char, 10);
				g_utf8_strncpy(thischar_unescaped, p, 1);
				thischar = g_markup_escape_text(thischar_unescaped, -1);
				g_free(thischar_unescaped);

				if (gradientFG || gradientBG) {
					/* Aggiungo i caratteri colorati del gradiente */

					int j;
					int color[3];
					char *tag, *fgAttribute = NULL, *bgAttribute = NULL;
					if (gradientFG) {
						for (j = 0; j <= 2; j++) {
							int delta = 0;
							if (ncharsFG > 1)
								delta = deltaColorFG[j] * gradientIndexFG / (ncharsFG - 1);
							color[j] = begColorFG[j] + delta;
						}
						fgAttribute = g_strdup_printf(" foreground=\"#%02x%02x%02x\"", color[0], color[1], color[2]);
					}
					else fgAttribute = g_strdup("");

					if (gradientBG) {
						for (j = 0; j <= 2; j++) {
							int delta = 0;
							if (ncharsBG > 1)
								delta = deltaColorBG[j] * gradientIndexBG / (ncharsBG - 1);
							color[j] = begColorBG[j] + delta;
						}
						bgAttribute = g_strdup_printf(" background=\"#%02x%02x%02x\"", color[0], color[1], color[2]);
					}
					else bgAttribute = g_strdup("");

					tag = g_strdup_printf("<span%s%s>%s</span>", fgAttribute, bgAttribute, thischar);
					g_free(fgAttribute);
					g_free(bgAttribute);

					g_string_append(buf, tag);
					g_free(tag);
					if (gradientFG) gradientIndexFG++;
					if (gradientBG) gradientIndexBG++;
					if (gradientIndexFG >= ncharsFG) gradientFG = FALSE;
					if (gradientIndexBG >= ncharsBG) gradientBG = FALSE;
				}
				else {
					/* Carattere normale, senza essere in un gradiente */
					g_string_append(buf, thischar);
				}
				g_free(thischar);
			}
		}
Exemple #23
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
unsigned char* createTriangle(size_t width, size_t height)
{
  unsigned char* arr = BYTARR(RGB_NUM_COMP, width, height);
  float indexConst1 = 0.414 / width;
  float indexConst2 = 0.207 / width;
  float tslConst1 = (90.0f * MXA_PI) / 180.0f;
 // size_t index = 0;
  float temp = 0.0f;
  float red1 = 0.0f;
  float green1 = 0.0f;
  float blue1 = 0.0f;
  float red2 = 0.0f;
  float green2 = 0.0f;
  float blue2 = 0.0f;
  float x = 0.0f;
  float y = 0.0f;
  float z = 0.0f;
  float a = 0.0f;
  float b = 0.0f;
  float c = 0.0f;
  float check1 = 0.0f;
  float check2 = 0.0f;
  float val = 0.0f;
  float x1 = 0.0f;
  float y1 = 0.0f;
  float z1 = 0.0f;
  float denom = 0.0f;
  float phi = 0.0f;
  float x1alt = 0.0f;
  float theta = 0.0f;

  for (size_t yIndex = 0; yIndex < width; ++yIndex)
  {
    for (size_t xIndex = 0; xIndex < height; ++xIndex)
    {

      temp = 0;
      red1 = 0;
      green1 = 0;
      blue1 = 0;
      red2 = 0;
      green2 = 0;
      blue2 = 0;
      x = xIndex * indexConst1 + indexConst2;
      y = yIndex * indexConst1 + indexConst2;
      z = -1.0;
      a = (x * x + y * y + 1);
      b = (2 * x * x + 2 * y * y);
      c = (x * x + y * y - 1);
      check1 = b * b;
      check2 = 4 * a * c;
      val = (-b + sqrtf(b * b - 4 * a * c)) / (2 * a);
      x1 = (1 + val) * x;
      y1 = (1 + val) * y;
      z1 = val;
      denom = (x1 * x1) + (y1 * y1) + (z1 * z1);
      denom = sqrtf(denom);
      x1 = x1 / denom;
      y1 = y1 / denom;
      z1 = z1 / denom;

      red1 = x1 * (-0.707f) + z1 * 0.707f;
      phi = acos(red1);
      x1alt = x1 / 0.707;
      x1alt = x1alt / sqrt((x1alt * x1alt) + (y1 * y1));
      // float check = cos((tslConst1)-phi);
      theta = acos(x1alt / cos((tslConst1) - phi));
      theta = acos(x1alt);
      size_t index = (yIndex * width * RGB_NUM_COMP) + xIndex * RGB_NUM_COMP;

      if (phi LT (45 * 3.1415926535897 / 180.0) OR
          phi GT (90 * 3.1415926535897 / 180.0) OR
          theta GT (35.26 * 3.1415926535897 / 180.0))
      {
        arr[index] = 255;
        arr[index + 1] = 255;
        arr[index + 2] = 255;
      }
      else
      {
        findColor(x1, y1, z1, &(arr[index]));
      }

    }
  }

  return arr;

}
Exemple #24
0
void LEDS::setFirstColor(byte firstColorKey)
{
    Color1 = findColor(firstColorKey);

}
Exemple #25
0
void LEDS::setSecondColor(byte secondColorKey)
{
    Color2 =  findColor(secondColorKey);

}
Exemple #26
0
int main(int argc, char *argv[]) {
    char *p = argv[1];

    int gradientIndexFG, gradientIndexBG, ncharsFG, ncharsBG;
    int begColorFG[3], endColorFG[3], deltaColorFG[3];
    int begColorBG[3], endColorBG[3], deltaColorBG[3];
    unsigned char gradientBG = FALSE, gradientFG = FALSE, insideTag = FALSE;

    /* Ciclo di lettura caratteri */
    GString *buf = g_string_new("");
    for (; *p; p = g_utf8_next_char(p)) {
#ifdef PLUS_DEBUG
        // printf("Leggo il carattere %c\n", *p);
#endif
        if (*p == '[') {
            /* Controllo tag */

            /* Faccio un fast forward per cercare il corrispondente ],
             * determinando quindi se si tratta di un tag oppure no. */
            int i;
            for(i = 1; i < 12; i++) {
                if (p[i] == ']') {
                    char *replace;
                    char gradientTag = FALSE;

                    /* Ho trovato la fine del tag, sono dentro! */
#ifdef PLUS_DEBUG
                    printf("Primo carattere del tag: %c\n", p[1]);
#endif
                    /* Controllo gradiente */

                    /* Try to unificate c/a*/
                    char tagCharLowerCase = 0, tagCharUpperCase = 0;
                    if (p[1] == 'c' || p[1] == 'C') {
                        tagCharLowerCase = 'c';
                        tagCharUpperCase = 'C';
                    }
                    else if (p[1] == 'a' || p[1] == 'A') {
                        tagCharLowerCase = 'a';
                        tagCharUpperCase = 'A';
                    }
                    else if (p[1] == 'b' || p[1] == 'B' || p[1] == 'i' || p[1] == 'I' ||
                             p[1] == 'u' || p[1] == 'U' || p[1] == 's' || p[1] == 'S' || p[1] == '/') {
                        /* sarebbe carino fargli skippare la parte di controllo gradiente */
                    }
                    else {
                        break;
                    }
                    insideTag = TRUE;


                    if ((p[1] == tagCharLowerCase || p[1] == tagCharUpperCase) && p[2] == '=') {
                        gchar *iter = p + i + 1;
                        char insideTagFastForward = FALSE;
                        int fastForwardCharCounter = 0;
#ifdef PLUS_DEBUG
                        printf("Controllo gradienti.\n");
#endif
                        if (tagCharLowerCase == 'c') {
                            gradientFG = FALSE; /* TODO: necessario? */
                            ncharsFG = 0;
                        }
                        else {
                            gradientBG = FALSE; /* TODO: necessario? */
                            ncharsBG = 0;
                        }

                        /* Vado avanti e cerco il finale corrispondente */
                        for (; *iter; iter = g_utf8_next_char(iter)) {

                            if (iter[0] == '[' && iter[1] == '/' &&
                                    (iter[2] == tagCharLowerCase || iter[2] == tagCharUpperCase)
                               ) {
#ifdef PLUS_DEBUG
                                printf("ho trovato un finale\n");
#endif
                                if (iter[3] == '=') {
                                    gradientTag = TRUE;
                                    /*  */
                                    char *initialColor = findColor(p + 3);
                                    char *finalColor = findColor(iter + 4);
                                    if (!initialColor || !finalColor) break;

#ifdef PLUS_DEBUG
                                    printf("Colore iniziale: %s\n", initialColor);
#endif
                                    int j;
                                    for (j = 0; j <= 2; j++) {
                                        if (tagCharLowerCase == 'c') {
                                            begColorFG[j] = hexDec(initialColor + 2 * j, 2);
                                            endColorFG[j] = hexDec(finalColor + 2 * j, 2);
                                            deltaColorFG[j] = endColorFG[j] - begColorFG[j];
                                        }
                                        else {
                                            begColorBG[j] = hexDec(initialColor + 2 * j, 2);
                                            endColorBG[j] = hexDec(finalColor + 2 * j, 2);
                                            deltaColorBG[j] = endColorBG[j] - begColorBG[j];
                                        }
                                    }

#ifdef PLUS_DEBUG
                                    printf("Colore finale: %s\n", finalColor);
#endif
                                    g_free(initialColor);
                                    g_free(finalColor);

                                    if (tagCharLowerCase == 'c') {
                                        gradientFG = TRUE;
                                        gradientIndexFG = 0;
#ifdef PLUS_DEBUG
                                        printf("numero caratteri: %i\n", ncharsFG);
#endif
                                    }
                                    else {
                                        gradientBG = TRUE;
                                        gradientIndexBG = 0;
#ifdef PLUS_DEBUG
                                        printf("numero caratteri: %i\n", ncharsBG);
#endif
                                    }
                                    // Calcolare il numero di caratteri effettivi (escludendo i tag),
                                    // e suddividere il Delta R, G, B diviso il numero di caratteri,
                                    // ottenendo l'incremento da aggiungere (o sottrarre)
                                    // ad ogni carattere.
                                    // Subito PRIMA dell'ultimo carattere, mettere il colore finale.


#ifdef PLUS_DEBUG
                                    printf("gradiente\n");
#endif
                                }
                                else {
#ifdef PLUS_DEBUG
                                    printf("non gradiente\n");
#endif
                                }
                                break;
                            }
                            else {
                                if (tagCharLowerCase == 'c') ncharsFG++; // TODO: devono essere effettivi, non cosi'.
                                else ncharsBG++;
                            }

                            if (iter[0] == '[') {
                                /* sono FORSE all'interno di un tag*/
                                if (iter[1] == 'b' || iter[1] == 'B' ||
                                        iter[1] == 'i' || iter[1] == 'I' ||
                                        iter[1] == 'u' || iter[1] == 'U' ||
                                        iter[1] == 's' || iter[1] == 'S' ||
                                        iter[1] == 'a' || iter[1] == 'A' ||
                                        iter[1] == 'c' || iter[1] == 'C' ||
                                        iter[1] == '/') {
                                    insideTagFastForward = TRUE; /* TODO: non e' vero, limite massimo caratteri */
                                    fastForwardCharCounter = 0;
                                }
                            }
                            else if (iter[0] == ']' && insideTagFastForward) {
                                /* ero all'interno di un tag ed ora l'ho chiuso */
                                insideTagFastForward = FALSE;
                                if (tagCharLowerCase == 'c')
                                    ncharsFG -= (fastForwardCharCounter + 2); /* 2 = squares []*/
                                else
                                    ncharsBG -=  (fastForwardCharCounter + 2); /* 2 = squares []*/
                            }
                            else if (insideTagFastForward) {
                                fastForwardCharCounter++;
                            }

                        }
                    } /* fine controllo gradiente */

                    /* Non devo tradurre il tag di fine gradiente: */
                    if (p[1] == '/' && p[3] == '=') {
                        gradientTag = TRUE;
                        if (tagCharLowerCase == 'c')
                            gradientFG = FALSE;
                        else if (tagCharLowerCase == 'a')
                            gradientBG = FALSE;
                    }

                    /* Tag convertito ed aggiunto solo se non sono in un gradiente.
                     * Infatti in questo caso viene gestito dopo. */
                    if (!gradientTag) {
#ifdef PLUS_DEBUG
                        printf("Provo il tag %s\n", g_strndup(p + 1, i - 1));
#endif
                        replace = convert_tag(g_strndup(p + 1, i - 1));
                        if (replace) {
                            g_string_append(buf, replace);
                        }
                        g_free(replace);
                    }
                    break; /* Ne ho trovata una, non cerco le seguenti. */
                } /* Fine if p = ] */
            } /* Fine ciclo for per cercare la fine del tag ] */





        }
        else if (*p == ']' && insideTag) {
            insideTag = FALSE;
            continue;
        }

        if (!insideTag) {
            gchar *thischar_unescaped, *thischar;
            thischar_unescaped = g_new0(char, 10);
            g_utf8_strncpy(thischar_unescaped, p, 1);
            thischar = g_markup_escape_text(thischar_unescaped, -1);
            g_free(thischar_unescaped);

            if (gradientFG || gradientBG) {
                /* Aggiungo i caratteri colorati del gradiente */

                int j;
                int color[3];
                char *tag, *fgAttribute = NULL, *bgAttribute = NULL;
                if (gradientFG) {
                    for (j = 0; j <= 2; j++) {
                        int delta = 0;
                        if (ncharsFG > 1)
                            delta = deltaColorFG[j] * gradientIndexFG / (ncharsFG - 1);
                        color[j] = begColorFG[j] + delta;
#ifdef PLUS_DEBUG
//					printf("Deltacolor: %i; delta=%i; color[%i]=%i\n", deltaColor[j], delta, j, color[j]);
//					printf("delta[%i] = %i\n", j, delta);
#endif
                    }
                    fgAttribute = g_strdup_printf(" foreground=\"#%02x%02x%02x\"", color[0], color[1], color[2]);
                }
                else fgAttribute = g_strdup("");

                if (gradientBG) {
                    for (j = 0; j <= 2; j++) {
                        int delta = 0;
                        if (ncharsBG > 1)
                            delta = deltaColorBG[j] * gradientIndexBG / (ncharsBG - 1);
                        color[j] = begColorBG[j] + delta;
#ifdef PLUS_DEBUG
//					printf("Deltacolor: %i; delta=%i; color[%i]=%i\n", deltaColor[j], delta, j, color[j]);
//					printf("delta[%i] = %i\n", j, delta);
#endif
                    }
                    bgAttribute = g_strdup_printf(" background=\"#%02x%02x%02x\"", color[0], color[1], color[2]);
                }
                else bgAttribute = g_strdup("");
#ifdef PLUS_DEBUG
                // printf("%s\n", g_utf8_offset_to_pointer(p, 2));
#endif

                tag = g_strdup_printf("<span%s%s>%s</span>", fgAttribute, bgAttribute, thischar);

                g_free(fgAttribute);
                g_free(bgAttribute);

                g_string_append(buf, tag);
                g_free(tag);
                if (gradientFG) gradientIndexFG++;
                if (gradientBG) gradientIndexBG++;
                if (gradientIndexFG >= ncharsFG) gradientFG = FALSE;
                if (gradientIndexBG >= ncharsBG) gradientBG = FALSE;
            }
            else {
                /* Carattere normale, senza essere in un gradiente */
                g_string_append(buf, thischar);
            }
            g_free(thischar);
        }
    }
Exemple #27
0
int main(int argc, char **argv)
{
  google::SetUsageMessage("dense --help");
  google::SetVersionString("1.0.0");
  google::ParseCommandLineFlags(&argc, &argv, true);
  
  int maxCorners = 10000;
  double qualityLevel = 0.03;
  double minDistance = 2;
  std::vector<cv::Mat> all_images;
  std::vector<cv::Mat> all_gray_images;
  std::vector<camera_frame_wo_image> camera_frame_wo_images;

  nvm_file input(FLAGS_nvm_file);
  all_images.resize(input.kf_data.size());
  all_gray_images.resize(input.kf_data.size());
  camera_frame_wo_images.resize(input.kf_data.size());
  // TODO: Add distortion parameters
  for (int i=0; i<all_images.size(); i++) {
    std::cerr << FLAGS_data_dir + "/" + input.kf_data[i].filename << "\n";
    all_images[i] = cv::imread(FLAGS_data_dir + "/" + input.kf_data[i].filename);
    cv::cvtColor(all_images[i], all_gray_images[i], CV_RGBA2GRAY);
    camera_frame_wo_images[i] = camera_frame_wo_image(
      input.kf_data[i].focal, 
      input.kf_data[i].rotation, 
      input.kf_data[i].translation,
      all_images[i].cols/2, all_images[i].rows/2);
  }
  // input.corr_data.clear();
  cv::Point2f center(all_images[0].cols/2, all_images[0].rows/2);
  
  // for (int i=0; i<input.kf_data.size()-FLAGS_windows; i++) {
  for (int i=0; i<1; i++) {
    // Get good points in img i
    std::vector<cv::Point2f> corners;
    cv::goodFeaturesToTrack(all_gray_images[i], corners, maxCorners, qualityLevel, minDistance);
    std::cout << "Found " << corners.size() << "\n"; 
    int c1= 0; 
    for (auto pt: corners) {
      std::cout << c1 << "\n";
      c1++;
      std::vector<triangulation_bundle> to_triangulate;
      // Get correspondances in img i+1 and i+2 ...
      to_triangulate.push_back(triangulation_bundle(camera_frame_wo_images[i], 
          makeCenterSubtracted(pt, center)));
      cv::Point2f location; 
      for (int j=i+1; j<i + FLAGS_windows; j++) {
        if (findPoint(pt, all_images[i], all_images[j], camera_frame_wo_images[i], camera_frame_wo_images[j], location)) {
          to_triangulate.push_back(triangulation_bundle(camera_frame_wo_images[j],
            makeCenterSubtracted(location, center)));
        }
      }
      // Triangulate
      if (to_triangulate.size()>2) {
        cv::Point3f final3d = Triangulate(to_triangulate);

        // Add to input 3D cloud
        input.corr_data.push_back(Corr3D(final3d, findColor(all_images[i], pt)));  
      }
    }
  }

  input.save_to_disk(FLAGS_output_file);
  input.save_ply_file(FLAGS_output_ply);
  return 0;
}