static SkPDFArray* make_indexed_color_space(const SkColorTable* table) { SkPDFArray* result = new SkPDFArray; result->reserve(4); result->appendName("Indexed"); result->appendName("DeviceRGB"); SkASSERT(table); if (table->count() < 1) { result->appendInt(0); char shortTableArray[3] = {0, 0, 0}; SkString tableString(shortTableArray, SK_ARRAY_COUNT(shortTableArray)); result->appendString(tableString); return result; } result->appendInt(table->count() - 1); // maximum color index. // Potentially, this could be represented in fewer bytes with a stream. // Max size as a string is 1.5k. char tableArray[256 * 3]; SkASSERT(3u * table->count() <= SK_ARRAY_COUNT(tableArray)); uint8_t* tablePtr = reinterpret_cast<uint8_t*>(tableArray); const SkPMColor* colors = table->readColors(); for (int i = 0; i < table->count(); i++) { pmcolor_to_rgb24(colors[i], tablePtr); tablePtr += 3; } SkString tableString(tableArray, 3 * table->count()); result->appendString(tableString); return result; }
//static SkPDFArray* SkPDFUtils::RectToArray(const SkRect& rect) { SkPDFArray* result = new SkPDFArray(); result->reserve(4); result->appendScalar(rect.fLeft); result->appendScalar(rect.fTop); result->appendScalar(rect.fRight); result->appendScalar(rect.fBottom); return result; }
// static SkPDFArray* SkPDFUtils::MatrixToArray(const SkMatrix& matrix) { SkScalar values[6]; SkAssertResult(matrix.pdfTransform(values)); SkPDFArray* result = new SkPDFArray; result->reserve(6); for (size_t i = 0; i < SK_ARRAY_COUNT(values); i++) { result->append(new SkPDFScalar(values[i]))->unref(); } return result; }
// static SkPDFArray* SkPDFUtils::MatrixToArray(const SkMatrix& matrix) { SkScalar values[6]; if (!matrix.asAffine(values)) { SkMatrix::SetAffineIdentity(values); } SkPDFArray* result = new SkPDFArray; result->reserve(6); for (size_t i = 0; i < SK_ARRAY_COUNT(values); i++) { result->appendScalar(values[i]); } return result; }
static SkPDFArray* make_indexed_color_space(SkColorTable* table) { SkPDFArray* result = new SkPDFArray(); result->reserve(4); result->appendName("Indexed"); result->appendName("DeviceRGB"); result->appendInt(table->count() - 1); // Potentially, this could be represented in fewer bytes with a stream. // Max size as a string is 1.5k. SkString index; for (int i = 0; i < table->count(); i++) { char buf[3]; SkColor color = SkUnPreMultiply::PMColorToColor((*table)[i]); buf[0] = SkGetPackedR32(color); buf[1] = SkGetPackedG32(color); buf[2] = SkGetPackedB32(color); index.append(buf, 3); } result->append(new SkPDFString(index))->unref(); return result; }