This commit is contained in:
2024-09-26 15:39:49 +02:00
parent 492b4815a6
commit 007330caa7
9 changed files with 42 additions and 44 deletions

View File

@ -106,10 +106,9 @@ static PyObject *decode(PyObject *Py_UNUSED(self), PyObject *args,
return NULL;
}
if (n_threads == 1){
if (n_threads == 1) {
pm_decode(src, dst, pm, n_frames, n_rows * n_cols);
}else{
} else {
// Multithreaded processing
pthread_t *threads = malloc(sizeof(pthread_t *) * n_threads);
thread_args *arguments = malloc(sizeof(thread_args) * n_threads);
@ -120,7 +119,8 @@ static PyObject *decode(PyObject *Py_UNUSED(self), PyObject *args,
arguments[i].src = src + (i * frames_per_thread * pm_size);
arguments[i].dst = dst + (i * frames_per_thread * pm_size);
arguments[i].pm = pm;
arguments[i].n_frames = frames_per_thread; // TODO! not matching frames.
arguments[i].n_frames =
frames_per_thread; // TODO! not matching frames.
arguments[i].n_pixels = n_rows * n_cols;
assigned_frames += frames_per_thread;
}
@ -128,7 +128,7 @@ static PyObject *decode(PyObject *Py_UNUSED(self), PyObject *args,
for (size_t i = 0; i < n_threads; i++) {
pthread_create(&threads[i], NULL, (void *)thread_pmdecode,
&arguments[i]);
&arguments[i]);
}
for (size_t i = 0; i < n_threads; i++) {
pthread_join(threads[i], NULL);
@ -136,8 +136,6 @@ static PyObject *decode(PyObject *Py_UNUSED(self), PyObject *args,
free(threads);
free(arguments);
}
Py_DECREF(raw_data);
Py_DECREF(pixel_map);

View File

@ -1,17 +1,18 @@
#include "pm_decode.h"
#include "thread_utils.h"
void thread_pmdecode(void* args){
thread_args* a;
a = (thread_args *) args;
void thread_pmdecode(void *args) {
thread_args *a;
a = (thread_args *)args;
pm_decode(a->src, a->dst, a->pm, a->n_frames, a->n_pixels);
}
void pm_decode(uint16_t* src, uint16_t* dst, uint32_t* pm, size_t n_frames, size_t n_pixels){
for(size_t i = 0; i<n_frames; i++){
for(size_t j=0; j<n_pixels; j++){
void pm_decode(uint16_t *src, uint16_t *dst, uint32_t *pm, size_t n_frames,
size_t n_pixels) {
for (size_t i = 0; i < n_frames; i++) {
for (size_t j = 0; j < n_pixels; j++) {
*dst++ = src[pm[j]];
}
src += n_pixels;
}
src += n_pixels;
}
}

View File

@ -1,8 +1,8 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
//Wrapper to be used with pthreads
void thread_pmdecode(void* args);
#include <stdint.h>
// Wrapper to be used with pthreads
void thread_pmdecode(void *args);
void pm_decode(uint16_t* src, uint16_t* dst, uint32_t* pm, size_t n_frames, size_t n_pixels);
void pm_decode(uint16_t *src, uint16_t *dst, uint32_t *pm, size_t n_frames,
size_t n_pixels);

View File

@ -1,10 +1,10 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
typedef struct{
uint16_t* src;
uint16_t* dst;
uint32_t* pm;
#include <stdint.h>
typedef struct {
uint16_t *src;
uint16_t *dst;
uint32_t *pm;
size_t n_frames;
size_t n_pixels;
}thread_args;
} thread_args;