OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "media/capture/video/blob_utils.h" | 5 #include "media/capture/video/video_capture_utils.h" |
6 | 6 |
7 #include "media/base/video_capture_types.h" | 7 #include "media/base/video_capture_types.h" |
8 #include "media/base/video_frame.h" | 8 #include "media/base/video_frame.h" |
9 #include "third_party/libyuv/include/libyuv.h" | 9 #include "third_party/libyuv/include/libyuv.h" |
10 #include "third_party/skia/include/core/SkImage.h" | 10 #include "third_party/skia/include/core/SkImage.h" |
11 #include "ui/gfx/codec/png_codec.h" | 11 #include "ui/gfx/codec/png_codec.h" |
12 | 12 |
| 13 #define FourCcMacro(f, o, u, r) \ |
| 14 static_cast<unsigned>((static_cast<unsigned>(f) << 0)) | \ |
| 15 (static_cast<unsigned>(o) << 8) | (static_cast<unsigned>(u) << 16) | \ |
| 16 (static_cast<unsigned>(r) << 24) |
| 17 |
13 namespace media { | 18 namespace media { |
14 | 19 |
| 20 static const unsigned kFourCcZ16 = FourCcMacro('Z', '1', '6', ' '); |
| 21 static const unsigned kFourCcINVZ = FourCcMacro('I', 'N', 'V', 'Z'); |
| 22 static const unsigned kFourCcY16 = FourCcMacro('Y', '1', '6', ' '); |
| 23 |
15 mojom::BlobPtr Blobify(const uint8_t* buffer, | 24 mojom::BlobPtr Blobify(const uint8_t* buffer, |
16 const uint32_t bytesused, | 25 const uint32_t bytesused, |
17 const VideoCaptureFormat& capture_format) { | 26 const VideoCaptureFormat& capture_format) { |
18 DCHECK(buffer); | 27 DCHECK(buffer); |
19 DCHECK(bytesused); | 28 DCHECK(bytesused); |
20 DCHECK(capture_format.IsValid()); | 29 DCHECK(capture_format.IsValid()); |
21 | 30 |
22 const VideoPixelFormat pixel_format = capture_format.pixel_format; | 31 const VideoPixelFormat pixel_format = capture_format.pixel_format; |
23 if (pixel_format == VideoPixelFormat::PIXEL_FORMAT_MJPEG) { | 32 if (pixel_format == VideoPixelFormat::PIXEL_FORMAT_MJPEG) { |
24 mojom::BlobPtr blob = mojom::Blob::New(); | 33 mojom::BlobPtr blob = mojom::Blob::New(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 const bool result = gfx::PNGCodec::Encode( | 68 const bool result = gfx::PNGCodec::Encode( |
60 tmp_argb.get(), codec_color_format, frame_size, frame_size.width() * 4, | 69 tmp_argb.get(), codec_color_format, frame_size, frame_size.width() * 4, |
61 true /* discard_transparency */, std::vector<gfx::PNGCodec::Comment>(), | 70 true /* discard_transparency */, std::vector<gfx::PNGCodec::Comment>(), |
62 &blob->data); | 71 &blob->data); |
63 DCHECK(result); | 72 DCHECK(result); |
64 | 73 |
65 blob->mime_type = "image/png"; | 74 blob->mime_type = "image/png"; |
66 return blob; | 75 return blob; |
67 } | 76 } |
68 | 77 |
| 78 bool IsY16FormatFourCc(unsigned four) { |
| 79 return four == kFourCcZ16 || four == kFourCcINVZ || four == kFourCcY16; |
| 80 } |
| 81 |
69 } // namespace media | 82 } // namespace media |
OLD | NEW |