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

Side by Side Diff: ui/gfx/codec/jpeg_codec.cc

Issue 1879443002: JPEG decoding: replace ownership comments with std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fixes Created 4 years, 8 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 | « ui/gfx/codec/jpeg_codec.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/codec/jpeg_codec.h" 5 #include "ui/gfx/codec/jpeg_codec.h"
6 6
7 #include <setjmp.h> 7 #include <setjmp.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 } 596 }
597 } 597 }
598 #endif 598 #endif
599 599
600 jpeg_finish_decompress(&cinfo); 600 jpeg_finish_decompress(&cinfo);
601 jpeg_destroy_decompress(&cinfo); 601 jpeg_destroy_decompress(&cinfo);
602 return true; 602 return true;
603 } 603 }
604 604
605 // static 605 // static
606 SkBitmap* JPEGCodec::Decode(const unsigned char* input, size_t input_size) { 606 std::unique_ptr<SkBitmap> JPEGCodec::Decode(const unsigned char* input,
607 size_t input_size) {
607 int w, h; 608 int w, h;
608 std::vector<unsigned char> data_vector; 609 std::vector<unsigned char> data_vector;
609 if (!Decode(input, input_size, FORMAT_SkBitmap, &data_vector, &w, &h)) 610 if (!Decode(input, input_size, FORMAT_SkBitmap, &data_vector, &w, &h))
610 return NULL; 611 return nullptr;
611 612
612 // Skia only handles 32 bit images. 613 // Skia only handles 32 bit images.
613 int data_length = w * h * 4; 614 int data_length = w * h * 4;
614 615
615 SkBitmap* bitmap = new SkBitmap(); 616 std::unique_ptr<SkBitmap> bitmap(new SkBitmap());
616 bitmap->allocN32Pixels(w, h); 617 bitmap->allocN32Pixels(w, h);
617 memcpy(bitmap->getAddr32(0, 0), &data_vector[0], data_length); 618 memcpy(bitmap->getAddr32(0, 0), &data_vector[0], data_length);
618 619
619 return bitmap; 620 return bitmap;
620 } 621 }
621 622
622 } // namespace gfx 623 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/codec/jpeg_codec.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698