add colortable setting support to c api
authorTyler Hoeflicker <thoeflicker@bluebeam.com>
Mon, 14 Nov 2016 18:17:43 +0000 (10:17 -0800)
committerTyler Hoeflicker <thoeflicker@bluebeam.com>
Mon, 14 Nov 2016 18:17:43 +0000 (10:17 -0800)
include/c/sk_bitmap.h
src/c/sk_bitmap.cpp

index bd7f901..7bf6c4a 100644 (file)
@@ -41,6 +41,7 @@ SK_API void sk_bitmap_set_pixel_colors(sk_bitmap_t* cbitmap, const sk_color_t* c
 SK_API bool sk_bitmap_try_alloc_pixels(sk_bitmap_t* cbitmap, const sk_imageinfo_t* requestedInfo, size_t rowBytes);
 SK_API bool sk_bitmap_try_alloc_pixels_with_color_table(sk_bitmap_t* cbitmap, const sk_imageinfo_t* requestedInfo, sk_pixelref_factory_t* factory, sk_colortable_t* ctable);
 SK_API sk_colortable_t* sk_bitmap_get_colortable(sk_bitmap_t* cbitmap);
+SK_API void sk_bitmap_set_colortable(sk_bitmap_t* cbitmap, sk_colortable_t* ctable);
 
 SK_C_PLUS_PLUS_END_GUARD
 
index 9e54972..fcf36bc 100644 (file)
@@ -25,6 +25,17 @@ static inline void copyAlpha8ToColor(size_t size, const uint8_t* pixels, sk_colo
     }
 }
 
+static inline void copyIndex8ToColor(sk_bitmap_t* cbitmap, size_t size, const uint8_t* pixels, sk_color_t* colors)
+{
+    SkBitmap* bmp = AsBitmap(cbitmap);
+    SkColorTable* ctable = bmp->getColorTable();
+    while (size-- != 0) {
+        const uint8_t* addr = pixels++;
+        const SkPMColor c = (*ctable)[*addr];
+        *colors++ = SkUnPreMultiply::PMColorToColor(c);
+    }
+}
+
 static inline void copyGray8ToColor(size_t size, const uint8_t* pixels, sk_color_t* colors)
 {
     while (size-- != 0) {
@@ -231,6 +242,9 @@ void sk_bitmap_get_pixel_colors(sk_bitmap_t* cbitmap, sk_color_t* colors)
     case kAlpha_8_SkColorType:
         copyAlpha8ToColor(size, (const uint8_t*)pixels, colors);
         break;
+    case kIndex_8_SkColorType:
+        copyIndex8ToColor(cbitmap, size, (const uint8_t*)pixels, colors);
+        break;
     case kGray_8_SkColorType:
         copyGray8ToColor(size, (const uint8_t*)pixels, colors);
         break;
@@ -300,3 +314,9 @@ sk_colortable_t* sk_bitmap_get_colortable(sk_bitmap_t* cbitmap)
 {
     return ToColorTable(AsBitmap(cbitmap)->getColorTable());
 }
+
+void sk_bitmap_set_colortable(sk_bitmap_t* cbitmap, sk_colortable_t* ctable)
+{
+    SkBitmap* bmp AsBitmap(cbitmap);
+    bmp->setPixels(bmp->getPixels(), AsColorTable(ctable));
+}
\ No newline at end of file