bool IsBorder(IplImage *img, int r, int c, int cid, int ds = 4) { if (IsColor(img, c, r, cid)) { for (int d = 0; d < ds; d++) if (0 <= r + dirs[d][0] && r + dirs[d][0] < img->height && 0 <= c + dirs[d][1] && c + dirs[d][1] < img->width) if (IsColor(img, c + dirs[d][1], r + dirs[d][0], cid) == false) return true; } return false; }
static void ParseStyle(FXSettings*reg, const char*section, StyleDef *style) { if (style->key) { FXString tmp=reg->readStringEntry(section, style->key, ""); tmp.lower(); tmp.substitute('\t', ' ', true); tmp.trim(); tmp.simplify(); tmp.substitute(" ", "", true); if (!tmp.empty()) { char buf[256]; char *fg=buf; char *bg=NULL; char *fs=NULL; int flags=Normal; strncpy(buf, tmp.text(), sizeof(buf)-1); bg=strchr(buf,','); if (bg) { *bg='\0'; bg++; fs=strchr(bg,','); if (fs) { *fs='\0'; fs++; if (strstr(fs,"italic")) { flags|=Italic; } if (strstr(fs,"bold")) { flags|=Bold; } if (strstr(fs,"underline")) { flags|=Underline; } if (strstr(fs,"eolfill")) { flags|=EOLFill; } } if (IsColor(bg)) { strncpy(style->bg, bg, 7); } } if (IsColor(fg)) { strncpy(style->fg, fg, 7); } style->style=(SciDocFontStyle)(flags); } } }
void GoRegionBoard::UpdateBlock(int move, SgBlackWhite moveColor) { SgPoint anchor = Board().Anchor(move); // board is already up to date. bool done = false; const int size = Board().Size(); if (! Board().IsSingleStone(move)) // find old neighbor blocks { SgVectorOf<GoBlock> old; for (GoNbIterator it(Board(), move); it; ++it) { if (IsColor(*it, moveColor)) old.Include(BlockAt(*it)); } if (old.IsLength(1)) // append to single neighbor block { GoBlock* b = old.Front(); AppendStone(b, move); done = true; } else // delete old, recompute { for (SgVectorIteratorOf<GoBlock> it(old); it; ++it) RemoveBlock(*it, true, true); } } if (! done) // create new block. { GoBlock* b = GenBlock(anchor, moveColor); SgPointSet area(b->Stones().Border(size)); // link it to neighbor regions SgVectorOf<GoRegion> regions; RegionsAt(area, moveColor, ®ions); for (SgVectorIteratorOf<GoRegion> it(regions); it; ++it) (*it)->BlocksNonConst().PushBack(b); } }
Font::Font(const String& filename) : Image(filename, 16, 16) { _glyphs = Array<Glyph>(); Glyph myGlyph = Glyph(); // Cargamos el buffer con la imagen int iWidth; int iHeight; unsigned char* buffer = stbi_load(filename.ToCString(), &iWidth, &iHeight, NULL, nElemPixel); // Calculamos las dimensiones de cada frame bool dimX = false; for (int i = 1; i < iWidth / nElemPixel && !dimX; i++) { uint8 r = buffer[i * nElemPixel]; uint8 g = buffer[i * nElemPixel + 1]; uint8 b = buffer[i * nElemPixel + 2]; if (IsColor(r, g, b, 255, 255, 0)) { _dimFrameX = i; dimX = true; } } bool dimY = false; for (int i = 1; i < iHeight / nElemPixel && !dimY; i++) { uint8 r = buffer[i * iWidth * nElemPixel]; uint8 g = buffer[i * iWidth * nElemPixel + 1]; uint8 b = buffer[i * iWidth * nElemPixel + 2]; if (IsColor(r, g, b, 255, 255, 0)) { _dimFrameY = i; dimY = true; } } // Tratamos los pixeles dentro de cada frame if ( buffer ) { if (dimX && dimY) { for (int j = 0; j < nFrameY; j++) { for (int i = 0; i < nFrameX; i++) { // Accedemos al frame[i,j] for (int k = 0; k < _dimFrameX; k++) { for (int l = 0; l < _dimFrameY; l++) { // Accedemos al pixel[k,l] del frame[i,j] uint8 r = buffer[IndexFrom(i, j, k, l, iWidth, 0)]; uint8 g = buffer[IndexFrom(i, j, k, l, iWidth, 1)]; uint8 b = buffer[IndexFrom(i, j, k, l, iWidth, 2)]; if (IsColor(r, g, b, 255, 255, 0)) { myGlyph.SetIni(i * _dimFrameX + k, j * _dimFrameY + l); buffer[IndexFrom(i, j, k, l, iWidth, 3)] = 0; } else if (IsColor(r, g, b, 255, 0, 0)) { myGlyph.SetFin(i * _dimFrameX + k, j * _dimFrameY + l); buffer[IndexFrom(i, j, k, l, iWidth, 3)] = 0; } else if (IsColor(r, g, b, 0, 0, 0)) { buffer[IndexFrom(i, j, k, l, iWidth, 3)] = 0; } } } if (myGlyph.GetIniX() != 0 || myGlyph.GetIniY() != 0 || myGlyph.GetFinX() != 0 || myGlyph.GetFinY() != 0) _glyphs.Add(myGlyph); } } glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iWidth, iHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); } free(buffer); } }
bool TransparencyStyle::IsCheckered() const{ return !IsColor(); }