Browse Source

Using cairo_scale() instead

v1.x
Tj Holowaychuk 15 years ago
parent
commit
e4a40e5ea2
  1. 48
      src/CanvasRenderingContext2d.cc

48
src/CanvasRenderingContext2d.cc

@ -403,43 +403,35 @@ Context2d::DrawImage(const Arguments &args) {
// TODO: arg handling / boundaries // TODO: arg handling / boundaries
Image *img = ObjectWrap::Unwrap<Image>(args[0]->ToObject()); Image *img = ObjectWrap::Unwrap<Image>(args[0]->ToObject());
Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This()); Context2d *context = ObjectWrap::Unwrap<Context2d>(args.This());
cairo_t *ctx = context->context();
// Src point // Src point
int sx = 0; int sx = 0
int sy = 0; , sy = 0;
// Dest point // Dest point
int dx = args[1]->NumberValue(); int dx = args[1]->NumberValue()
int dy = args[2]->NumberValue(); , dy = args[2]->NumberValue();
// Dest dimensions // Dest dimensions
int dw = args[3]->IsNumber() ? args[3]->NumberValue() : img->width; int height = img->height
int dh = args[4]->IsNumber() ? args[4]->NumberValue() : img->height; , width = img->width;
int dw = args[3]->IsNumber() ? args[3]->NumberValue() : width
, dh = args[4]->IsNumber() ? args[4]->NumberValue() : height;
// Draw // Draw
uint8_t *dst = context->canvas()->data(); cairo_save(ctx);
int dstStride = context->canvas()->stride(); if (dw != width || dh != height) {
cairo_scale(ctx
int srcStride = img->stride(); , (float) dw / width
uint8_t *src = img->data() + sy * srcStride + sx * 4; , (float) dh / height
);
for (int y = 0; y < dh; ++y) {
uint32_t *dstRow = (uint32_t *)(dst + dstStride * (y + dy));
for (int x = 0; x < dw; ++x) {
int bx = x * 4;
uint32_t *srcPixel = (uint32_t *)(src + bx);
uint32_t *dstPixel = dstRow + x + dx;
*dstPixel = *srcPixel;
}
src += srcStride;
} }
// TODO: globalAlpha
cairo_surface_mark_dirty_rectangle( cairo_set_source_surface(ctx, img->surface(), dx, dy);
context->canvas()->surface() cairo_paint(ctx);
, dx cairo_restore(ctx);
, dy
, dw
, dh);
return Undefined(); return Undefined();
} }

Loading…
Cancel
Save