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

Side by Side Diff: ui/gfx/image/image_util.cc

Issue 2895953003: Use SkJpegEncoder in gfx jpeg_codec (Closed)
Patch Set: Update comment Created 3 years, 6 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
OLDNEW
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/image/image_util.h" 5 #include "ui/gfx/image/image_util.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 std::vector<unsigned char>* dst) { 58 std::vector<unsigned char>* dst) {
59 const gfx::ImageSkiaRep& image_skia_rep = 59 const gfx::ImageSkiaRep& image_skia_rep =
60 image.AsImageSkia().GetRepresentation(1.0f); 60 image.AsImageSkia().GetRepresentation(1.0f);
61 if (image_skia_rep.scale() != 1.0f) 61 if (image_skia_rep.scale() != 1.0f)
62 return false; 62 return false;
63 63
64 const SkBitmap& bitmap = image_skia_rep.sk_bitmap(); 64 const SkBitmap& bitmap = image_skia_rep.sk_bitmap();
65 if (!bitmap.readyToDraw()) 65 if (!bitmap.readyToDraw())
66 return false; 66 return false;
67 67
68 return gfx::JPEGCodec::Encode( 68 SkPixmap pixmap;
69 reinterpret_cast<unsigned char*>(bitmap.getAddr32(0, 0)), 69 bool success = bitmap.peekPixels(&pixmap);
70 gfx::JPEGCodec::FORMAT_SkBitmap, bitmap.width(), 70 DCHECK(success);
71 bitmap.height(), 71
72 static_cast<int>(bitmap.rowBytes()), quality, 72 return gfx::JPEGCodec::Encode(pixmap, quality, dst);
73 dst);
74 } 73 }
75 #endif // !defined(OS_IOS) 74 #endif // !defined(OS_IOS)
76 75
77 void GetVisibleMargins(const ImageSkia& image, int* left, int* right) { 76 void GetVisibleMargins(const ImageSkia& image, int* left, int* right) {
78 *left = 0; 77 *left = 0;
79 *right = 0; 78 *right = 0;
80 if (!image.HasRepresentation(1.f)) 79 if (!image.HasRepresentation(1.f))
81 return; 80 return;
82 const SkBitmap& bitmap = image.GetRepresentation(1.f).sk_bitmap(); 81 const SkBitmap& bitmap = image.GetRepresentation(1.f).sk_bitmap();
83 if (bitmap.drawsNothing() || bitmap.isOpaque()) 82 if (bitmap.drawsNothing() || bitmap.isOpaque())
(...skipping 18 matching lines...) Expand all
102 // Since we already know column *left is non-transparent, we can avoid 101 // Since we already know column *left is non-transparent, we can avoid
103 // rechecking that column; hence the '>' here. 102 // rechecking that column; hence the '>' here.
104 for (x = bitmap.width() - 1; x > *left; --x) { 103 for (x = bitmap.width() - 1; x > *left; --x) {
105 if (ColumnHasVisiblePixels(bitmap, x)) 104 if (ColumnHasVisiblePixels(bitmap, x))
106 break; 105 break;
107 } 106 }
108 *right = bitmap.width() - 1 - x; 107 *right = bitmap.width() - 1 - x;
109 } 108 }
110 109
111 } // namespace gfx 110 } // namespace gfx
OLDNEW
« chrome/renderer/chrome_render_frame_observer.cc ('K') | « ui/gfx/codec/jpeg_codec_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698