diff options
author | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 22:25:08 +0000 |
---|---|---|
committer | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-17 22:25:08 +0000 |
commit | 523b2523c1f2cb22f56be9cc52fb734370992387 (patch) | |
tree | ede3f93c4e118e840778e39b5633d6bfc7058ab3 /o3d/core/cross/bitmap.cc | |
parent | 9521c61f5588480d8cd6134144db7137630f2529 (diff) | |
download | chromium_src-523b2523c1f2cb22f56be9cc52fb734370992387.zip chromium_src-523b2523c1f2cb22f56be9cc52fb734370992387.tar.gz chromium_src-523b2523c1f2cb22f56be9cc52fb734370992387.tar.bz2 |
Add RawData request in preparation for manual loading of
Bitmaps and being able to flip them, scale them, etc...
Basically this just makes it possible to download a RawData
directly which you can then pass you'll be able to pass to
pack->CreateBitmapFromRawData.
Some design comments:
I used SetFromFile instead of making a different constructor
since it seemed wrong to do file IO in a constructor. Given
that SetFromFile is private I don't think this is a problem
since you can't call it directly.
Also, I thought about loading the file first and then calling
the original constructor but it seemed like a waste to load
the file into memory, then copy it to a new buffer when I could
just load it directly.
Finally I made it take a String instead of a FilePath because
it meant other places had to do less work.
Review URL: http://codereview.chromium.org/149784
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core/cross/bitmap.cc')
-rw-r--r-- | o3d/core/cross/bitmap.cc | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/o3d/core/cross/bitmap.cc b/o3d/core/cross/bitmap.cc index 61ac355..320d3e1 100644 --- a/o3d/core/cross/bitmap.cc +++ b/o3d/core/cross/bitmap.cc @@ -219,40 +219,39 @@ bool Bitmap::LoadFromStream(MemoryReadStream *stream, bool Bitmap::LoadFromFile(const FilePath &filepath, ImageFileType file_type, bool generate_mipmaps) { - // Open the file + // Open the file. + bool result = false; String filename = FilePathToUTF8(filepath); FILE *file = OpenFile(filepath, "rb"); if (!file) { DLOG(ERROR) << "bitmap file not found \"" << filename << "\""; - return false; - } - - // Determine the file's length - int64 file_size64; - if (!GetFileSize(filepath, &file_size64)) { - DLOG(ERROR) << "error getting bitmap file size \"" << filename << "\""; + } else { + // Determine the file's length + int64 file_size64; + if (!GetFileSize(filepath, &file_size64)) { + DLOG(ERROR) << "error getting bitmap file size \"" << filename << "\""; + } else { + if (file_size64 > 0xffffffffLL) { + DLOG(ERROR) << "bitmap file is too large \"" << filename << "\""; + } else { + size_t file_length = static_cast<size_t>(file_size64); + + // Load the compressed image data into memory + MemoryBuffer<uint8> file_contents(file_length); + uint8 *p = file_contents; + if (fread(p, file_length, 1, file) != 1) { + DLOG(ERROR) << "error reading bitmap file \"" << filename << "\""; + } else { + // And create the bitmap from a memory stream + MemoryReadStream stream(file_contents, file_length); + result = LoadFromStream(&stream, filename, file_type, + generate_mipmaps); + } + } + } CloseFile(file); - return false; - } - if (file_size64 > 0xffffffffLL) { - DLOG(ERROR) << "bitmap file is too large \"" << filename << "\""; - return false; } - size_t file_length = static_cast<size_t>(file_size64); - - // Load the compressed image data into memory - MemoryBuffer<uint8> file_contents(file_length); - uint8 *p = file_contents; - if (fread(p, file_length, 1, file) != 1) { - DLOG(ERROR) << "error reading bitmap file \"" << filename << "\""; - return false; - } - - // And create the bitmap from a memory stream - MemoryReadStream stream(file_contents, file_length); - bool result = LoadFromStream(&stream, filename, file_type, generate_mipmaps); - CloseFile(file); return result; } |