OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 | 7 |
8 #include "SkCodec.h" | 8 #include "SkCodec.h" |
9 #include "SkJpegCodec.h" | 9 #include "SkJpegCodec.h" |
10 #include "SkJpegDecoderMgr.h" | 10 #include "SkJpegDecoderMgr.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 static const uint8_t jpegSig[] = { 0xFF, 0xD8, 0xFF }; | 94 static const uint8_t jpegSig[] = { 0xFF, 0xD8, 0xFF }; |
95 char buffer[sizeof(jpegSig)]; | 95 char buffer[sizeof(jpegSig)]; |
96 return stream->read(buffer, sizeof(jpegSig)) == sizeof(jpegSig) && | 96 return stream->read(buffer, sizeof(jpegSig)) == sizeof(jpegSig) && |
97 !memcmp(buffer, jpegSig, sizeof(jpegSig)); | 97 !memcmp(buffer, jpegSig, sizeof(jpegSig)); |
98 } | 98 } |
99 | 99 |
100 bool SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut, | 100 bool SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut, |
101 JpegDecoderMgr** decoderMgrOut) { | 101 JpegDecoderMgr** decoderMgrOut) { |
102 | 102 |
103 // Create a JpegDecoderMgr to own all of the decompress information | 103 // Create a JpegDecoderMgr to own all of the decompress information |
104 SkAutoTDelete<JpegDecoderMgr> decoderMgr(SkNEW_ARGS(JpegDecoderMgr, (stream)
)); | 104 SkAutoTDelete<JpegDecoderMgr> decoderMgr(new JpegDecoderMgr(stream)); |
105 | 105 |
106 // libjpeg errors will be caught and reported here | 106 // libjpeg errors will be caught and reported here |
107 if (setjmp(decoderMgr->getJmpBuf())) { | 107 if (setjmp(decoderMgr->getJmpBuf())) { |
108 return decoderMgr->returnFalse("setjmp"); | 108 return decoderMgr->returnFalse("setjmp"); |
109 } | 109 } |
110 | 110 |
111 // Initialize the decompress info and the source manager | 111 // Initialize the decompress info and the source manager |
112 decoderMgr->init(); | 112 decoderMgr->init(); |
113 | 113 |
114 // Read the jpeg header | 114 // Read the jpeg header |
115 if (JPEG_HEADER_OK != chromium_jpeg_read_header(decoderMgr->dinfo(), true))
{ | 115 if (JPEG_HEADER_OK != chromium_jpeg_read_header(decoderMgr->dinfo(), true))
{ |
116 return decoderMgr->returnFalse("read_header"); | 116 return decoderMgr->returnFalse("read_header"); |
117 } | 117 } |
118 | 118 |
119 if (NULL != codecOut) { | 119 if (NULL != codecOut) { |
120 // Recommend the color type to decode to | 120 // Recommend the color type to decode to |
121 const SkColorType colorType = decoderMgr->getColorType(); | 121 const SkColorType colorType = decoderMgr->getColorType(); |
122 | 122 |
123 // Create image info object and the codec | 123 // Create image info object and the codec |
124 const SkImageInfo& imageInfo = SkImageInfo::Make(decoderMgr->dinfo()->im
age_width, | 124 const SkImageInfo& imageInfo = SkImageInfo::Make(decoderMgr->dinfo()->im
age_width, |
125 decoderMgr->dinfo()->image_height, colorType, kOpaque_SkAlphaTyp
e); | 125 decoderMgr->dinfo()->image_height, colorType, kOpaque_SkAlphaTyp
e); |
126 *codecOut = SkNEW_ARGS(SkJpegCodec, (imageInfo, stream, decoderMgr.detac
h())); | 126 *codecOut = new SkJpegCodec(imageInfo, stream, decoderMgr.detach()); |
127 } else { | 127 } else { |
128 SkASSERT(NULL != decoderMgrOut); | 128 SkASSERT(NULL != decoderMgrOut); |
129 *decoderMgrOut = decoderMgr.detach(); | 129 *decoderMgrOut = decoderMgr.detach(); |
130 } | 130 } |
131 return true; | 131 return true; |
132 } | 132 } |
133 | 133 |
134 SkCodec* SkJpegCodec::NewFromStream(SkStream* stream) { | 134 SkCodec* SkJpegCodec::NewFromStream(SkStream* stream) { |
135 SkAutoTDelete<SkStream> streamDeleter(stream); | 135 SkAutoTDelete<SkStream> streamDeleter(stream); |
136 SkCodec* codec = NULL; | 136 SkCodec* codec = NULL; |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 | 579 |
580 SkScanlineDecoder* SkJpegCodec::NewSDFromStream(SkStream* stream) { | 580 SkScanlineDecoder* SkJpegCodec::NewSDFromStream(SkStream* stream) { |
581 SkAutoTDelete<SkJpegCodec> codec(static_cast<SkJpegCodec*>(SkJpegCodec::NewF
romStream(stream))); | 581 SkAutoTDelete<SkJpegCodec> codec(static_cast<SkJpegCodec*>(SkJpegCodec::NewF
romStream(stream))); |
582 if (!codec) { | 582 if (!codec) { |
583 return NULL; | 583 return NULL; |
584 } | 584 } |
585 | 585 |
586 const SkImageInfo& srcInfo = codec->getInfo(); | 586 const SkImageInfo& srcInfo = codec->getInfo(); |
587 | 587 |
588 // Return the new scanline decoder | 588 // Return the new scanline decoder |
589 return SkNEW_ARGS(SkJpegScanlineDecoder, (srcInfo, codec.detach())); | 589 return new SkJpegScanlineDecoder(srcInfo, codec.detach()); |
590 } | 590 } |
OLD | NEW |