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

Side by Side Diff: src/images/SkImageDecoder_libjpeg.cpp

Issue 670453002: Remove image decoder and encoder autoregistration (Closed) Base URL: https://skia.googlesource.com/skia.git@separate-image-decoder-01-skpicture
Patch Set: Created 6 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright 2007 The Android Open Source Project 2 * Copyright 2007 The Android Open Source Project
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 7
8 8
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder_libjpeg.h"
10 #include "SkImageEncoder.h" 10
11 #include "SkJpegUtility.h" 11 #include "SkJpegUtility.h"
12 #include "SkColorPriv.h" 12 #include "SkColorPriv.h"
13 #include "SkDither.h" 13 #include "SkDither.h"
14 #include "SkScaledBitmapSampler.h" 14 #include "SkScaledBitmapSampler.h"
15 #include "SkStream.h" 15 #include "SkStream.h"
16 #include "SkTemplates.h" 16 #include "SkTemplates.h"
17 #include "SkTime.h" 17 #include "SkTime.h"
18 #include "SkUtils.h" 18 #include "SkUtils.h"
19 #include "SkRTConf.h" 19 #include "SkRTConf.h"
20 #include "SkRect.h" 20 #include "SkRect.h"
(...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 return Write_16_YUV; 1364 return Write_16_YUV;
1365 case kARGB_4444_SkColorType: 1365 case kARGB_4444_SkColorType:
1366 return Write_4444_YUV; 1366 return Write_4444_YUV;
1367 case kIndex_8_SkColorType: 1367 case kIndex_8_SkColorType:
1368 return Write_Index_YUV; 1368 return Write_Index_YUV;
1369 default: 1369 default:
1370 return NULL; 1370 return NULL;
1371 } 1371 }
1372 } 1372 }
1373 1373
1374 SkImageDecoder::Format SkDetectFormatJPEGImageDecoder(SkStreamRewindable* stream ) {
scroggo 2014/11/12 18:00:12 nit: The change is easier to follow without moving
Kimmo Kinnunen 2014/11/18 08:29:45 Done.
1375 static const unsigned char gHeader[] = { 0xFF, 0xD8, 0xFF };
1376 static const size_t HEADER_SIZE = sizeof(gHeader);
1377
1378 char buffer[HEADER_SIZE];
1379 size_t len = stream->read(buffer, HEADER_SIZE);
1380
1381 if (len != HEADER_SIZE) {
1382 return SkImageDecoder::kUnknown_Format; // can't read enough
1383 }
1384 if (memcmp(buffer, gHeader, HEADER_SIZE)) {
1385 return SkImageDecoder::kUnknown_Format;
1386 }
1387 return SkImageDecoder::kJPEG_Format;
1388 }
1389
1390 SkImageDecoder* SkCreateJPEGImageDecoder(SkStreamRewindable* stream) {
1391 if (SkDetectFormatJPEGImageDecoder(stream) == SkImageDecoder::kJPEG_Format) {
1392 return SkNEW(SkJPEGImageDecoder);
1393 }
1394 return NULL;
1395 }
1396
1374 class SkJPEGImageEncoder : public SkImageEncoder { 1397 class SkJPEGImageEncoder : public SkImageEncoder {
1375 protected: 1398 protected:
1376 virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) { 1399 virtual bool onEncode(SkWStream* stream, const SkBitmap& bm, int quality) {
1377 #ifdef TIME_ENCODE 1400 #ifdef TIME_ENCODE
1378 SkAutoTime atm("JPEG Encode"); 1401 SkAutoTime atm("JPEG Encode");
1379 #endif 1402 #endif
1380 1403
1381 SkAutoLockPixels alp(bm); 1404 SkAutoLockPixels alp(bm);
1382 if (NULL == bm.getPixels()) { 1405 if (NULL == bm.getPixels()) {
1383 return false; 1406 return false;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 srcRow = (const void*)((const char*)srcRow + bm.rowBytes()); 1461 srcRow = (const void*)((const char*)srcRow + bm.rowBytes());
1439 } 1462 }
1440 1463
1441 jpeg_finish_compress(&cinfo); 1464 jpeg_finish_compress(&cinfo);
1442 jpeg_destroy_compress(&cinfo); 1465 jpeg_destroy_compress(&cinfo);
1443 1466
1444 return true; 1467 return true;
1445 } 1468 }
1446 }; 1469 };
1447 1470
1448 /////////////////////////////////////////////////////////////////////////////// 1471 SkImageEncoder* SkCreateJPEGImageEncoder(SkImageEncoder::Type t) {
1449 DEFINE_DECODER_CREATOR(JPEGImageDecoder);
1450 DEFINE_ENCODER_CREATOR(JPEGImageEncoder);
1451 ///////////////////////////////////////////////////////////////////////////////
1452
1453 static bool is_jpeg(SkStreamRewindable* stream) {
1454 static const unsigned char gHeader[] = { 0xFF, 0xD8, 0xFF };
1455 static const size_t HEADER_SIZE = sizeof(gHeader);
1456
1457 char buffer[HEADER_SIZE];
1458 size_t len = stream->read(buffer, HEADER_SIZE);
1459
1460 if (len != HEADER_SIZE) {
1461 return false; // can't read enough
1462 }
1463 if (memcmp(buffer, gHeader, HEADER_SIZE)) {
1464 return false;
1465 }
1466 return true;
1467 }
1468
1469
1470 static SkImageDecoder* sk_libjpeg_dfactory(SkStreamRewindable* stream) {
1471 if (is_jpeg(stream)) {
1472 return SkNEW(SkJPEGImageDecoder);
1473 }
1474 return NULL;
1475 }
1476
1477 static SkImageDecoder::Format get_format_jpeg(SkStreamRewindable* stream) {
1478 if (is_jpeg(stream)) {
1479 return SkImageDecoder::kJPEG_Format;
1480 }
1481 return SkImageDecoder::kUnknown_Format;
1482 }
1483
1484 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) {
1485 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; 1472 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL;
1486 } 1473 }
1487
1488 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory);
1489 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg);
1490 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698