RenderImageCairo::RenderImageCairo(void* data, size_t len) { int x, y, n; stbi_buffer_ = stbi_load_from_memory((const stbi_uc*)data, len, &x, &y, &n, 4); Color* pColorBegin = (Color*)stbi_buffer_; for (int i = 0; i < x*y; i++) { Color* pColor = pColorBegin + i; Color origin = *pColor; uint8 a = ColorGetA(origin); uint8 r = ColorGetB(origin); uint8 g = ColorGetG(origin); uint8 b = ColorGetR(origin); if (a < 255) { *pColor = ColorSetARGB(a, r*a/255, g*a/255, b*a/255); } else { *pColor = ColorSetARGB(a, r, g, b); } } size_.SetSize(x, y); cairo_format_t format = CAIRO_FORMAT_ARGB32; int stride = cairo_format_stride_for_width(format, x); image_surface_ = cairo_image_surface_create_for_data(stbi_buffer_, format, x, y, stride); }
void Shape::drawBackground(SkCanvas & canvas, float opacity) { if (kNone == category_) return; SkPaint paint; paint.setAntiAlias(Core::AntiAliasEnable()); paint.setColor(color_); paint.setShader(shader_); paint.setAlpha(ClampAlpha(opacity, ColorGetA(color_))); paint.setStrokeWidth(stroke_width_); if (effect_) paint.setPathEffect(effect_); if (kFill == style_) paint.setStyle(SkPaint::kFill_Style); else if (kStroke == style_) paint.setStyle(SkPaint::kStroke_Style); if(kRect == category_) { SkRect r; Rect re = Rect::MakeLTRB(param_.rect.left, param_.rect.top, param_.rect.right, param_.rect.bottom); if (re.isEmpty()) { if (kStroke == style_) { auto offset = stroke_width_ / 2; re = Rect::MakeLTRB(offset, offset, getWidth() - offset, getHeight() - offset); } else re = Rect::MakeLTRB(0, 0, getWidth(), getHeight()); r = Helper::ToSkRect(re); } else { if (kStroke == style_) { auto offset = stroke_width_ / 2; re = Rect::MakeLTRB(re.left() + offset, re.top() + offset, re.right() - offset, re.bottom()- offset); } r = Helper::ToSkRect(re); } canvas.drawRoundRect(r, param_.rect.rx, param_.rect.ry, paint); } else if( kCircle == category_) { canvas.drawCircle(param_.circle.cx, param_.circle.cy, param_.circle.radius, paint); } else if (kLine == category_) { canvas.drawLine(param_.line.xs, param_.line.ys, param_.line.xe, param_.line.ye, paint); } else if (kPoint == category_) { canvas.drawPoint(param_.point.x, param_.point.y, paint); } else if (kOval == category_) { Rect re = Rect::MakeLTRB(param_.oval.left, param_.oval.top, param_.oval.right, param_.oval.bottom); if (re.isEmpty()) re.setLTRB(0, 0, getWidth(), getHeight()); canvas.drawOval(Helper::ToSkRect(re), paint); } else if (kArc == category_) { Rect re = Rect::MakeLTRB(param_.arc.left, param_.arc.top, param_.arc.right, param_.arc.bottom); if (re.isEmpty()) re.setLTRB(0, 0, getWidth(), getHeight()); canvas.drawArc(Helper::ToSkRect(re), param_.arc.start, param_.arc.sweep, param_.arc.center, paint); } else if (kPath == category_) canvas.drawPath(*path_, paint); }