Пример #1
0
static int mod_init(void)
{
    if (bind_dbmod(db_url.s, &db )) {
	LOG(L_CRIT, "Cannot bind to database module! "
	     "Did you forget to load a database module ?\n");
	return -1;
    }
    
	 /* Check if cache needs to be loaded from domain table */
    if (db_mode) {
	if (connect_db() < 0) goto error;
	if (check_version() < 0) goto error;
	if (allocate_tables() < 0) goto error;
	if (reload_domain_list() < 0) goto error;
	disconnect_db();
    }
    
    return 0;
    
 error:
    disconnect_db();
    return -1;
}
Пример #2
0
/** recompute tables for these filterbank parameters */
static
void recompute_tables(const unsigned       bands,
                      const double * const real_filter_coefficients,
                      const double * const imag_filter_coefficients,
                      const double * const normalization_factors)
{
    unsigned exponent, band;
    double temp;
    release_tables();
    allocate_tables(bands);
    for (exponent = 1; exponent <= TABLE_SIZE; ++exponent) {
        unsigned table_idx = exponent - 1;
        for (band = 0; band < bands; ++band) {
            if (exponent == 1) {
                precomp_real_pow[band] = real_filter_coefficients[band];
                precomp_imag_pow[band] = imag_filter_coefficients[band];
            }
            else {
                complex_mult_(precomp_real_pow[(table_idx-1) * bands + band],
                              precomp_imag_pow[(table_idx-1) * bands + band],
                              real_filter_coefficients[band],
                              imag_filter_coefficients[band],
                              precomp_real_pow[table_idx * bands + band],
                              precomp_imag_pow[table_idx * bands + band]);
            }
            complex_reciprocal_(precomp_real_pow[table_idx * bands + band],
                                precomp_imag_pow[table_idx * bands + band],
                                precomp_real_norm[table_idx * bands + band],
                                precomp_imag_norm[table_idx * bands + band],
                                temp);
            precomp_real_norm[table_idx * bands + band] *=
                normalization_factors[band];
            precomp_imag_norm[table_idx * bands + band] *=
                normalization_factors[band];
        }
    }
}
Пример #3
0
/**
 * Initialize the table_rV, table_gU[i], table_gV, and table_bU fields
 * in SwsContext
 *
 * @param inv_table the YUV -> RGB table (this is a line of Inverse_Table_6_9)
 * @param fullRange 0->MPEG YUV space 1->JPEG YUV space
*/
int yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation)
{  
    int i;
    static uint8_t ytable[1024];
    int64_t cy, oy;
    int64_t crv, cbu, cgu, cgv;
    int entry_size = 0;
    uint8_t *table_r, *table_g, *table_b;
    int value;

    if ((inv_table[0] == 0) || (inv_table[1] == 0) || (inv_table[2] == 0) || (inv_table[3] == 0)) {
        MSG_ERR("Invalid YUV ---> RGB table!\n");

        return -1;
    }
    crv = inv_table[0];
    cbu = inv_table[1];
    cgu = inv_table[2];
    cgv = inv_table[3];
    if (fullRange) {
        cy = 1 << 16;
        oy = 0;
        crv= (crv*224) / 255;
        cbu= (cbu*224) / 255;
        cgu= (cgu*224) / 255;
        cgv= (cgv*224) / 255;
        //FIXME maybe its cleaner if the tables where based on full range (*244/255)
    } else {
        cy = ((1 << 16) * 255) / 219;
        oy= 16 << 16;
    }

    cy = (cy *contrast             )>>16;
    crv= (crv*contrast * saturation)>>32;
    cbu= (cbu*contrast * saturation)>>32;
    cgu= (cgu*contrast * saturation)>>32;
    cgv= (cgv*contrast * saturation)>>32;
    oy -= 256*brightness;

    for (i = 0; i < 1024; i++) {
        value = (cy*(((i - YTABLE_MIN)<<16) - oy) + (1<<31))>>32;
        ytable[i] = av_clip_uint8(value);
    }

    entry_size = get_entry_size(fmt_depth(c->dstFormat));
    av_free(c->yuvTable);
    c->yuvTable = allocate_tables(&table_r, &table_g, &table_b, fmt_depth(c->dstFormat));
    if (c->yuvTable == NULL) {
        return -1;
    }

    switch (fmt_depth(c->dstFormat)) {
        case 32:
            for (i = -198; i < 256 + 197; i++) {
                value = ytable[i + YTABLE_MIN];
                if (isBGR(c->dstFormat)) {
                    value <<= 16;
                }
                ((uint32_t *)table_r)[i] = value;
            }
            for (i = -133; i < 256 + 132; i++) {
                ((uint32_t *)table_g)[i] = ytable[i + YTABLE_MIN] << 8;
            }
            for (i = -233; i < 256 + 232; i++) {
                value = ytable[i + YTABLE_MIN];
                if (!isBGR(c->dstFormat)) {
                    value <<= 16;
                }
                ((uint32_t *)table_b)[i] = value;
            }
            break;

        case 24:
            for (i = -233; i < 256 + 232; i++) {
                ((uint8_t * )table_b)[i] = ytable[i + YTABLE_MIN];
            }
            break;

        case 15:
        case 16:
            for (i = -198; i < 256 + 197; i++) {
                value = ytable[i + YTABLE_MIN] >> 3;
                if (isBGR(c->dstFormat)) {
                    value <<= ((fmt_depth(c->dstFormat) == 16) ? 11 : 10);
                }
                ((uint16_t *)table_r)[i] = value;
            }
            for (i = -133; i < 256 + 132; i++) {
                value = ytable[i + YTABLE_MIN];
                value >>= ((fmt_depth(c->dstFormat) == 16) ? 2 : 3);
                ((uint16_t *)table_g)[i] = value << 5;
            }
            for (i = -233; i < 256 + 232; i++) {
                value = ytable[i + YTABLE_MIN] >> 3;
                if (!isBGR(c->dstFormat)) {
                    value <<= ((fmt_depth(c->dstFormat) == 16) ? 11 : 10);
                }
                ((uint16_t *)table_b)[i] = value;
            }
            break;
        case 8:
            for (i = -198; i < 256 + 197; i++) {
                value = (ytable[i + YTABLE_MIN - 16] + 18) / 36;
                if (isBGR(c->dstFormat)) {
                    value <<= 5;
                }
                ((uint8_t *)table_r)[i] = value;
            }
            for (i = -133; i < 256 + 132; i++) {
                value = (ytable[i + YTABLE_MIN - 16] + 18) / 36;
                if (!isBGR(c->dstFormat)) {
                    value <<= 1;
                }
                ((uint8_t *)table_g)[i] = value << 2;
            }
            for (i = -233; i < 256 + 232; i++) {
                value = (ytable[i + YTABLE_MIN - 37] + 43) / 85;
                if (!isBGR(c->dstFormat)) {
                    value <<= 6;
                }
                ((uint8_t *)table_b)[i] = value;
            }
            break;
        case 4:
            for (i = -198; i < 256 + 197; i++) {
                value = ytable[i + YTABLE_MIN - 110] >> 7;
                if (isBGR(c->dstFormat)) {
                    value <<= 3;
                }
                ((uint8_t *)table_r)[i] = value;
            }
            for (i = -133; i < 256 + 132; i++) {
                value = (ytable[i + YTABLE_MIN - 37]+ 43) / 85;
                ((uint8_t *)table_g)[i] = value << 1;
            }
            for (i = -233; i < 256 + 232; i++) {
                value = ytable[i + YTABLE_MIN - 110] >> 7;
                if (!isBGR(c->dstFormat)) {
                    value <<= 3;
                }
                ((uint8_t *)table_b)[i] = value;
            }
            break;
        case 1:
            for (i = 0; i < 256 + 256; i++) {
                value = ytable[i + YTABLE_MIN - 110] >> 7;
                ((uint8_t *)table_g)[i] = value;
            }
            break;
        default:
            MSG_ERR("%ibpp not supported by yuv2rgb\n", fmt_depth(c->dstFormat));
            av_free(c->yuvTable);
            c->yuvTable = NULL;

            return -1;
    }

    for (i = 0; i < 256; i++) {
        c->table_rV[i] = table_r +
                         entry_size * ROUNDED_DIV(crv * (i - 128), 76309);
        c->table_gU[i] = table_g +
                         entry_size * ROUNDED_DIV(cgu * (i - 128), 76309);
        c->table_gV[i] = entry_size * ROUNDED_DIV(cgv * (i - 128), 76309);
        c->table_bU[i] = table_b +
                         entry_size * ROUNDED_DIV(cbu * (i - 128), 76309);
    }

    return 0;
}