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

Side by Side Diff: src/ports/SkFontHost_FreeType_common.cpp

Issue 322963002: hide SkBitmap::setConfig (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 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
« no previous file with comments | « src/images/SkScaledBitmapSampler.cpp ('k') | src/ports/SkImageDecoder_CG.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006-2012 The Android Open Source Project 2 * Copyright 2006-2012 The Android Open Source Project
3 * Copyright 2012 Mozilla Foundation 3 * Copyright 2012 Mozilla Foundation
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 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 for (int i = 0; i < leftOverBits; ++i, --shift) { 288 for (int i = 0; i < leftOverBits; ++i, --shift) {
289 bits |= convert_8_to_1(*src++) << shift; 289 bits |= convert_8_to_1(*src++) << shift;
290 } 290 }
291 *dst++ = bits; 291 *dst++ = bits;
292 } 292 }
293 src += srcPad; 293 src += srcPad;
294 dst += dstPad; 294 dst += dstPad;
295 } 295 }
296 } 296 }
297 297
298 inline SkMask::Format SkMaskFormat_for_SkBitmapConfig(SkBitmap::Config config) { 298 inline SkMask::Format SkMaskFormat_for_SkColorType(SkColorType colorType) {
299 switch (config) { 299 switch (colorType) {
300 case SkBitmap::kA8_Config: 300 case kAlpha_8_SkColorType:
301 return SkMask::kA8_Format; 301 return SkMask::kA8_Format;
302 case SkBitmap::kARGB_8888_Config: 302 case kN32_SkColorType:
303 return SkMask::kARGB32_Format; 303 return SkMask::kARGB32_Format;
304 default: 304 default:
305 SkDEBUGFAIL("unsupported SkBitmap::Config"); 305 SkDEBUGFAIL("unsupported SkBitmap::Config");
306 return SkMask::kA8_Format; 306 return SkMask::kA8_Format;
307 } 307 }
308 } 308 }
309 309
310 inline SkBitmap::Config SkBitmapConfig_for_FTPixelMode(FT_Pixel_Mode pixel_mode) { 310 inline SkColorType SkColorType_for_FTPixelMode(FT_Pixel_Mode pixel_mode) {
311 switch (pixel_mode) { 311 switch (pixel_mode) {
312 case FT_PIXEL_MODE_MONO: 312 case FT_PIXEL_MODE_MONO:
313 case FT_PIXEL_MODE_GRAY: 313 case FT_PIXEL_MODE_GRAY:
314 return SkBitmap::kA8_Config; 314 return kAlpha_8_SkColorType;
315 case FT_PIXEL_MODE_BGRA: 315 case FT_PIXEL_MODE_BGRA:
316 return SkBitmap::kARGB_8888_Config; 316 return kN32_SkColorType;
317 default: 317 default:
318 SkDEBUGFAIL("unsupported FT_PIXEL_MODE"); 318 SkDEBUGFAIL("unsupported FT_PIXEL_MODE");
319 return SkBitmap::kA8_Config; 319 return kAlpha_8_SkColorType;
320 } 320 }
321 } 321 }
322 322
323 inline SkBitmap::Config SkBitmapConfig_for_SkMaskFormat(SkMask::Format format) { 323 inline SkColorType SkColorType_for_SkMaskFormat(SkMask::Format format) {
324 switch (format) { 324 switch (format) {
325 case SkMask::kBW_Format: 325 case SkMask::kBW_Format:
326 case SkMask::kA8_Format: 326 case SkMask::kA8_Format:
327 case SkMask::kLCD16_Format: 327 case SkMask::kLCD16_Format:
328 return SkBitmap::kA8_Config; 328 return kAlpha_8_SkColorType;
329 case SkMask::kARGB32_Format: 329 case SkMask::kARGB32_Format:
330 return SkBitmap::kARGB_8888_Config; 330 return kN32_SkColorType;
331 default: 331 default:
332 SkDEBUGFAIL("unsupported destination SkBitmap::Config"); 332 SkDEBUGFAIL("unsupported destination SkBitmap::Config");
333 return SkBitmap::kA8_Config; 333 return kAlpha_8_SkColorType;
334 } 334 }
335 } 335 }
336 336
337 void SkScalerContext_FreeType_Base::generateGlyphImage(FT_Face face, const SkGly ph& glyph) { 337 void SkScalerContext_FreeType_Base::generateGlyphImage(FT_Face face, const SkGly ph& glyph) {
338 const bool doBGR = SkToBool(fRec.fFlags & SkScalerContext::kLCD_BGROrder_Fla g); 338 const bool doBGR = SkToBool(fRec.fFlags & SkScalerContext::kLCD_BGROrder_Fla g);
339 const bool doVert = SkToBool(fRec.fFlags & SkScalerContext::kLCD_Vertical_Fl ag); 339 const bool doVert = SkToBool(fRec.fFlags & SkScalerContext::kLCD_Vertical_Fl ag);
340 340
341 switch ( face->glyph->format ) { 341 switch ( face->glyph->format ) {
342 case FT_GLYPH_FORMAT_OUTLINE: { 342 case FT_GLYPH_FORMAT_OUTLINE: {
343 FT_Outline* outline = &face->glyph->outline; 343 FT_Outline* outline = &face->glyph->outline;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 SkMask dstMask; 419 SkMask dstMask;
420 glyph.toMask(&dstMask); 420 glyph.toMask(&dstMask);
421 copyFTBitmap(face->glyph->bitmap, dstMask); 421 copyFTBitmap(face->glyph->bitmap, dstMask);
422 break; 422 break;
423 } 423 }
424 424
425 // Otherwise, scale the bitmap. 425 // Otherwise, scale the bitmap.
426 426
427 // Copy the FT_Bitmap into an SkBitmap (either A8 or ARGB) 427 // Copy the FT_Bitmap into an SkBitmap (either A8 or ARGB)
428 SkBitmap unscaledBitmap; 428 SkBitmap unscaledBitmap;
429 unscaledBitmap.setConfig(SkBitmapConfig_for_FTPixelMode(pixel_mode), 429 unscaledBitmap.allocPixels(SkImageInfo::Make(face->glyph->bitmap.wid th,
430 face->glyph->bitmap.width, face->glyph->bit map.rows); 430 face->glyph->bitmap.row s,
431 unscaledBitmap.allocPixels(); 431 SkColorType_for_FTPixel Mode(pixel_mode),
432 kPremul_SkAlphaType));
432 433
433 SkMask unscaledBitmapAlias; 434 SkMask unscaledBitmapAlias;
434 unscaledBitmapAlias.fImage = reinterpret_cast<uint8_t*>(unscaledBitm ap.getPixels()); 435 unscaledBitmapAlias.fImage = reinterpret_cast<uint8_t*>(unscaledBitm ap.getPixels());
435 unscaledBitmapAlias.fBounds.set(0, 0, unscaledBitmap.width(), unscal edBitmap.height()); 436 unscaledBitmapAlias.fBounds.set(0, 0, unscaledBitmap.width(), unscal edBitmap.height());
436 unscaledBitmapAlias.fRowBytes = unscaledBitmap.rowBytes(); 437 unscaledBitmapAlias.fRowBytes = unscaledBitmap.rowBytes();
437 unscaledBitmapAlias.fFormat = SkMaskFormat_for_SkBitmapConfig(unscal edBitmap.config()); 438 unscaledBitmapAlias.fFormat = SkMaskFormat_for_SkColorType(unscaledB itmap.colorType());
438 copyFTBitmap(face->glyph->bitmap, unscaledBitmapAlias); 439 copyFTBitmap(face->glyph->bitmap, unscaledBitmapAlias);
439 440
440 // Wrap the glyph's mask in a bitmap, unless the glyph's mask is BW or LCD. 441 // Wrap the glyph's mask in a bitmap, unless the glyph's mask is BW or LCD.
441 // BW requires an A8 target for resizing, which can then be down sam pled. 442 // BW requires an A8 target for resizing, which can then be down sam pled.
442 // LCD should use a 4x A8 target, which will then be down sampled. 443 // LCD should use a 4x A8 target, which will then be down sampled.
443 // For simplicity, LCD uses A8 and is replicated. 444 // For simplicity, LCD uses A8 and is replicated.
444 int bitmapRowBytes = 0; 445 int bitmapRowBytes = 0;
445 if (SkMask::kBW_Format != maskFormat && SkMask::kLCD16_Format != mas kFormat) { 446 if (SkMask::kBW_Format != maskFormat && SkMask::kLCD16_Format != mas kFormat) {
446 bitmapRowBytes = glyph.rowBytes(); 447 bitmapRowBytes = glyph.rowBytes();
447 } 448 }
448 SkBitmap dstBitmap; 449 SkBitmap dstBitmap;
449 dstBitmap.setConfig(SkBitmapConfig_for_SkMaskFormat(maskFormat), 450 dstBitmap.setInfo(SkImageInfo::Make(glyph.fWidth, glyph.fHeight,
450 glyph.fWidth, glyph.fHeight, bitmapRowBytes); 451 SkColorType_for_SkMaskFormat(mas kFormat),
452 kPremul_SkAlphaType),
453 bitmapRowBytes);
451 if (SkMask::kBW_Format == maskFormat || SkMask::kLCD16_Format == mas kFormat) { 454 if (SkMask::kBW_Format == maskFormat || SkMask::kLCD16_Format == mas kFormat) {
452 dstBitmap.allocPixels(); 455 dstBitmap.allocPixels();
453 } else { 456 } else {
454 dstBitmap.setPixels(glyph.fImage); 457 dstBitmap.setPixels(glyph.fImage);
455 } 458 }
456 459
457 // Scale unscaledBitmap into dstBitmap. 460 // Scale unscaledBitmap into dstBitmap.
458 SkCanvas canvas(dstBitmap); 461 SkCanvas canvas(dstBitmap);
459 canvas.clear(SK_ColorTRANSPARENT); 462 canvas.clear(SK_ColorTRANSPARENT);
460 canvas.scale(SkIntToScalar(glyph.fWidth) / SkIntToScalar(face->glyph ->bitmap.width), 463 canvas.scale(SkIntToScalar(glyph.fWidth) / SkIntToScalar(face->glyph ->bitmap.width),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 556
554 FT_Error err = FT_Outline_Decompose(&face->glyph->outline, &funcs, path); 557 FT_Error err = FT_Outline_Decompose(&face->glyph->outline, &funcs, path);
555 558
556 if (err != 0) { 559 if (err != 0) {
557 path->reset(); 560 path->reset();
558 return; 561 return;
559 } 562 }
560 563
561 path->close(); 564 path->close();
562 } 565 }
OLDNEW
« no previous file with comments | « src/images/SkScaledBitmapSampler.cpp ('k') | src/ports/SkImageDecoder_CG.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698