void UIContext::drawText(const OUIControlRef& pControl, const Rect& rect, const UITextComponent& textComponent) { if (textComponent.text.empty()) return; auto align = (textComponent.font.align); auto oRect = (rect); auto pFont = pContentManager.lock()->getResourceAs<OFont>(textComponent.font.typeFace.c_str()); auto oColor = (textComponent.font.color); if (pControl->getState(OThis) == UIControl::State::Disabled) { oColor = {.4f, .4f, .4f, 1}; } oColor.Premultiply(); if (pFont) { if (pControl->getStyleName() == "password") { std::string pwd; pwd.resize(textComponent.text.size(), '*'); if (pControl->hasFocus(OThis) && ODynamicCast<UITextBox>(pControl)->isCursorVisible()) { pwd.back() = '_'; } pFont->draw(pwd, ORectAlign(oRect, align), Vector2(align), oColor); } else { pFont->draw(textComponent.text, ORectAlign(oRect, align), Vector2(align), oColor); } } };
ImageDraw::operator Image() const { ImageBuffer img(isz); FetchStraight(img); Premultiply(img); return img; }
SImageDraw::operator Image() const { ImageBuffer b(ib.GetSize()); memcpy(b, ib.Begin(), sizeof(RGBA) * ib.GetLength()); RGBA *t = b; const RGBA *e = b.End();; if(has_alpha) { const RGBA *s = alpha.ib.Begin(); while(t < e) { t->a = s->r; t++; s++; } Premultiply(b); b.SetKind(IMAGE_ALPHA); } else { while(t < e) { t->a = 255; t++; } b.SetKind(IMAGE_OPAQUE); } return b; }
void HeaderCtrl::LeftDrag(Point p, dword keyflags) { if(li < 0 || !moving) return; int n = 0; for(int i = 0; i < col.GetCount(); i++) if(col[i].visible) n++; if(n < 2) return; push = false; ti = li; pushi = -1; Refresh(); Rect r = GetTabRect(li).OffsetedHorz(-sb); Size sz = r.GetSize(); ImageDraw iw(sz.cx, sz.cy); bool first = true; col[li].Paint(first, iw, 0, 0, sz.cx, sz.cy, false, false, false); DrawFrame(iw, sz, SColorText()); dragtab = iw; dragx = p.x; dragd = r.left - p.x; ImageBuffer ib(dragtab); Unmultiply(ib); RGBA *s = ~ib; RGBA *e = s + ib.GetLength(); while(s < e) { s->a >>= 1; s++; } Premultiply(ib); dragtab = ib; isdrag = true; }
RGBA RGBACtrl::Get() const { RGBA c = color; c.a = alpha.Get(); if(alpha.IsMask()) c.r = c.g = c.b = c.a; Premultiply(&c, &c, 1); return c; }
Pixel* GenerateGradientTable(Pixel StartColor, Pixel EndColor, int Size, int Offset) { if (Size < 1) Size = 1; // Pixel *pTable = AllocateArray(Pixel, Size); Pixel *pTable = LookupAllocate<Pixel>(Size + 1); if (!pTable) return Null; if (Size == 1) { pTable[0] = Premultiply(StartColor); return pTable; } if (Offset < 0) Offset = 0; float w = 0, winc = ((float)255 / (float)(Size - 1)); int weight = 0, ci = 0; for (int i = 0; i < Size; i++) { ci = i - Offset; w += winc; if (((ci) >= 0) && (ci < Size)) { weight = ClipByte(w); // set the alpha for this column (inverted) pTable[ci][::Alpha] = (((StartColor[::Alpha] * (weight ^ 0xFF)) + (EndColor[::Alpha] * weight)) / 255) ^ 0xFF; // set the color for this column (premultiplied for more speed) pTable[ci][::Blue] = (((StartColor[::Blue] * (weight ^ 0xFF)) + (EndColor[::Blue] * weight)) / 255) * (pTable[ci][::Alpha] ^ 0xFF) / 255; pTable[ci][::Green] = (((StartColor[::Green] * (weight ^ 0xFF)) + (EndColor[::Green] * weight)) / 255) * (pTable[ci][::Alpha] ^ 0xFF) / 255; pTable[ci][::Red] = (((StartColor[::Red] * (weight ^ 0xFF)) + (EndColor[::Red] * weight)) / 255) * (pTable[ci][::Alpha] ^ 0xFF) / 255; } } pTable[0] = Premultiply(StartColor); pTable[0][::Alpha] = pTable[0][::Alpha] ^ 0xFF; pTable[Size - 1] = Premultiply(EndColor); pTable[Size - 1][::Alpha] = pTable[Size - 1][::Alpha] ^ 0xFF; return pTable; }
Image DisImage(const Image& m) { Image mm = Grayscale(m, 200); ImageBuffer ib(mm); RGBA *s = ~ib; RGBA *e = s + ib.GetLength(); while(s < e) (s++)->a /= 3; Premultiply(ib); return ib; }
void nsGLPbufferWGL::SwapBuffers() { MakeContextCurrent(); mGLWrap.fReadPixels (0, 0, mWidth, mHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, mThebesSurface->Data()); // premultiply the image int len = mWidth*mHeight*4; unsigned char *src = mThebesSurface->Data(); Premultiply(src, len); }
void IconDes::MakePaste() { if(!IsCurrent() || !IsPasting()) return; Slot& c = Current(); c.image = c.base_image; if(paste_opaque) UPP::Copy(c.image, c.pastepos, c.paste_image, c.paste_image.GetSize()); else UPP::Over(c.image, c.pastepos, Premultiply(c.paste_image), c.paste_image.GetSize()); MaskSelection(); }
Image IconDes::MakeIconDesCursor(const Image& arrow, const Image& cmask) { RGBA c = CurrentColor(); c.a = 255; Image ucmask = Unmultiply(cmask); ImageBuffer ib(ucmask.GetSize()); const RGBA *m = ~ucmask; RGBA *t = ~ib; RGBA *e = ib.End(); while(t < e) { *t = c; t->a = m->a; m++; t++; } Image cm(ib); Image r = arrow; Over(r, Point(0, 0), Premultiply(cm), r.GetSize()); return r; }
Image ImageDraw::Get(bool pm) const { ImageBuffer result(image.GetSize()); const RGBA *e = image.End(); const RGBA *p = ~image; RGBA *t = ~result; if(has_alpha) { const RGBA *a = ~alpha; while(p < e) { *t = *p++; (t++)->a = (a++)->r; } if(pm) Premultiply(result); result.SetKind(IMAGE_ALPHA); } else { while(p < e) { *t = *p++; (t++)->a = 255; } } return result; }
ImageDraw::operator Image() const { GuiLock __; XImage *xim = XGetImage(Xdisplay, dw, 0, 0, max(size.cx, 1), max(size.cy, 1), AllPlanes, ZPixmap); if(!xim) return Null; Visual *v = DefaultVisual(Xdisplay, Xscreenno); RasterFormat fmt; RGBA palette[256]; switch(xim->depth) { case 15: case 16: if(xim->byte_order == LSBFirst) fmt.Set16le(v->red_mask, v->green_mask, v->blue_mask); else fmt.Set16be(v->red_mask, v->green_mask, v->blue_mask); break; case 8: { int n = min(v->map_entries, 256); XColor colors[256]; for(int i = 0; i < 256; i++) { colors[i].pixel = i; colors[i].flags = DoRed|DoGreen|DoBlue; } XQueryColors(Xdisplay, Xcolormap, colors, n); XColor *s = colors; XColor *e = s + n; while(s < e) { RGBA& t = palette[s->pixel]; t.r = s->red >> 8; t.g = s->green >> 8; t.b = s->blue >> 8; t.a = 255; s++; } fmt.Set8(); break; } default: if(xim->bits_per_pixel == 32) if(xim->byte_order == LSBFirst) fmt.Set32le(v->red_mask, v->green_mask, v->blue_mask); else fmt.Set32be(v->red_mask, v->green_mask, v->blue_mask); else if(xim->byte_order == LSBFirst) fmt.Set24le(v->red_mask, v->green_mask, v->blue_mask); else fmt.Set24be(v->red_mask, v->green_mask, v->blue_mask); break; } ImageBuffer ib(size); const byte *s = (const byte *)xim->data; RGBA *t = ib; for(int y = 0; y < size.cy; y++) { fmt.Read(t, s, size.cx, palette); s += xim->bytes_per_line; t += size.cx; } XDestroyImage(xim); if(has_alpha) { xim = XGetImage(Xdisplay, alpha.dw, 0, 0, max(size.cx, 1), max(size.cy, 1), AllPlanes, ZPixmap); if(xim) { const byte *s = (const byte *)xim->data; t = ib; Buffer<RGBA> line(size.cx); for(int y = 0; y < size.cy; y++) { fmt.Read(line, s, size.cx, palette); for(int x = 0; x < size.cx; x++) (t++)->a = line[x].r; s += xim->bytes_per_line; } XDestroyImage(xim); } } Premultiply(ib); return ib; }
bool LoadIml(const String& data, Array<ImlImage>& img, int& format) { CParser p(data); format = 0; try { bool premultiply = !p.Id("PREMULTIPLIED"); Vector<String> name; Vector<bool> exp; while(p.Id("IMAGE_ID")) { p.PassChar('('); String n; if(p.IsId()) { n = p.ReadId(); if(n.StartsWith("im__", 4)) n = Null; p.PassChar(')'); } else while(!p.IsEof()) { if(p.Char(')')) break; p.SkipTerm(); } name.Add(n); bool e = false; if(p.Id("IMAGE_META")) { p.PassChar('('); e = p.ReadString() == "exp"; if(p.Char(',') && p.IsString()) p.ReadString(); p.PassChar(')'); } exp.Add(e); } int ii = 0; while(p.Id("IMAGE_BEGIN_DATA")) { String data; while(p.Id("IMAGE_DATA")) { p.PassChar('('); for(int j = 0; j < 32; j++) { if(j) p.PassChar(','); data.Cat(p.ReadInt()); } p.PassChar(')'); } p.PassId("IMAGE_END_DATA"); p.PassChar('('); int zlen = p.ReadInt(); p.PassChar(','); int count = p.ReadInt(); p.PassChar(')'); data.Trim(zlen); Vector<Image> m = UnpackImlData(data, data.GetCount()); if(m.GetCount() != count || ii + count > name.GetCount()) p.ThrowError(""); for(int i = 0; i < count; i++) { ImlImage& c = img.Add(); c.name = name[ii]; c.exp = exp[ii++]; c.image = m[i]; if(premultiply) c.image = Premultiply(c.image); } } if(!p.IsEof()) p.ThrowError(""); } catch(CParser::Error) { try { CParser p(data); Array<ImlImage> m; VectorMap<String, String> s; ScanIML(p, img, s); if(img.GetCount()) format = 1; } catch(...) { return false; } } return true; }