Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CGColorSpaceGetColorTable(+Count) & Tests #2397

Merged
merged 2 commits into from
Apr 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd prefer CopyColorTable or CopyColorTableToBuffer

}
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);
}