Hello noel,
I'd like you to do a code review. Please execute
g4 diff -c 10950128
or point your web browser to
http://mondrian/10950128
to review the following code:
Change 10950128 by nigel...@nigeltao-srcgears2 on 2009/04/28 20:53:46 *pending*
Add an (optional) filter argument to canvas.resize, to choose between
bi-linear and nearest-neighbor filtering.
PRESUBMIT=passed
R=noel
[email protected]
DELTA=32 (28 added, 0 deleted, 4 changed)
OCL=10950128
Affected files ...
... //depot/googleclient/gears/opensource/gears/canvas/canvas.cc#31 edit
... //depot/googleclient/gears/opensource/gears/canvas/canvas.h#25 edit
32 delta lines: 28 added, 0 deleted, 4 changed
Also consider running:
g4 lint -c 10950128
which verifies that the changelist doesn't introduce new style violations.
If you can't do the review, please let me know as soon as possible. During
your review, please ensure that all new code has corresponding unit tests and
that existing unit tests are updated appropriately. Visit
http://www/eng/code_review.html for more information.
This is a semiautomated message from "g4 mail". Complaints or suggestions?
Mail [email protected].
Change 10950128 by nigel...@nigeltao-srcgears2 on 2009/04/28 20:53:46 *pending*
Add an (optional) filter argument to canvas.resize, to choose between
bi-linear and nearest-neighbor filtering.
Affected files ...
... //depot/googleclient/gears/opensource/gears/canvas/canvas.cc#31 edit
... //depot/googleclient/gears/opensource/gears/canvas/canvas.h#25 edit
==== //depot/googleclient/gears/opensource/gears/canvas/canvas.cc#31 -
/home/nigeltao/srcgears2/googleclient/gears/opensource/gears/canvas/canvas.cc
====
# action=edit type=text
--- googleclient/gears/opensource/gears/canvas/canvas.cc 2009-04-28
20:53:53.000000000 +1000
+++ googleclient/gears/opensource/gears/canvas/canvas.cc 2009-04-28
20:52:04.000000000 +1000
@@ -300,6 +300,8 @@
{ JSPARAM_REQUIRED, JSPARAM_INT, &height }
};
context->GetArguments(ARRAYSIZE(args), args);
+ if (context->is_exception_set())
+ return;
ValidateWidthAndHeight(width, height, context);
if (context->is_exception_set())
return;
@@ -325,14 +327,28 @@
void GearsCanvas::Resize(JsCallContext *context) {
int new_width, new_height;
+ std::string16 filter;
+ bool filter_is_nearest = false;
JsArgument args[] = {
{ JSPARAM_REQUIRED, JSPARAM_INT, &new_width },
- { JSPARAM_REQUIRED, JSPARAM_INT, &new_height }
+ { JSPARAM_REQUIRED, JSPARAM_INT, &new_height },
+ { JSPARAM_OPTIONAL, JSPARAM_STRING16, &filter }
};
context->GetArguments(ARRAYSIZE(args), args);
+ if (context->is_exception_set())
+ return;
ValidateWidthAndHeight(new_width, new_height, context);
if (context->is_exception_set())
return;
+ if (context->GetArgumentCount() == 3) {
+ if (filter == STRING16(L"nearest")) {
+ filter_is_nearest = true;
+ } else if (filter != STRING16(L"bilinear")) {
+ context->SetException(
+ STRING16(L"Filter must be 'bilinear' or 'nearest'."));
+ return;
+ }
+ }
EnsureBitmapPixelsAreAllocated();
SkBitmap new_bitmap;
@@ -352,7 +368,14 @@
context->SetException(STRING16(L"Could not resize the image."));
return;
}
- new_canvas.drawBitmap(*skia_bitmap_, SkIntToScalar(0), SkIntToScalar(0));
+ if (filter_is_nearest) {
+ new_canvas.drawBitmap(*skia_bitmap_, SkIntToScalar(0), SkIntToScalar(0));
+ } else {
+ SkPaint paint;
+ paint.setFilterBitmap(true);
+ new_canvas.drawBitmap(
+ *skia_bitmap_, SkIntToScalar(0), SkIntToScalar(0), &paint);
+ }
}
new_bitmap.swap(*skia_bitmap_);
}
@@ -373,6 +396,8 @@
{ JSPARAM_REQUIRED, JSPARAM_INT, &new_width }
};
context->GetArguments(ARRAYSIZE(args), args);
+ if (context->is_exception_set())
+ return;
ValidateWidthAndHeight(new_width, GetHeight(), context);
if (context->is_exception_set())
return;
@@ -385,6 +410,8 @@
{ JSPARAM_REQUIRED, JSPARAM_INT, &new_height }
};
context->GetArguments(ARRAYSIZE(args), args);
+ if (context->is_exception_set())
+ return;
ValidateWidthAndHeight(GetWidth(), new_height, context);
if (context->is_exception_set())
return;
==== //depot/googleclient/gears/opensource/gears/canvas/canvas.h#25 -
/home/nigeltao/srcgears2/googleclient/gears/opensource/gears/canvas/canvas.h
====
# action=edit type=text
--- googleclient/gears/opensource/gears/canvas/canvas.h 2009-04-28
20:53:53.000000000 +1000
+++ googleclient/gears/opensource/gears/canvas/canvas.h 2009-04-28
20:50:03.000000000 +1000
@@ -77,8 +77,9 @@
// OUT: -
void Crop(JsCallContext *context);
- // Resizes the canvas (scaling its contents), in-place.
- // IN: int width, int height
+ // Resizes the canvas (scaling its contents), in-place. The filter (either
+ // "bilinear" or "nearest") defaults to "bilinear" if unspecified.
+ // IN: int width, int height, optional String filter
// OUT: -
void Resize(JsCallContext *context);