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

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, 1 month 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/SkImageDecoder_libjpeg.h ('k') | src/images/SkImageDecoder_libpng.h » ('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 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 #include "SkImageDecoder_libjpeg.h"
9 #include "SkImageDecoder.h"
10 #include "SkImageEncoder.h"
11 #include "SkJpegUtility.h"
12 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
13 #include "SkDither.h" 10 #include "SkDither.h"
11 #include "SkJpegUtility.h"
14 #include "SkScaledBitmapSampler.h" 12 #include "SkScaledBitmapSampler.h"
15 #include "SkStream.h" 13 #include "SkStream.h"
16 #include "SkTemplates.h" 14 #include "SkTemplates.h"
17 #include "SkTime.h" 15 #include "SkTime.h"
18 #include "SkUtils.h" 16 #include "SkUtils.h"
19 #include "SkRTConf.h" 17 #include "SkRTConf.h"
20 #include "SkRect.h" 18 #include "SkRect.h"
21 #include "SkCanvas.h" 19 #include "SkCanvas.h"
22 20
23 21
(...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 srcRow = (const void*)((const char*)srcRow + bm.rowBytes()); 1402 srcRow = (const void*)((const char*)srcRow + bm.rowBytes());
1405 } 1403 }
1406 1404
1407 jpeg_finish_compress(&cinfo); 1405 jpeg_finish_compress(&cinfo);
1408 jpeg_destroy_compress(&cinfo); 1406 jpeg_destroy_compress(&cinfo);
1409 1407
1410 return true; 1408 return true;
1411 } 1409 }
1412 }; 1410 };
1413 1411
1414 /////////////////////////////////////////////////////////////////////////////// 1412 SkImageDecoder::Format SkDetectFormatJPEGImageDecoder(SkStreamRewindable* stream ) {
1415 DEFINE_DECODER_CREATOR(JPEGImageDecoder);
1416 DEFINE_ENCODER_CREATOR(JPEGImageEncoder);
1417 ///////////////////////////////////////////////////////////////////////////////
1418
1419 static bool is_jpeg(SkStreamRewindable* stream) {
1420 static const unsigned char gHeader[] = { 0xFF, 0xD8, 0xFF }; 1413 static const unsigned char gHeader[] = { 0xFF, 0xD8, 0xFF };
1421 static const size_t HEADER_SIZE = sizeof(gHeader); 1414 static const size_t HEADER_SIZE = sizeof(gHeader);
1422 1415
1423 char buffer[HEADER_SIZE]; 1416 char buffer[HEADER_SIZE];
1424 size_t len = stream->read(buffer, HEADER_SIZE); 1417 size_t len = stream->read(buffer, HEADER_SIZE);
1425 1418
1426 if (len != HEADER_SIZE) { 1419 if (len != HEADER_SIZE) {
1427 return false; // can't read enough 1420 return SkImageDecoder::kUnknown_Format; // can't read enough
1428 } 1421 }
1429 if (memcmp(buffer, gHeader, HEADER_SIZE)) { 1422 if (memcmp(buffer, gHeader, HEADER_SIZE)) {
1430 return false; 1423 return SkImageDecoder::kUnknown_Format;
1431 } 1424 }
1432 return true; 1425 return SkImageDecoder::kJPEG_Format;
1433 } 1426 }
1434 1427
1435 1428 SkImageDecoder* SkCreateJPEGImageDecoder(SkImageDecoder::Format format) {
1436 static SkImageDecoder* sk_libjpeg_dfactory(SkStreamRewindable* stream) { 1429 SkASSERT(SkImageDecoder::kJPEG_Format == format);
1437 if (is_jpeg(stream)) { 1430 return SkNEW(SkJPEGImageDecoder);
1438 return SkNEW(SkJPEGImageDecoder);
1439 }
1440 return NULL;
1441 } 1431 }
1442 1432
1443 static SkImageDecoder::Format get_format_jpeg(SkStreamRewindable* stream) { 1433 SkImageEncoder* SkCreateJPEGImageEncoder(SkImageEncoder::Type t) {
1444 if (is_jpeg(stream)) {
1445 return SkImageDecoder::kJPEG_Format;
1446 }
1447 return SkImageDecoder::kUnknown_Format;
1448 }
1449
1450 static SkImageEncoder* sk_libjpeg_efactory(SkImageEncoder::Type t) {
1451 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL; 1434 return (SkImageEncoder::kJPEG_Type == t) ? SkNEW(SkJPEGImageEncoder) : NULL;
1452 } 1435 }
1453
1454 static SkImageDecoder_DecodeReg gDReg(sk_libjpeg_dfactory);
1455 static SkImageDecoder_FormatReg gFormatReg(get_format_jpeg);
1456 static SkImageEncoder_EncodeReg gEReg(sk_libjpeg_efactory);
OLDNEW
« no previous file with comments | « src/images/SkImageDecoder_libjpeg.h ('k') | src/images/SkImageDecoder_libpng.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698