Test region decoding in skimage, plus fixes.

Add tests in skimage to perform region decoding. Write out a
PNG of the region as well as a bitmap obtained with extractSubset
for comparison.

Rename decodeRegion to decodeSubset, so it will not be confused
with SkRegion. (Leave a function called decodeRegion which calls
decodeSubset.)

Clean up some comments.

Use png_set_interlaced_pass instead of modifying pass directly.

Make some changes to region decoding to fix problems I discovered
during testing:

Only call getAddr within a valid range.
Check for a NULL fInputStream.
Return a boolean for whether cropBitmap succeeded.
In cropBitmap, do not attempt to draw to a bitmap to an Index8
bitmap, which crashes. Use extractSubset instead.
Remove an assert.

R=djsollen@google.com

Review URL: https://codereview.chromium.org/14567011

git-svn-id: http://skia.googlecode.com/svn/trunk/include@8996 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/images/SkImageDecoder.h b/images/SkImageDecoder.h
index 54176bd..f6f64e1 100644
--- a/images/SkImageDecoder.h
+++ b/images/SkImageDecoder.h
@@ -216,13 +216,21 @@
     bool buildTileIndex(SkStream*, int *width, int *height);
 
     /**
-     * Decode a rectangle region in the image specified by rect.
+     * Decode a rectangle subset in the image.
      * The method can only be called after buildTileIndex().
      *
      * Return true for success.
      * Return false if the index is never built or failing in decoding.
      */
-    bool decodeRegion(SkBitmap* bitmap, const SkIRect& rect, SkBitmap::Config pref);
+    bool decodeSubset(SkBitmap* bm, const SkIRect& subset, SkBitmap::Config pref);
+
+    /**
+     *  @Deprecated
+     *  Use decodeSubset instead.
+     */
+    bool decodeRegion(SkBitmap* bitmap, const SkIRect& rect, SkBitmap::Config pref) {
+        return this->decodeSubset(bitmap, rect, pref);
+    }
 
     /** Given a stream, this will try to find an appropriate decoder object.
         If none is found, the method returns NULL.
@@ -344,7 +352,7 @@
 
     // If the decoder wants to support tiled based decoding,
     // this method must be overridden. This guy is called by decodeRegion(...)
-    virtual bool onDecodeRegion(SkBitmap* bitmap, const SkIRect& rect) {
+    virtual bool onDecodeSubset(SkBitmap* bitmap, const SkIRect& rect) {
         return false;
     }
 
@@ -359,10 +367,11 @@
      * @param (dstX, dstY) the upper-left point of the dest bitmap in terms of
      *                     the coordinate in the original bitmap.
      * @param (width, height) the width and height of the unsampled dst.
-     * @param (srcX, srcY) the upper-left point of the src bitimap in terms of
+     * @param (srcX, srcY) the upper-left point of the src bitmap in terms of
      *                     the coordinate in the original bitmap.
+     * @return bool Whether or not it succeeded.
      */
-    void cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize,
+    bool cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize,
                     int dstX, int dstY, int width, int height,
                     int srcX, int srcY);