Feat/row align bytes (#7)
* better bytes alignment Signed-off-by: fufesou <shuanglongchen@yeah.net> * debug macos Signed-off-by: fufesou <shuanglongchen@yeah.net> * debug linux Signed-off-by: fufesou <shuanglongchen@yeah.net> * windows switch_rgba Signed-off-by: fufesou <shuanglongchen@yeah.net> * better switch_rgba Signed-off-by: fufesou <shuanglongchen@yeah.net> --------- Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
044bb260d9
commit
873919902e
16 changed files with 94 additions and 60 deletions
|
|
@ -39,13 +39,18 @@ G_DEFINE_TYPE(TextureRgba, texture_rgba,
|
|||
(G_TYPE_CHECK_INSTANCE_CAST((obj), texture_rgba_get_type(), \
|
||||
TextureRgba))
|
||||
|
||||
static inline void switch_rgba(uint8_t* pixels, int width, int height) {
|
||||
static inline void switch_rgba(uint8_t* pixels, int len, int height) {
|
||||
uint8_t temp;
|
||||
|
||||
for (int i = 0; i < width * height; i++) {
|
||||
temp = pixels[4 * i];
|
||||
pixels[4 * i] = pixels[4 * i + 2];
|
||||
pixels[4 * i + 2] = temp;
|
||||
int byes_per_row = len / height;
|
||||
int width = byes_per_row >> 2;
|
||||
for (int i = 0; i < height; ++i) {
|
||||
int row_idx_base = i * byes_per_row;
|
||||
for (int k = 0; k < width; ++k) {
|
||||
int idx = row_idx_base + k * 4;
|
||||
temp = pixels[idx];
|
||||
pixels[idx] = pixels[idx + 2];
|
||||
pixels[idx + 2] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ FLUTTER_PLUGIN_EXPORT void texture_rgba_renderer_plugin_register_with_registrar(
|
|||
FlPluginRegistrar* registrar);
|
||||
|
||||
// Keep the same symbol name with Windows.
|
||||
FLUTTER_PLUGIN_EXPORT void FlutterRgbaRendererPluginOnRgba(void *texture_rgba, const uint8_t *buffer, int width, int height);
|
||||
FLUTTER_PLUGIN_EXPORT void FlutterRgbaRendererPluginOnRgba(void *texture_rgba, const uint8_t *buffer, int len, int width, int height, int row_align_bytes);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
std::unordered_map<int64_t, TextureRgba *> g_renderer_map;
|
||||
|
||||
void FlutterRgbaRendererPluginOnRgba(void *texture_rgba_ptr, const uint8_t *buffer, int width, int height);
|
||||
void FlutterRgbaRendererPluginOnRgba(void *texture_rgba_ptr, const uint8_t *buffer, int len, int width, int height);
|
||||
struct _TextureRgbaRendererPlugin
|
||||
{
|
||||
GObject parent_instance;
|
||||
|
|
@ -68,11 +68,12 @@ static void texture_rgba_renderer_plugin_handle_method_call(
|
|||
auto args = fl_method_call_get_args(method_call);
|
||||
auto key = fl_value_get_int(fl_value_lookup_string(args, "key"));
|
||||
auto data = fl_value_get_uint8_list(fl_value_lookup_string(args, "data"));
|
||||
// auto data_length = fl_value_get_length(fl_value_lookup_string(args, "data"));
|
||||
auto data_length = fl_value_get_length(fl_value_lookup_string(args, "data"));
|
||||
auto width = fl_value_get_int(fl_value_lookup_string(args, "width"));
|
||||
auto height = fl_value_get_int(fl_value_lookup_string(args, "height"));
|
||||
auto row_align_bytes = fl_value_get_int(fl_value_lookup_string(args, "row_align_bytes"));
|
||||
auto texture_rgba = g_renderer_map[key];
|
||||
FlutterRgbaRendererPluginOnRgba((void*)texture_rgba, data, width, height);
|
||||
FlutterRgbaRendererPluginOnRgba((void*)texture_rgba, data, data_length, width, height, row_align_bytes);
|
||||
response = FL_METHOD_RESPONSE(fl_method_success_response_new(
|
||||
fl_value_new_bool(fl_texture_registrar_mark_texture_frame_available(self->texture_registrar, FL_TEXTURE(texture_rgba)))));
|
||||
}
|
||||
|
|
@ -140,16 +141,15 @@ void texture_rgba_renderer_plugin_register_with_registrar(FlPluginRegistrar *reg
|
|||
|
||||
|
||||
extern "C" {
|
||||
void FlutterRgbaRendererPluginOnRgba(void *texture_rgba_ptr, const uint8_t *buffer, int width, int height) {
|
||||
void FlutterRgbaRendererPluginOnRgba(void *texture_rgba_ptr, const uint8_t *buffer, int len, int width, int height, int row_align_bytes) {
|
||||
TextureRgba* self = TEXTURE_RGBA(texture_rgba_ptr);
|
||||
g_mutex_lock(&self->mutex);
|
||||
// selfate has registered a texture_id,
|
||||
if (self->texture_id != 0 && !g_atomic_int_get(&self->buffer_ready) && !texture_rgba_is_terminate(self)) {
|
||||
// copy data to the texture.
|
||||
auto buffer_length = 4 * width * height;
|
||||
auto copied_data = new uint8_t[buffer_length];
|
||||
memcpy(copied_data, buffer, buffer_length);
|
||||
switch_rgba(copied_data, width, height);
|
||||
auto copied_data = new uint8_t[len];
|
||||
memcpy(copied_data, buffer, len);
|
||||
switch_rgba(copied_data, len, height);
|
||||
// It's safe to working on a non reading index
|
||||
g_atomic_pointer_set(&self->buffer, copied_data);
|
||||
g_atomic_int_set(&self->video_height, height);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue