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

Side by Side Diff: samplecode/SampleApp.cpp

Issue 169063002: use SkColorType instead of SkBitmap::Config in samplecode (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « samplecode/SampleAARects.cpp ('k') | samplecode/SampleBitmapRect.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 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SampleApp.h" 7 #include "SampleApp.h"
8 8
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 paint.setColor(SK_ColorBLUE); 1356 paint.setColor(SK_ColorBLUE);
1357 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint); 1357 drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
1358 canvas->restoreToCount(count); 1358 canvas->restoreToCount(count);
1359 } 1359 }
1360 1360
1361 void SampleWindow::onDraw(SkCanvas* canvas) { 1361 void SampleWindow::onDraw(SkCanvas* canvas) {
1362 } 1362 }
1363 1363
1364 #include "SkColorPriv.h" 1364 #include "SkColorPriv.h"
1365 1365
1366 #if 0 // UNUSED
1367 static void reverseRedAndBlue(const SkBitmap& bm) {
1368 SkASSERT(bm.config() == SkBitmap::kARGB_8888_Config);
1369 uint8_t* p = (uint8_t*)bm.getPixels();
1370 uint8_t* stop = p + bm.getSize();
1371 while (p < stop) {
1372 // swap red/blue (to go from ARGB(int) to RGBA(memory) and premultiply
1373 unsigned scale = SkAlpha255To256(p[3]);
1374 unsigned r = p[2];
1375 unsigned b = p[0];
1376 p[0] = SkAlphaMul(r, scale);
1377 p[1] = SkAlphaMul(p[1], scale);
1378 p[2] = SkAlphaMul(b, scale);
1379 p += 4;
1380 }
1381 }
1382 #endif
1383
1384 void SampleWindow::saveToPdf() 1366 void SampleWindow::saveToPdf()
1385 { 1367 {
1386 fSaveToPdf = true; 1368 fSaveToPdf = true;
1387 this->inval(NULL); 1369 this->inval(NULL);
1388 } 1370 }
1389 1371
1390 SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) { 1372 SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) {
1391 if (fSaveToPdf) { 1373 if (fSaveToPdf) {
1392 const SkBitmap& bmp = canvas->getDevice()->accessBitmap(false); 1374 const SkBitmap& bmp = canvas->getDevice()->accessBitmap(false);
1393 SkISize size = SkISize::Make(bmp.width(), bmp.height()); 1375 SkISize size = SkISize::Make(bmp.width(), bmp.height());
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 static SkColorType gColorTypeCycle[] = { 1551 static SkColorType gColorTypeCycle[] = {
1570 kUnknown_SkColorType, // none -> none 1552 kUnknown_SkColorType, // none -> none
1571 kUnknown_SkColorType, // a8 -> none 1553 kUnknown_SkColorType, // a8 -> none
1572 kARGB_4444_SkColorType, // 565 -> 4444 1554 kARGB_4444_SkColorType, // 565 -> 4444
1573 kPMColor_SkColorType, // 4444 -> 8888 1555 kPMColor_SkColorType, // 4444 -> 8888
1574 kRGB_565_SkColorType, // 8888 -> 565 1556 kRGB_565_SkColorType, // 8888 -> 565
1575 kRGB_565_SkColorType, // 8888 -> 565 1557 kRGB_565_SkColorType, // 8888 -> 565
1576 kUnknown_SkColorType, // index8 -> none 1558 kUnknown_SkColorType, // index8 -> none
1577 }; 1559 };
1578 1560
1579 static SkColorType cycle_configs(SkColorType c) { 1561 static SkColorType cycle_colortypes(SkColorType c) {
1580 return gColorTypeCycle[c]; 1562 return gColorTypeCycle[c];
1581 } 1563 }
1582 1564
1583 void SampleWindow::changeZoomLevel(float delta) { 1565 void SampleWindow::changeZoomLevel(float delta) {
1584 fZoomLevel += delta; 1566 fZoomLevel += delta;
1585 if (fZoomLevel > 0) { 1567 if (fZoomLevel > 0) {
1586 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL); 1568 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL);
1587 fZoomScale = fZoomLevel + SK_Scalar1; 1569 fZoomScale = fZoomLevel + SK_Scalar1;
1588 } else if (fZoomLevel < 0) { 1570 } else if (fZoomLevel < 0) {
1589 fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL); 1571 fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL);
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 } else { 1949 } else {
1968 fNClip = !fNClip; 1950 fNClip = !fNClip;
1969 this->inval(NULL); 1951 this->inval(NULL);
1970 this->updateTitle(); 1952 this->updateTitle();
1971 } 1953 }
1972 return true; 1954 return true;
1973 case kDown_SkKey: 1955 case kDown_SkKey:
1974 if (USE_ARROWS_FOR_ZOOM) { 1956 if (USE_ARROWS_FOR_ZOOM) {
1975 this->changeZoomLevel(-1.f / 32.f); 1957 this->changeZoomLevel(-1.f / 32.f);
1976 } else { 1958 } else {
1977 this->setColorType(cycle_configs(this->getBitmap().colorType())) ; 1959 this->setColorType(cycle_colortypes(this->getBitmap().colorType( )));
1978 this->updateTitle(); 1960 this->updateTitle();
1979 } 1961 }
1980 return true; 1962 return true;
1981 case kOK_SkKey: { 1963 case kOK_SkKey: {
1982 SkString title; 1964 SkString title;
1983 if (curr_title(this, &title)) { 1965 if (curr_title(this, &title)) {
1984 writeTitleToPrefs(title.c_str()); 1966 writeTitleToPrefs(title.c_str());
1985 } 1967 }
1986 return true; 1968 return true;
1987 } 1969 }
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
2580 SkGraphics::Init(); 2562 SkGraphics::Init();
2581 SkEvent::Init(); 2563 SkEvent::Init();
2582 } 2564 }
2583 2565
2584 // FIXME: this should be in a header 2566 // FIXME: this should be in a header
2585 void application_term(); 2567 void application_term();
2586 void application_term() { 2568 void application_term() {
2587 SkEvent::Term(); 2569 SkEvent::Term();
2588 SkGraphics::Term(); 2570 SkGraphics::Term();
2589 } 2571 }
OLDNEW
« no previous file with comments | « samplecode/SampleAARects.cpp ('k') | samplecode/SampleBitmapRect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698