Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/core/SkBitmap.cpp

Issue 15489004: New API for encoding bitmaps during serialization. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Respond to comments. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2008 The Android Open Source Project 3 * Copyright 2008 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 return SUB_OFFSET_FAILURE; 859 return SUB_OFFSET_FAILURE;
860 } 860 }
861 return y * bm.rowBytes() + x; 861 return y * bm.rowBytes() + x;
862 } 862 }
863 863
864 /** 864 /**
865 * Using the pixelRefOffset(), rowBytes(), and Config of bm, determine the (x, y) coordinate of the 865 * Using the pixelRefOffset(), rowBytes(), and Config of bm, determine the (x, y) coordinate of the
866 * upper left corner of bm relative to its SkPixelRef. 866 * upper left corner of bm relative to its SkPixelRef.
867 * x and y must be non-NULL. 867 * x and y must be non-NULL.
868 */ 868 */
869 static bool getUpperLeftFromOffset(const SkBitmap& bm, int32_t* x, int32_t* y) { 869 bool getUpperLeftFromOffset(SkBitmap::Config config, size_t offset, size_t rowBy tes,
870 int32_t* x, int32_t* y) {
870 SkASSERT(x != NULL && y != NULL); 871 SkASSERT(x != NULL && y != NULL);
871 const size_t offset = bm.pixelRefOffset();
872 if (0 == offset) { 872 if (0 == offset) {
873 *x = *y = 0; 873 *x = *y = 0;
874 return true; 874 return true;
875 } 875 }
876 // Use integer division to find the correct y position. 876 // Use integer division to find the correct y position.
877 *y = SkToS32(offset / bm.rowBytes()); 877 *y = SkToS32(offset / rowBytes);
878 // The remainder will be the x position, after we reverse getSubOffset. 878 // The remainder will be the x position, after we reverse getSubOffset.
879 *x = SkToS32(offset % bm.rowBytes()); 879 *x = SkToS32(offset % rowBytes);
880 switch (bm.getConfig()) { 880 switch (config) {
881 case SkBitmap::kA8_Config: 881 case SkBitmap::kA8_Config:
882 // Fall through. 882 // Fall through.
883 case SkBitmap::kIndex8_Config: 883 case SkBitmap::kIndex8_Config:
884 // x is unmodified 884 // x is unmodified
885 break; 885 break;
886 886
887 case SkBitmap::kRGB_565_Config: 887 case SkBitmap::kRGB_565_Config:
888 // Fall through. 888 // Fall through.
889 case SkBitmap::kARGB_4444_Config: 889 case SkBitmap::kARGB_4444_Config:
890 *x >>= 1; 890 *x >>= 1;
891 break; 891 break;
892 892
893 case SkBitmap::kARGB_8888_Config: 893 case SkBitmap::kARGB_8888_Config:
894 *x >>= 2; 894 *x >>= 2;
895 break; 895 break;
896 896
897 case SkBitmap::kNo_Config: 897 case SkBitmap::kNo_Config:
898 // Fall through. 898 // Fall through.
899 case SkBitmap::kA1_Config: 899 case SkBitmap::kA1_Config:
900 // Fall through. 900 // Fall through.
901 default: 901 default:
902 return false; 902 return false;
903 } 903 }
904 return true; 904 return true;
905 } 905 }
906 906
907 static bool getUpperLeftFromOffset(const SkBitmap& bm, int32_t* x, int32_t* y) {
djsollen 2013/05/21 14:10:44 according to our style guide static methods should
scroggo 2013/05/21 16:14:15 Done.
908 return getUpperLeftFromOffset(bm.config(), bm.pixelRefOffset(), bm.rowBytes( ), x, y);
909 }
910
907 bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const { 911 bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const {
908 SkDEBUGCODE(this->validate();) 912 SkDEBUGCODE(this->validate();)
909 913
910 if (NULL == result || NULL == fPixelRef) { 914 if (NULL == result || NULL == fPixelRef) {
911 return false; // no src pixels 915 return false; // no src pixels
912 } 916 }
913 917
914 SkIRect srcRect, r; 918 SkIRect srcRect, r;
915 srcRect.set(0, 0, this->width(), this->height()); 919 srcRect.set(0, 0, this->width(), this->height());
916 if (!r.intersect(srcRect, subset)) { 920 if (!r.intersect(srcRect, subset)) {
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 if (NULL != uri) { 1673 if (NULL != uri) {
1670 str->appendf(" uri:\"%s\"", uri); 1674 str->appendf(" uri:\"%s\"", uri);
1671 } else { 1675 } else {
1672 str->appendf(" pixelref:%p", pr); 1676 str->appendf(" pixelref:%p", pr);
1673 } 1677 }
1674 } 1678 }
1675 1679
1676 str->append(")"); 1680 str->append(")");
1677 } 1681 }
1678 #endif 1682 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698