Skip to content
Snippets Groups Projects
Commit 0bf0ce33 authored by tfarina@chromium.org's avatar tfarina@chromium.org
Browse files

remoting: Extract the utility to get the BytesPerPixel from PixelFormat into a function.

Note: That was a TODO for hclam.

BUG=None
TEST=trybots

Review URL: http://codereview.chromium.org/2865019

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50928 0039d316-1c4b-4281-b951-d872f2087c98
parent 193b0b89
No related branches found
No related tags found
No related merge requests found
......@@ -24,4 +24,19 @@ scoped_refptr<media::DataBuffer> SerializeAndFrameMessage(
return buffer;
}
int GetBytesPerPixel(PixelFormat format) {
// Note: The order is important here for performace. This is sorted from the
// most common to the less common (PixelFormatAscii is mostly used
// just for testing).
switch (format) {
case PixelFormatRgb24: return 3;
case PixelFormatRgb565: return 2;
case PixelFormatRgb32: return 4;
case PixelFormatAscii: return 1;
default:
NOTREACHED() << "Pixel format not supported";
return 0;
}
}
} // namespace remoting
......@@ -7,6 +7,7 @@
#include "google/protobuf/message_lite.h"
#include "media/base/data_buffer.h"
#include "remoting/base/protocol/chromotocol.pb.h"
// This file defines utility methods used for encoding and decoding the protocol
// used in Chromoting.
......@@ -19,6 +20,8 @@ namespace remoting {
scoped_refptr<media::DataBuffer> SerializeAndFrameMessage(
const google::protobuf::MessageLite& msg);
int GetBytesPerPixel(PixelFormat format);
} // namespace remoting
#endif // REMOTING_BASE_PROTOCOL_UTIL_H_
......@@ -4,6 +4,8 @@
#include "remoting/client/decoder_verbatim.h"
#include "remoting/base/protocol_util.h"
namespace remoting {
DecoderVerbatim::DecoderVerbatim()
......@@ -37,20 +39,6 @@ bool DecoderVerbatim::PartialDecode(HostMessage* message) {
int y = message->update_stream_packet().header().y();
PixelFormat pixel_format =
message->update_stream_packet().header().pixel_format();
int bytes_per_pixel = 0;
// TODO(hclam): Extract the following to an util function.
if (pixel_format == PixelFormatRgb24) {
bytes_per_pixel = 3;
} else if (pixel_format == PixelFormatRgb565) {
bytes_per_pixel = 2;
} else if (pixel_format == PixelFormatRgb32) {
bytes_per_pixel = 4;
} else if (pixel_format == PixelFormatAscii) {
bytes_per_pixel = 1;
} else {
NOTREACHED() << "Pixel format not supported";
}
if (static_cast<PixelFormat>(frame_->format()) != pixel_format) {
NOTREACHED() << "Pixel format of message doesn't match the video frame. "
......@@ -59,6 +47,7 @@ bool DecoderVerbatim::PartialDecode(HostMessage* message) {
<< " Color space conversion required.";
}
int bytes_per_pixel = GetBytesPerPixel(pixel_format);
// Copy the data line by line.
const int src_stride = bytes_per_pixel * width;
const char* src = message->update_stream_packet().data().c_str();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment