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

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

Issue 2398463003: 16 bit capture and GPU&CPU memory buffer support.
Patch Set: fixes. Created 4 years, 2 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
« no previous file with comments | « media/capture/video/blob_utils.h ('k') | media/capture/video/fake_video_capture_device.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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 const 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 const gfx::Size frame_size = capture_format.frame_size;
44 // PNGCodec does not support YUV formats, convert to a temporary ARGB buffer.
45 std::unique_ptr<uint8_t[]> tmp_argb(
46 new uint8_t[VideoFrame::AllocationSize(PIXEL_FORMAT_ARGB, frame_size)]);
47 if (ConvertToARGB(buffer, bytesused, tmp_argb.get(), frame_size.width() * 4,
48 0 /* crop_x_pos */, 0 /* crop_y_pos */, frame_size.width(),
49 frame_size.height(), frame_size.width(),
50 frame_size.height(), libyuv::RotationMode::kRotate0,
51 src_format) != 0) {
52 return nullptr;
53 }
54
55 mojom::BlobPtr blob = mojom::Blob::New();
56 const gfx::PNGCodec::ColorFormat codec_color_format =
57 (kN32_SkColorType == kRGBA_8888_SkColorType) ? gfx::PNGCodec::FORMAT_RGBA
58 : gfx::PNGCodec::FORMAT_BGRA;
59 const bool result = gfx::PNGCodec::Encode(
60 tmp_argb.get(), codec_color_format, frame_size, frame_size.width() * 4,
61 true /* discard_transparency */, std::vector<gfx::PNGCodec::Comment>(),
62 &blob->data);
63 DCHECK(result);
64
65 blob->mime_type = "image/png";
66 return blob;
67 }
68
69 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/blob_utils.h ('k') | media/capture/video/fake_video_capture_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698