void testCouleur() { //TODO: un 'if' qui prend la couleur avec le i2c ou analogue dependant du robot //le robot 43 a une pin entre le digital 9 et le Vcc bool estRobot43 = (DIGITALIO_Read(9) == 1); //initialiser le capteur cest important quand on s'appelle robot 43 if(estRobot43) initCapteurI2C(); //ofstream fichier; //fichier.open("couleur.txt"); while(1) { RgbColor readColor; //step 1 if(estRobot43) readColor = getColorI2C(); else readColor = getColorAnalog(); LCD_ClearAndPrint("\nR=%i, G=%i, B=%i", readColor.r, readColor.g, readColor.b); //fichier << "background-color: rgb(" <<readColor.r<<","<<readColor.g<<","<<readColor.b<<")"<< endl; //step 2 HsbColor colorsHSB = RGBtoHSB(readColor); LCD_Printf("\nH=%.4f, S=%.4f, B=%.4f ", colorsHSB.hue, colorsHSB.saturation, colorsHSB.brightness); int laCouleur = currentFloorColor(colorsHSB,estRobot43); LCD_Printf("\n"); switch(laCouleur){ case 0: LCD_Printf("BLANC");break; case 1: LCD_Printf("BLEU");break; case 2: LCD_Printf("ROUGE");break; case 3: LCD_Printf("VERT");break; case 4: LCD_Printf("JAUNE");break; case 5: LCD_Printf("WTF");break; case 6: LCD_Printf("Noir");break; default: LCD_Printf("default");break; } //LCD_Printf("%s",laCouleur.c_str()); /*if(estRobot43) laCouleur = currentFloorColor(colorsHSB);*/ //else //laCouleur = currentFloorColorAnalog(colorsHSB); //LCD_Printf("%s",laCouleur.c_str()); } }
SHSB CRtoHSB( COLORREF rc ) { return RGBtoHSB( CRtoRGB( rc ) ); }
static void dofilter (GimpDrawable *drawable) { gint i, j, k, channels; gint x1, y1, x2, y2; GimpPixelRgn rgn_in, rgn_out; guchar *inrow; guchar *outrow; /* Gets upper left and lower right coordinates, * and layers number in the image */ gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); channels = gimp_drawable_bpp (drawable->drawable_id); /* Initialises two PixelRgns, one to read original data, * and the other to write output data. That second one will * be merged at the end by the call to * gimp_drawable_merge_shadow() */ gimp_pixel_rgn_init (&rgn_in, drawable, x1, y1, x2 - x1, y2 - y1, FALSE, FALSE); gimp_pixel_rgn_init (&rgn_out, drawable, x1, y1, x2 - x1, y2 - y1, TRUE, TRUE); /* Initialise enough memory for inrow, outrow */ inrow = g_new (guchar, channels * (x2 - x1)); outrow = g_new (guchar, channels * (x2 - x1)); /* EXAMPLE USAGE of the functions to get the range */ // guchar minp[4],maxp[4]; // getrange(drawable, minp, maxp, x1, x2, y1, y2); for (i = y1; i < y2; i++) { /* Get row i into inrow array*/ gimp_pixel_rgn_get_row (&rgn_in, inrow, x1, i, x2 - x1); for (j = x1; j < x2; j++) { /* For each layer get the color * pixels */ guchar rgb[4]; for (k = 0; k < 4; k++) { if (k<channels) rgb[k] = inrow[channels * (j - x1) + k]; else rgb[k] = 0; } /* YOUR MAIN CODE HERE : should modify the values inside the rgb array*/ /* EXAMPLE OF CODE : */ float h,s,b; RGBtoHSB (rgb,&h,&s,&b); h=180.0f*(1.0f + cos(h * M_2_PI / 360.0f)); HSBtoRGB(h,s,b,rgb); /* END OF YOUR MAIN CODE HERE */ /* write the new rgb values to the pixels of the outrow */ for (k = 0; k < channels; k++){ outrow[channels * (j - x1) + k] = rgb[k]; } } /*end for j each pixel of the row*/ gimp_pixel_rgn_set_row (&rgn_out, outrow, x1, i, x2 - x1); if (i % 10 == 0) gimp_progress_update ((gdouble) (i - x1) / (gdouble) (x2 - x1)); } /*end for i each row*/ g_free (inrow); g_free (outrow); /* Update the modified region */ gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); gimp_drawable_update (drawable->drawable_id, x1, y1, x2 - x1, y2 - y1); }
/////////////////////////////////////////////////////////////////////////////// // RGB --> HSB /////////////////////////////////////////////////////////////////////////////// unsigned long RGBtoHSB (Color C) { return RGBtoHSB (C.Red(), C.Green(), C.Blue()); }