 Chromium Code Reviews
 Chromium Code Reviews Issue 145873006:
  ui/base/resource: Roll our own version of ReadBigEndian() function.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 145873006:
  ui/base/resource: Roll our own version of ReadBigEndian() function.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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/base/resource/resource_bundle.h" | 5 #include "ui/base/resource/resource_bundle.h" | 
| 6 | 6 | 
| 7 #include <vector> | 7 #include <vector> | 
| 8 | 8 | 
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" | 
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" | 
| 11 #include "base/logging.h" | 11 #include "base/logging.h" | 
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" | 
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" | 
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" | 
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" | 
| 16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" | 
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" | 
| 18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" | 
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" | 
| 20 #include "grit/app_locale_settings.h" | 20 #include "grit/app_locale_settings.h" | 
| 21 #include "net/base/big_endian.h" | |
| 22 #include "skia/ext/image_operations.h" | 21 #include "skia/ext/image_operations.h" | 
| 23 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" | 
| 24 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" | 
| 25 #include "ui/base/layout.h" | 24 #include "ui/base/layout.h" | 
| 26 #include "ui/base/resource/data_pack.h" | 25 #include "ui/base/resource/data_pack.h" | 
| 27 #include "ui/base/ui_base_paths.h" | 26 #include "ui/base/ui_base_paths.h" | 
| 28 #include "ui/base/ui_base_switches.h" | 27 #include "ui/base/ui_base_switches.h" | 
| 29 #include "ui/gfx/codec/jpeg_codec.h" | 28 #include "ui/gfx/codec/jpeg_codec.h" | 
| 30 #include "ui/gfx/codec/png_codec.h" | 29 #include "ui/gfx/codec/png_codec.h" | 
| 31 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" | 
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 } | 754 } | 
| 756 return empty_image_; | 755 return empty_image_; | 
| 757 } | 756 } | 
| 758 | 757 | 
| 759 // static | 758 // static | 
| 760 bool ResourceBundle::ShouldHighlightMissingScaledResources() { | 759 bool ResourceBundle::ShouldHighlightMissingScaledResources() { | 
| 761 return CommandLine::ForCurrentProcess()->HasSwitch( | 760 return CommandLine::ForCurrentProcess()->HasSwitch( | 
| 762 switches::kHighlightMissingScaledResources); | 761 switches::kHighlightMissingScaledResources); | 
| 763 } | 762 } | 
| 764 | 763 | 
| 764 uint32_t ReadBigEndian32(const void* ptr) { | |
| 
tfarina
2014/02/12 02:08:22
Where I should put this function?
 
tfarina
2014/02/12 02:08:22
I copied this function from ppapi/tests/test_truet
 
tfarina
2014/02/12 02:08:22
There is another one in content/browser/speech/chu
 
tony
2014/02/12 02:23:02
Probably somewhere in base since it's used in so m
 | |
| 765 const uint8_t* data = reinterpret_cast<const uint8_t*>(ptr); | |
| 766 return (data[3] << 0) | (data[2] << 8) | (data[1] << 16) | (data[0] << 24); | |
| 767 } | |
| 768 | |
| 765 // static | 769 // static | 
| 766 bool ResourceBundle::PNGContainsFallbackMarker(const unsigned char* buf, | 770 bool ResourceBundle::PNGContainsFallbackMarker(const unsigned char* buf, | 
| 767 size_t size) { | 771 size_t size) { | 
| 768 if (size < arraysize(kPngMagic) || | 772 if (size < arraysize(kPngMagic) || | 
| 769 memcmp(buf, kPngMagic, arraysize(kPngMagic)) != 0) { | 773 memcmp(buf, kPngMagic, arraysize(kPngMagic)) != 0) { | 
| 770 // Data invalid or a JPEG. | 774 // Data invalid or a JPEG. | 
| 771 return false; | 775 return false; | 
| 772 } | 776 } | 
| 773 size_t pos = arraysize(kPngMagic); | 777 size_t pos = arraysize(kPngMagic); | 
| 774 | 778 | 
| 775 // Scan for custom chunks until we find one, find the IDAT chunk, or run out | 779 // Scan for custom chunks until we find one, find the IDAT chunk, or run out | 
| 776 // of chunks. | 780 // of chunks. | 
| 777 for (;;) { | 781 for (;;) { | 
| 778 if (size - pos < kPngChunkMetadataSize) | 782 if (size - pos < kPngChunkMetadataSize) | 
| 779 break; | 783 break; | 
| 780 uint32 length = 0; | 784 uint32 length = ReadBigEndian32(buf + pos); | 
| 781 net::ReadBigEndian(reinterpret_cast<const char*>(buf + pos), &length); | |
| 782 if (size - pos - kPngChunkMetadataSize < length) | 785 if (size - pos - kPngChunkMetadataSize < length) | 
| 783 break; | 786 break; | 
| 784 if (length == 0 && memcmp(buf + pos + sizeof(uint32), kPngScaleChunkType, | 787 if (length == 0 && memcmp(buf + pos + sizeof(uint32), kPngScaleChunkType, | 
| 785 arraysize(kPngScaleChunkType)) == 0) { | 788 arraysize(kPngScaleChunkType)) == 0) { | 
| 786 return true; | 789 return true; | 
| 787 } | 790 } | 
| 788 if (memcmp(buf + pos + sizeof(uint32), kPngDataChunkType, | 791 if (memcmp(buf + pos + sizeof(uint32), kPngDataChunkType, | 
| 789 arraysize(kPngDataChunkType)) == 0) { | 792 arraysize(kPngDataChunkType)) == 0) { | 
| 790 // Stop looking for custom chunks, any custom chunks should be before an | 793 // Stop looking for custom chunks, any custom chunks should be before an | 
| 791 // IDAT chunk. | 794 // IDAT chunk. | 
| 792 break; | 795 break; | 
| 793 } | 796 } | 
| 794 pos += length + kPngChunkMetadataSize; | 797 pos += length + kPngChunkMetadataSize; | 
| 795 } | 798 } | 
| 796 return false; | 799 return false; | 
| 797 } | 800 } | 
| 798 | 801 | 
| 799 // static | 802 // static | 
| 800 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 803 bool ResourceBundle::DecodePNG(const unsigned char* buf, | 
| 801 size_t size, | 804 size_t size, | 
| 802 SkBitmap* bitmap, | 805 SkBitmap* bitmap, | 
| 803 bool* fell_back_to_1x) { | 806 bool* fell_back_to_1x) { | 
| 804 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 807 *fell_back_to_1x = PNGContainsFallbackMarker(buf, size); | 
| 805 return gfx::PNGCodec::Decode(buf, size, bitmap); | 808 return gfx::PNGCodec::Decode(buf, size, bitmap); | 
| 806 } | 809 } | 
| 807 | 810 | 
| 808 } // namespace ui | 811 } // namespace ui | 
| OLD | NEW |