OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/png_codec.h" | 5 #include "ui/gfx/codec/png_codec.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 return false; | 705 return false; |
706 } | 706 } |
707 | 707 |
708 // Row stride should be at least as long as the length of the data. | 708 // Row stride should be at least as long as the length of the data. |
709 DCHECK(input_color_components * size.width() <= row_byte_width); | 709 DCHECK(input_color_components * size.width() <= row_byte_width); |
710 | 710 |
711 png_struct* png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, | 711 png_struct* png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, |
712 NULL, NULL, NULL); | 712 NULL, NULL, NULL); |
713 if (!png_ptr) | 713 if (!png_ptr) |
714 return false; | 714 return false; |
715 // info_ptr should have wider lifetime scope than destroyer that access it | |
Nico
2016/12/14 20:11:29
nit: i'd add a comma at the end of this line to re
krasin1
2016/12/14 20:56:59
Done.
| |
716 // to avoid use-after-scope bugs. | |
717 png_info* info_ptr; | |
715 PngWriteStructDestroyer destroyer(&png_ptr); | 718 PngWriteStructDestroyer destroyer(&png_ptr); |
716 png_info* info_ptr = png_create_info_struct(png_ptr); | 719 info_ptr = png_create_info_struct(png_ptr); |
717 if (!info_ptr) | 720 if (!info_ptr) |
718 return false; | 721 return false; |
719 destroyer.SetInfoStruct(&info_ptr); | 722 destroyer.SetInfoStruct(&info_ptr); |
720 | 723 |
721 output->clear(); | 724 output->clear(); |
722 | 725 |
723 PngEncoderState state(output); | 726 PngEncoderState state(output); |
724 bool success = DoLibpngWrite(png_ptr, info_ptr, &state, | 727 bool success = DoLibpngWrite(png_ptr, info_ptr, &state, |
725 size.width(), size.height(), row_byte_width, | 728 size.width(), size.height(), row_byte_width, |
726 input, compression_level, png_output_color_type, | 729 input, compression_level, png_output_color_type, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 } | 807 } |
805 | 808 |
806 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) | 809 PNGCodec::Comment::Comment(const std::string& k, const std::string& t) |
807 : key(k), text(t) { | 810 : key(k), text(t) { |
808 } | 811 } |
809 | 812 |
810 PNGCodec::Comment::~Comment() { | 813 PNGCodec::Comment::~Comment() { |
811 } | 814 } |
812 | 815 |
813 } // namespace gfx | 816 } // namespace gfx |
OLD | NEW |