Logo Search packages:      
Sourcecode: librasterlite version File versions  Download package

local int validate_set ( pixel_set set,
int  channel_size 
)

Validate set

The process of splitting, moving and testing sets in the SPECK algorithm is a bit tricky. This function can be thought as a very strict validation tool.

Parameters:
setSet to validate
channel_sizeChannel size
Returns:
1 for valid sets and 0 for invalid ones

Definition at line 53 of file speck.c.

References is_power_of_two(), number_of_bits(), TYPE_I, TYPE_POINT, and TYPE_S.

Referenced by significance_test(), and split_set().

{
    int base_size = channel_size & (~1);

    /* Basic checks */
    if ((set->type != TYPE_POINT) && (set->type != TYPE_S) && (set->type != TYPE_I))
        return 0;

    if ((set->x < 0) || (set->x >= channel_size))
        return 0;

    if ((set->y < 0) || (set->y >= channel_size))
        return 0;

    if ((set->width <= 0) || (set->width > channel_size))
        return 0;

    if ((set->height <= 0) || (set->height > channel_size))
        return 0;

    if (set->x + set->height > channel_size)
        return 0;

    if (set->y + set->width > channel_size)
        return 0;

    switch (set->type) {
        case TYPE_POINT:
        {
            /* Single point */
            if ((set->width != 1) || (set->height != 1))
                return 0;

            return 1;
        }
        case TYPE_S:
        {
            /* Set of type 'S' */
            int scale;

            if ((set->width == 1) && (set->height == 1))
                return 0;

            if (channel_size == base_size) {
                /* Normal mode */
                if (set->width != set->height)
                    return 0;

                if (!is_power_of_two(set->width))
                    return 0;

                scale = number_of_bits(set->width) - 1;

                if ((set->x) & (~(~0 << scale)))
                    return 0;

                if ((set->y) & (~(~0 << scale)))
                    return 0;

                return 1;
            } else {
                /* OTLPF mode */
                if ((set->x == 0) && (set->y == 0)) {
                    /* Origin */
                    if (set->width != set->height)
                        return 0;

                    if (!is_power_of_two(set->width - 1))
                        return 0;

                    return 1;
                } else if ((set->x == 0) && (set->y > 1)) {
                    /* Top border */
                    if (set->height - set->width != 1)
                        return 0;

                    if (!is_power_of_two(set->width))
                        return 0;

                    scale = number_of_bits(set->width) - 1;

                    if ((set->y - 1) & (~(~0 << scale)))
                        return 0;

                    return 1;
                } else if ((set->x > 1) && (set->y == 0)) {
                    /* Left border */
                    if (set->width - set->height != 1)
                        return 0;

                    if (!is_power_of_two(set->height))
                        return 0;

                    scale = number_of_bits(set->height) - 1;

                    if ((set->x - 1) & (~(~0 << scale)))
                        return 0;

                    return 1;
                } else if ((set->x > 1) && (set->y > 1)) {
                    /* Internal */
                    if (set->width != set->height)
                        return 0;

                    if (!is_power_of_two(set->width))
                        return 0;

                    scale = number_of_bits(set->width) - 1;

                    if ((set->x - 1) & (~(~0 << scale)))
                        return 0;

                    if ((set->y - 1) & (~(~0 << scale)))
                        return 0;

                    return 1;
                } else {
                    return 0;
                }
            }
        }
        case TYPE_I:
        {
            /* Set of type 'I' */
            if (set->x != set->y)
                return 0;

            if (set->width != set->height)
                return 0;

            if (set->x + set->width != channel_size)
                return 0;

            if (channel_size == base_size) {
                /* Normal mode */
                if (!is_power_of_two(set->x))
                    return 0;
            } else {
                /* OTLPF mode */
                if (!is_power_of_two(set->x - 1))
                    return 0;
            }

            return 1;
        }
        default:
        {
            return 0;
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index