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

Side by Side Diff: media/capture/video/blob_utils.cc

Issue 2354783002: ImageCapture: Implement takePhoto() for Windows (Closed)
Patch Set: Created 4 years, 3 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/capture/video/blob_utils.h"
6
xianglu 2016/09/20 18:43:03 nit: redundant line
mcasas 2016/09/20 19:51:10 ? l.5 needs to be separated [1], and I should incl
xianglu 2016/09/20 20:42:58 I thought l.6 was redundant.
7 #include "media/base/video_capture_types.h"
8 #include "media/base/video_frame.h"
9 #include "third_party/libyuv/include/libyuv.h"
10 #include "third_party/skia/include/core/SkImage.h"
11 #include "ui/gfx/codec/png_codec.h"
12
13 namespace media {
14
15 mojom::BlobPtr Blobify(const uint8_t* buffer,
16 const uint32_t bytesused,
17 VideoCaptureFormat capture_format) {
18 DCHECK(buffer);
19 DCHECK(bytesused);
20 DCHECK(capture_format.IsValid());
21
22 const VideoPixelFormat pixel_format = capture_format.pixel_format;
23 if (pixel_format == VideoPixelFormat::PIXEL_FORMAT_MJPEG) {
24 mojom::BlobPtr blob = mojom::Blob::New();
25 blob->data.resize(bytesused);
26 memcpy(blob->data.data(), buffer, bytesused);
27 blob->mime_type = "image/jpeg";
28 return blob;
29 }
30
31 uint32_t src_format;
32 if (pixel_format == VideoPixelFormat::PIXEL_FORMAT_UYVY)
33 src_format = libyuv::FOURCC_UYVY;
34 else if (pixel_format == VideoPixelFormat::PIXEL_FORMAT_YUY2)
35 src_format = libyuv::FOURCC_YUY2;
36 else if (pixel_format == VideoPixelFormat::PIXEL_FORMAT_I420)
37 src_format = libyuv::FOURCC_I420;
38 else if (pixel_format == VideoPixelFormat::PIXEL_FORMAT_RGB24)
39 src_format = libyuv::FOURCC_24BG;
40 else
41 return nullptr;
42
43 // PNGCodec does not support YUV formats, convert to a temporary ARGB buffer.
44 std::unique_ptr<uint8_t[]> tmp_argb(new uint8_t[VideoFrame::AllocationSize(
xianglu 2016/09/20 18:43:03 Since it's used several times below, maybe you can
mcasas 2016/09/20 19:51:10 Done.
45 PIXEL_FORMAT_ARGB, capture_format.frame_size)]);
46 if (ConvertToARGB(buffer, bytesused, tmp_argb.get(),
47 capture_format.frame_size.width() * 4, 0 /* crop_x_pos */,
48 0 /* crop_y_pos */, capture_format.frame_size.width(),
49 capture_format.frame_size.height(),
50 capture_format.frame_size.width(),
51 capture_format.frame_size.height(),
52 libyuv::RotationMode::kRotate0, src_format) != 0) {
53 return nullptr;
54 }
55
56 mojom::BlobPtr blob = mojom::Blob::New();
57 const gfx::PNGCodec::ColorFormat codec_color_format =
58 (kN32_SkColorType == kRGBA_8888_SkColorType) ? gfx::PNGCodec::FORMAT_RGBA
59 : gfx::PNGCodec::FORMAT_BGRA;
60 const bool result = gfx::PNGCodec::Encode(
61 tmp_argb.get(), codec_color_format, capture_format.frame_size,
62 capture_format.frame_size.width() * 4, true /* discard_transparency */,
63 std::vector<gfx::PNGCodec::Comment>(), &blob->data);
64 DCHECK(result);
65
66 blob->mime_type = "image/png";
67 return blob;
68 }
69
70 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698