Beispiel #1
0
TEST_F(StyleEngineTest, AnalyzedInject) {
  document().body()->setInnerHTML(
      "<style>div { color: red }</style><div id='t1'>Green</div><div></div>");
  document().view()->updateAllLifecyclePhases();

  Element* t1 = document().getElementById("t1");
  ASSERT_TRUE(t1);
  ASSERT_TRUE(t1->computedStyle());
  EXPECT_EQ(makeRGB(255, 0, 0),
            t1->computedStyle()->visitedDependentColor(CSSPropertyColor));

  unsigned beforeCount = styleEngine().styleForElementCount();

  StyleSheetContents* parsedSheet =
      StyleSheetContents::create(CSSParserContext(document(), nullptr));
  parsedSheet->parseString("#t1 { color: green }");
  styleEngine().injectAuthorSheet(parsedSheet);
  document().view()->updateAllLifecyclePhases();

  unsigned afterCount = styleEngine().styleForElementCount();
  EXPECT_EQ(1u, afterCount - beforeCount);

  ASSERT_TRUE(t1->computedStyle());
  EXPECT_EQ(makeRGB(0, 128, 0),
            t1->computedStyle()->visitedDependentColor(CSSPropertyColor));
}
Beispiel #2
0
TEST_F(StyleEngineTest, StyleMediaAttributeNoStyleChange) {
  document().body()->setInnerHTML(
      "<style id='s1' media='(max-width: 1000px)'>#t1 { color: green }</style>"
      "<div id='t1'>Green</div><div></div>");
  document().view()->updateAllLifecyclePhases();

  Element* t1 = document().getElementById("t1");
  ASSERT_TRUE(t1);
  ASSERT_TRUE(t1->computedStyle());
  EXPECT_EQ(makeRGB(0, 128, 0),
            t1->computedStyle()->visitedDependentColor(CSSPropertyColor));

  unsigned beforeCount = styleEngine().styleForElementCount();

  Element* s1 = document().getElementById("s1");
  s1->setAttribute(blink::HTMLNames::mediaAttr, "(max-width: 2000px)");
  document().view()->updateAllLifecyclePhases();

  unsigned afterCount = styleEngine().styleForElementCount();
  // TODO([email protected]): Should be 0 for ruleset based invalidations.
  EXPECT_EQ(8u, afterCount - beforeCount);

  ASSERT_TRUE(t1->computedStyle());
  EXPECT_EQ(makeRGB(0, 128, 0),
            t1->computedStyle()->visitedDependentColor(CSSPropertyColor));
}
static RGBA32 parseColorStringWithCrazyLegacyRules(const String& colorString)
{
    // Per spec, only look at the first 128 digits of the string.
    const size_t maxColorLength = 128;
    // We'll pad the buffer with two extra 0s later, so reserve two more than the max.
    Vector<char, maxColorLength+2> digitBuffer;

    size_t i = 0;
    // Skip a leading #.
    if (colorString[0] == '#')
        i = 1;

    // Grab the first 128 characters, replacing non-hex characters with 0.
    // Non-BMP characters are replaced with "00" due to them appearing as two "characters" in the String.
    for (; i < colorString.length() && digitBuffer.size() < maxColorLength; i++) {
        if (!isASCIIHexDigit(colorString[i]))
            digitBuffer.append('0');
        else
            digitBuffer.append(colorString[i]);
    }

    if (!digitBuffer.size())
        return Color::black;

    // Pad the buffer out to at least the next multiple of three in size.
    digitBuffer.append('0');
    digitBuffer.append('0');

    if (digitBuffer.size() < 6)
        return makeRGB(toASCIIHexValue(digitBuffer[0]), toASCIIHexValue(digitBuffer[1]), toASCIIHexValue(digitBuffer[2]));

    // Split the digits into three components, then search the last 8 digits of each component.
    ASSERT(digitBuffer.size() >= 6);
    size_t componentLength = digitBuffer.size() / 3;
    size_t componentSearchWindowLength = min<size_t>(componentLength, 8);
    size_t redIndex = componentLength - componentSearchWindowLength;
    size_t greenIndex = componentLength * 2 - componentSearchWindowLength;
    size_t blueIndex = componentLength * 3 - componentSearchWindowLength;
    // Skip digits until one of them is non-zero, or we've only got two digits left in the component.
    while (digitBuffer[redIndex] == '0' && digitBuffer[greenIndex] == '0' && digitBuffer[blueIndex] == '0' && (componentLength - redIndex) > 2) {
        redIndex++;
        greenIndex++;
        blueIndex++;
    }
    ASSERT(redIndex + 1 < componentLength);
    ASSERT(greenIndex >= componentLength);
    ASSERT(greenIndex + 1 < componentLength * 2);
    ASSERT(blueIndex >= componentLength * 2);
    ASSERT_WITH_SECURITY_IMPLICATION(blueIndex + 1 < digitBuffer.size());

    int redValue = toASCIIHexValue(digitBuffer[redIndex], digitBuffer[redIndex + 1]);
    int greenValue = toASCIIHexValue(digitBuffer[greenIndex], digitBuffer[greenIndex + 1]);
    int blueValue = toASCIIHexValue(digitBuffer[blueIndex], digitBuffer[blueIndex + 1]);
    return makeRGB(redValue, greenValue, blueValue);
}
Beispiel #4
0
int main()
{
	int wnd = npCreateObject();

	SetColor(wnd,"bg",255,255,0);
	SetColor(wnd,"border",0,0,0);
	SetAttribute(wnd,"borderRadius","10px");

	npObject* obj = LockObject(wnd,"bg border");
	makeRGB(obj->att[0].data,obj->att[0].data+sizeof(RGB),0,0,0);
	makeRGB(obj->att[1].data,obj->att[1].data+sizeof(RGB),0,0,0);

	return 0;
}
Beispiel #5
0
static bool parseRGBParameters(CSSParserTokenRange& range, RGBA32& result, bool parseAlpha)
{
    ASSERT(range.peek().functionId() == CSSValueRgb || range.peek().functionId() == CSSValueRgba);
    CSSParserTokenRange args = consumeFunction(range);
    CSSPrimitiveValue* colorParameter = consumeInteger(args);
    if (!colorParameter)
        colorParameter = consumePercent(args, ValueRangeAll);
    if (!colorParameter)
        return false;
    const bool isPercent = colorParameter->isPercentage();
    int colorArray[3];
    colorArray[0] = clampRGBComponent(*colorParameter);
    for (int i = 1; i < 3; i++) {
        if (!consumeCommaIncludingWhitespace(args))
            return false;
        colorParameter = isPercent ? consumePercent(args, ValueRangeAll) : consumeInteger(args);
        if (!colorParameter)
            return false;
        colorArray[i] = clampRGBComponent(*colorParameter);
    }
    if (parseAlpha) {
        if (!consumeCommaIncludingWhitespace(args))
            return false;
        double alpha;
        if (!consumeNumberRaw(args, alpha))
            return false;
        // Convert the floating pointer number of alpha to an integer in the range [0, 256),
        // with an equal distribution across all 256 values.
        int alphaComponent = static_cast<int>(clampTo<double>(alpha, 0.0, 1.0) * nextafter(256.0, 0.0));
        result = makeRGBA(colorArray[0], colorArray[1], colorArray[2], alphaComponent);
    } else {
        result = makeRGB(colorArray[0], colorArray[1], colorArray[2]);
    }
    return args.atEnd();
}
TEST_F(LayoutThemeTest, ChangeFocusRingColor)
{
    setHtmlInnerHTML("<span id=span tabIndex=0>Span</span>");

    Element* span = document().getElementById(AtomicString("span"));
    EXPECT_NE(nullptr, span);
    EXPECT_NE(nullptr, span->layoutObject());

    Color customColor = makeRGB(123, 145, 167);

    // Checking unfocused style.
    EXPECT_EQ(BNONE, outlineStyle(span));
    EXPECT_NE(customColor, outlineColor(span));

    // Do focus.
    document().page()->focusController().setActive(true);
    document().page()->focusController().setFocused(true);
    span->focus();
    document().view()->updateAllLifecyclePhases();

    // Checking focused style.
    EXPECT_NE(BNONE, outlineStyle(span));
    EXPECT_NE(customColor, outlineColor(span));

    // Change focus ring color.
    LayoutTheme::theme().setCustomFocusRingColor(customColor);
    Page::platformColorsChanged();
    document().view()->updateAllLifecyclePhases();

    // Check that the focus ring color is updated.
    EXPECT_NE(BNONE, outlineStyle(span));
    EXPECT_EQ(customColor, outlineColor(span));
}
Beispiel #7
0
static bool fastParseColorInternal(RGBA32& rgb,
                                   const CharacterType* characters,
                                   unsigned length,
                                   bool quirksMode) {
  CSSPrimitiveValue::UnitType expect = CSSPrimitiveValue::UnitType::Unknown;

  if (length >= 4 && characters[0] == '#')
    return Color::parseHexColor(characters + 1, length - 1, rgb);

  if (quirksMode && (length == 3 || length == 6)) {
    if (Color::parseHexColor(characters, length, rgb))
      return true;
  }

  // Try rgba() syntax.
  if (mightBeRGBA(characters, length)) {
    const CharacterType* current = characters + 5;
    const CharacterType* end = characters + length;
    int red;
    int green;
    int blue;
    int alpha;

    if (!parseColorIntOrPercentage(current, end, ',', expect, red))
      return false;
    if (!parseColorIntOrPercentage(current, end, ',', expect, green))
      return false;
    if (!parseColorIntOrPercentage(current, end, ',', expect, blue))
      return false;
    if (!parseAlphaValue(current, end, ')', alpha))
      return false;
    if (current != end)
      return false;
    rgb = makeRGBA(red, green, blue, alpha);
    return true;
  }

  // Try rgb() syntax.
  if (mightBeRGB(characters, length)) {
    const CharacterType* current = characters + 4;
    const CharacterType* end = characters + length;
    int red;
    int green;
    int blue;
    if (!parseColorIntOrPercentage(current, end, ',', expect, red))
      return false;
    if (!parseColorIntOrPercentage(current, end, ',', expect, green))
      return false;
    if (!parseColorIntOrPercentage(current, end, ')', expect, blue))
      return false;
    if (current != end)
      return false;
    rgb = makeRGB(red, green, blue);
    return true;
  }

  return false;
}
// ######################################################################
void CenterSurroundHistogramSegmenter::drawCurrentCSbelief
(Point2D<int> pt, Rectangle grC, Rectangle grS)
{
  uint width  = itsImage.getWidth();
  uint height = itsImage.getHeight();
  if(itsWin.is_invalid())
    itsWin.reset(new XWinManaged(Dims(2*width, height), 0, 0, "CSHse"));
  else itsWin->setDims(Dims(2*width, height));

  uint gwidth  = width/GRID_SIZE;
  uint gheight = height/GRID_SIZE;

  // display the window      
  Image<PixRGB<byte> > disp(2*width, height, ZEROS);
  inplacePaste(disp, itsImage, Point2D<int>(0,0));
  if(pt.isValid())
    {
      drawCross(disp, pt, PixRGB<byte>(255,0,0), 10, 1);
    }
  if(grC.isValid())
    {
      drawRect(disp, grC*GRID_SIZE, PixRGB<byte>(255,0,0), 1);
      drawRect(disp, grS*GRID_SIZE, PixRGB<byte>(0,255,0), 1);
    }

  float mVal = 32;
  float bVal = 255 - mVal;
  
  Image<byte> dImaR, dImaG, dImaB;
  getComponents(itsImage, dImaR, dImaG, dImaB);
  inplaceNormalize(dImaR, byte(0), byte(mVal));
  inplaceNormalize(dImaG, byte(0), byte(mVal));
  inplaceNormalize(dImaB, byte(0), byte(mVal));
  Image<PixRGB<byte> > dIma  = makeRGB(dImaR,dImaG,dImaB);      
  
  // Image<float> dImaCf = itsGridCenterBelief;
  // inplaceNormalize(dImaCf, 0.0F, bVal);
  // Image<byte> dImaCb(dImaCf);
  // Image<PixRGB<byte> > dImaC = makeRGB(dImaCb,dImaCb,dImaCb);
  
  // Image<float> dImaSf = itsGridSurroundBelief;
  // inplaceNormalize(dImaSf, 0.0F, bVal);
  // Image<byte> dImaSb(dImaSf);
  // Image<PixRGB<byte> > dImaS = makeRGB(dImaSb,dImaSb,dImaSb);

  // Image<PixRGB<byte> > tdImaC(dIma+zoomXY(dImaC,GRID_SIZE));
  // Image<PixRGB<byte> > tdImaS(dIma+zoomXY(dImaS,GRID_SIZE));
  // inplacePaste (disp, tdImaC, Point2D<int>(width,0));
  // inplacePaste (disp, tdImaS, Point2D<int>(2*width,0));
 
  Image<float> dImaCSf = 
    clampedDiff((itsGridCenterBelief - itsGridSurroundBelief), 
              Image<float>(gwidth,gheight,ZEROS));
  inplaceNormalize(dImaCSf, 0.0F, bVal);
  Image<byte> dImaCSb(dImaCSf);
  Image<PixRGB<byte> > dImaCS = makeRGB(dImaCSb,dImaCSb,dImaCSb);
  Image<PixRGB<byte> > tdImaCS(dIma+zoomXY(dImaCS,GRID_SIZE));
  inplacePaste (disp, tdImaCS, Point2D<int>(width,0));

  Point2D<int> noff (width,0);
  drawCross(disp, pt+noff, PixRGB<byte>(255,0,0), 10, 1);
 
  if(itsCSrectangle.isValid())
    {
      drawRect(disp, itsCSrectangle*GRID_SIZE,        PixRGB<byte>(255,0,0), 1);
      drawRect(disp, (itsCSrectangle*GRID_SIZE)+noff, PixRGB<byte>(255,0,0), 1);
    }

  itsWin->drawImage(disp,0,0);
  Raster::waitForKey();
}
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;
}
// ######################################################################
Image<PixRGB<byte> > ContourBoundaryDetector::getContourBoundaryImage()
{
  int w = itsImage.getWidth();
  int h = itsImage.getHeight();

  Image<PixRGB<byte> > image = itsImage;
  float mVal = 96;
  float bVal = 255 - mVal;
  Image<byte> dImaR, dImaG, dImaB;
  getComponents(image, dImaR, dImaG, dImaB);
  inplaceNormalize(dImaR, byte(0), byte(mVal));
  inplaceNormalize(dImaG, byte(0), byte(mVal));
  inplaceNormalize(dImaB, byte(0), byte(mVal));

  // Image<float> tBI = itsBoundaryImageNMS;
  // inplaceNormalize(tBI, 0.0f, bVal); 
  // Image<byte> tBIb(tBI);

  Image<PixRGB<byte> > dIma = makeRGB(dImaR,dImaG,dImaB);
  // Image<PixRGB<byte> > dIma = 
  //   makeRGB(Image<byte>(dImaR+tBIb),
  //           Image<byte>(dImaG+tBIb),
  //           Image<byte>(dImaB+tBIb) );
  //Image<PixRGB<byte> > dIma = makeRGB(tBIb, tBIb, tBIb);

  int hstep = BOUNDARY_STEP_SIZE/2;

  // clean image
  Image<byte> dCBmapR(w,h,ZEROS);
  Image<byte> dCBmapG(w,h,ZEROS);
  Image<byte> dCBmapB(w,h,ZEROS);

  for(uint i = 0; i < itsContourBoundaries.size(); i++)
    {
      rutz::shared_ptr<Contour> contour = itsContourBoundaries[i];

      if(contour->edgels.size() < 5) continue;

      byte rcVal, gcVal, bcVal;
      rcVal = bVal*rand()/(RAND_MAX+1.0);
      gcVal = bVal*rand()/(RAND_MAX+1.0);
      bcVal = bVal*rand()/(RAND_MAX+1.0);      
 
      for(uint j = 0; j < contour->edgels.size(); j++)
        {
          rutz::shared_ptr<Edgel> edgel = contour->edgels[j];
          
          uint aind = edgel->angleIndex; 
          float baind = 
            fmod((aind+(NUM_RIDGE_DIRECTIONS/2)),NUM_RIDGE_DIRECTIONS);
          
          float dx = cos(baind * M_PI/4.0) * hstep; 
          float dy = sin(baind * M_PI/4.0) * hstep;
          
          Point2D<int> pt = edgel->pt;
          Point2D<int> p1 = pt + Point2D<int>( dx+.5,  dy+.5); 
          Point2D<int> p2 = pt + Point2D<int>(-dx-.5, -dy-.5);
          
          //LINFO("%d %d | %d %d | %d %d::::: %d %d  %d", 
          //         pt.i, pt.j, p1.i, p1.j, p2.i, p2.j, iEdgel, jEdgel, maxk);	      

          // draw the edgel

          // draw the straightline contour in the image 
          // for visualization
          drawLine(dCBmapR, p1, p2, byte(rcVal));
          drawLine(dCBmapG, p1, p2, byte(gcVal));
          drawLine(dCBmapB, p1, p2, byte(bcVal));
          //drawDisk(itsContourBoundaryImage, pt, 2,  255.0F);
        }
    }

  Image<PixRGB<byte> > dCBmap = makeRGB(dCBmapR,dCBmapG,dCBmapB);
  return Image<PixRGB<byte> >(dIma+dCBmap);
}