Skip to content

Commit

Permalink
Implementation of CGColorSpaceGetColorTableCount & CGColorSpaceGetCol…
Browse files Browse the repository at this point in the history
…orTable with unittests. microsoft#2387
  • Loading branch information
msft-Jeyaram committed Mar 31, 2017
1 parent 451877b commit 08def3b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
19 changes: 12 additions & 7 deletions Frameworks/CoreGraphics/CGColorSpace.mm
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ inline size_t LastColorIndex() const {
return _lastColorIndex;
}

inline void GetTable(uint8_t* table) const {
std::copy(_palette.begin(), _palette.end(), table);
}

private:
CGColorSpaceModel _colorSpaceModel;
woc::StrongCF<CGColorSpaceRef> _baseColorSpace;
Expand Down Expand Up @@ -270,18 +274,19 @@ CGColorSpaceRef CGColorSpaceGetBaseColorSpace(CGColorSpaceRef space) {
}

/**
@Status Stub
@Notes
@Status Interoperable
*/
size_t CGColorSpaceGetColorTableCount(CGColorSpaceRef space) {
UNIMPLEMENTED();
return StubReturn();
RETURN_RESULT_IF_NULL(space, 0);
RETURN_RESULT_IF(space->ColorSpaceModel() != kCGColorSpaceModelIndexed, 0);
return space->LastColorIndex() + 1;
}

/**
@Status Stub
@Notes
@Status Interoperable
*/
void CGColorSpaceGetColorTable(CGColorSpaceRef space, uint8_t* table) {
UNIMPLEMENTED();
RETURN_IF(!space);
RETURN_IF(!table);
return space->GetTable(table);
}
4 changes: 2 additions & 2 deletions include/CoreGraphics/CGColorSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ COREGRAPHICS_EXPORT CFDataRef CGColorSpaceCopyICCProfile(CGColorSpaceRef space)
COREGRAPHICS_EXPORT CFTypeID CGColorSpaceGetTypeID();
COREGRAPHICS_EXPORT CGColorSpaceModel CGColorSpaceGetModel(CGColorSpaceRef space);
COREGRAPHICS_EXPORT CGColorSpaceRef CGColorSpaceGetBaseColorSpace(CGColorSpaceRef space);
COREGRAPHICS_EXPORT size_t CGColorSpaceGetColorTableCount(CGColorSpaceRef space) STUB_METHOD;
COREGRAPHICS_EXPORT void CGColorSpaceGetColorTable(CGColorSpaceRef space, uint8_t* table) STUB_METHOD;
COREGRAPHICS_EXPORT size_t CGColorSpaceGetColorTableCount(CGColorSpaceRef space);
COREGRAPHICS_EXPORT void CGColorSpaceGetColorTable(CGColorSpaceRef space, uint8_t* table);
23 changes: 23 additions & 0 deletions tests/unittests/CoreGraphics/CGColorTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#import <TestFramework.h>
#import <CoreGraphics/CoreGraphics.h>
#import <vector>

// TODO #2243: Remove the UIKit dependency
#if WINOBJC
Expand Down Expand Up @@ -129,3 +130,25 @@
EXPECT_EQ(2, CGColorGetNumberOfComponents(col));
}
}

TEST(CGColor, CGColorSpaceCreateIndexed) {
#if WINOBJC
[UIColor class];
#endif
auto rgbColorSpace = woc::MakeStrongCF<CGColorSpaceRef>(CGColorSpaceCreateDeviceRGB());

static const unsigned char tableVal[] = { 255, 255, 255, 0, 0, 0, 212, 255, 154 };
std::vector<unsigned char> table(tableVal, tableVal + std::extent<decltype(tableVal)>::value);

auto indexColorSpace = woc::MakeStrongCF<CGColorSpaceRef>(CGColorSpaceCreateIndexed(rgbColorSpace, 2, table.data()));
EXPECT_EQ(1, CGColorSpaceGetNumberOfComponents(indexColorSpace));
EXPECT_TRUE(CGColorSpaceGetModel(indexColorSpace) == kCGColorSpaceModelIndexed);

EXPECT_EQ(3, CGColorSpaceGetColorTableCount(indexColorSpace));

std::vector<unsigned char> resultTable(CGColorSpaceGetColorTableCount(indexColorSpace) *
CGColorSpaceGetNumberOfComponents(rgbColorSpace));
CGColorSpaceGetColorTable(indexColorSpace, resultTable.data());

EXPECT_EQ(table, resultTable);
}

0 comments on commit 08def3b

Please sign in to comment.