Commit 036aec4e authored by Paolo Bacchilega's avatar Paolo Bacchilega

jpeg loader: fixed possible multithread problem

initialize the tables inside a mutex lock
parent f41d9ef9
......@@ -85,6 +85,7 @@ static int *YCbCr_R_Cr_Tab = NULL;
static int *YCbCr_G_Cb_Tab = NULL;
static int *YCbCr_G_Cr_Tab = NULL;
static int *YCbCr_B_Cb_Tab = NULL;
static GStaticMutex Tables_Mutex = G_STATIC_MUTEX_INIT;
#define SCALE_FACTOR 16
......@@ -96,6 +97,8 @@ static int *YCbCr_B_Cb_Tab = NULL;
static void
CMYK_table_init (void)
{
g_static_mutex_lock (&Tables_Mutex);
if (CMYK_Tab == NULL) {
int v, k, i;
double k1;
......@@ -110,12 +113,16 @@ CMYK_table_init (void)
CMYK_Tab[i++] = (double) v * k1;
}
}
g_static_mutex_unlock (&Tables_Mutex);
}
static void
YCbCr_tables_init (void)
{
g_static_mutex_lock (&Tables_Mutex);
if (YCbCr_R_Cr_Tab == NULL) {
int i, v;
......@@ -125,12 +132,14 @@ YCbCr_tables_init (void)
YCbCr_B_Cb_Tab = g_new (int, 256);
for (i = 0, v = -128; i <= 255; i++, v++) {
YCbCr_R_Cr_Tab[i] = SCALE_DOWN (SCALE_UP(1.402) * v + ONE_HALF);
YCbCr_R_Cr_Tab[i] = SCALE_DOWN (SCALE_UP (1.402) * v + ONE_HALF);
YCbCr_G_Cb_Tab[i] = - SCALE_UP (0.34414) * v;
YCbCr_G_Cr_Tab[i] = - SCALE_UP (0.71414) * v + ONE_HALF;
YCbCr_B_Cb_Tab[i] = SCALE_DOWN (SCALE_UP(1.77200) * v + ONE_HALF);
YCbCr_B_Cb_Tab[i] = SCALE_DOWN (SCALE_UP (1.77200) * v + ONE_HALF);
}
}
g_static_mutex_unlock (&Tables_Mutex);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment