Fix bug in ColorPicker::pickColor() getting colors outside the image bounds

This commit is contained in:
David Capello 2014-03-02 20:07:11 -03:00
parent 77cd0e9cc6
commit 6cfcdc23e1

View File

@ -23,6 +23,7 @@
#include "app/color_picker.h" #include "app/color_picker.h"
#include "app/document_location.h" #include "app/document_location.h"
#include "gfx/point.h"
#include "raster/image.h" #include "raster/image.h"
#include "raster/primitives.h" #include "raster/primitives.h"
#include "raster/sprite.h" #include "raster/sprite.h"
@ -48,8 +49,10 @@ void ColorPicker::pickColor(const DocumentLocation& location, int x, int y, Mode
else { // Pick from the current layer else { // Pick from the current layer
int u, v; int u, v;
raster::Image* image = location.image(&u, &v, NULL); raster::Image* image = location.image(&u, &v, NULL);
if (image) { gfx::Point pt(x-u, y-v);
raster::color_t imageColor = get_pixel(image, x-u, y-v);
if (image && image->getBounds().contains(pt)) {
raster::color_t imageColor = get_pixel(image, pt.x, pt.y);
switch (image->getPixelFormat()) { switch (image->getPixelFormat()) {
case IMAGE_RGB: case IMAGE_RGB: