Skip to content

Commit

Permalink
Removed wavelet stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
schani committed Jan 25, 2009
1 parent 1978c00 commit a2b979e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 232 deletions.
12 changes: 6 additions & 6 deletions TODO
Expand Up @@ -2,18 +2,12 @@

* 1.1.0

make wavelet work again

test suite

give command line access to color spaces

is file format compatible with 1.0?

don't store all color space coeffs in metapixel - compute them like
the wavelet coeffs in a pass before the mosaic creation and store them
in an array

check all asserts

* 1.1.1
Expand All @@ -24,6 +18,12 @@ api docs

* later

don't store all color space coeffs in metapixel - compute them in a
pass before the mosaic creation and store them in an array

make wavelet work again. problem: the coeffs would have to be saved
for each color space separately.

use multiple threads for mosaic creation (create thread library to
unify with mathmap)

Expand Down
7 changes: 1 addition & 6 deletions api.h
Expand Up @@ -140,10 +140,6 @@ struct _metapixel_t
int enabled; /* Always true in this release */

/* these three are very internal */
/*
wavelet_coefficients_t coeffs;
float means[NUM_CHANNELS];
*/
unsigned char subpixels_rgb[NUM_SUBPIXELS * NUM_CHANNELS];
unsigned char subpixels_hsv[NUM_SUBPIXELS * NUM_CHANNELS];
unsigned char subpixels_yiq[NUM_SUBPIXELS * NUM_CHANNELS];
Expand Down Expand Up @@ -233,8 +229,7 @@ void tiling_get_metapixel_coords (tiling_t *tiling, unsigned int image_width, un
unsigned int metapixel_x, unsigned int metapixel_y,
unsigned int *x, unsigned int *y, unsigned int *width, unsigned int *height);

#define METRIC_WAVELET 1
#define METRIC_SUBPIXEL 2
#define METRIC_SUBPIXEL 1

#define COLOR_SPACE_RGB 1
#define COLOR_SPACE_HSV 2
Expand Down
31 changes: 0 additions & 31 deletions internals.h
Expand Up @@ -48,15 +48,6 @@

#define TILING_RECTANGULAR 1

/* Wavelet parameters */
#define WAVELET_IMAGE_SIZE 64
#define SQRT_OF_WAVELET_IMAGE_SIZE 8.0
#define WAVELET_IMAGE_PIXELS (WAVELET_IMAGE_SIZE * WAVELET_IMAGE_SIZE)
#define WAVELET_ROW_LENGTH (WAVELET_IMAGE_SIZE * NUM_CHANNELS)
#define SIGNIFICANT_WAVELET_COEFFS 40
#define NUM_WAVELET_COEFFS (NUM_CHANNELS * SIGNIFICANT_WAVELET_COEFFS)
#define NUM_WAVELET_INDEXES (WAVELET_IMAGE_SIZE * WAVELET_IMAGE_SIZE * NUM_CHANNELS * 2)

/* Subpixel parameters */
#define NUM_SUBPIXEL_ROWS_COLS 5
#define NUM_SUBPIXELS (NUM_SUBPIXEL_ROWS_COLS * NUM_SUBPIXEL_ROWS_COLS)
Expand All @@ -69,27 +60,13 @@ typedef struct

typedef unsigned short index_t;

typedef struct
{
index_t coeffs[NUM_WAVELET_COEFFS];
} wavelet_coefficients_t;

typedef struct
{
unsigned char subpixels[NUM_SUBPIXELS * NUM_CHANNELS];
} subpixel_coefficients_t;

typedef union
{
/*
struct
{
wavelet_coefficients_t coeffs;
float means[NUM_CHANNELS];
float sums[NUM_COEFFS];
} wavelet;
*/

subpixel_coefficients_t subpixel;
} coeffs_union_t;

Expand Down Expand Up @@ -176,14 +153,6 @@ metapixel_t* metapixel_find_in_libraries (int num_libraries, library_t **librari
const char *library_path, const char *filename,
int *num_new_libraries, library_t ***new_libraries);

void wavelet_decompose_image (float *image);
void wavelet_find_highest_coeffs (float *image, coefficient_with_index_t highest_coeffs[NUM_WAVELET_COEFFS]);
void wavelet_generate_coeffs (wavelet_coefficients_t *search_coeffs, float sums[NUM_WAVELET_COEFFS],
coefficient_with_index_t raw_coeffs[NUM_WAVELET_COEFFS]);

/* Must be called before using any wavelet functions. */
void init_wavelet (void);

typedef float (*compare_func_t) (coeffs_union_t *coeffs, metapixel_t *pixel,
float best_score, int color_space, float weights[]);

Expand Down
55 changes: 5 additions & 50 deletions library.c
Expand Up @@ -117,23 +117,6 @@ write_metapixel_metadata (metapixel_t *metapixel, FILE *out)
lisp_print_boolean(metapixel->flip & FLIP_VER, out);
lisp_print_close_paren(out);

lisp_print_open_paren(out);
lisp_print_symbol("wavelet", out);
lisp_print_open_paren(out);
lisp_print_symbol("means", out);
lisp_print_real(/*pixel.means[0]*/ 0.0, out);
lisp_print_real(/*pixel.means[1]*/ 0.0, out);
lisp_print_real(/*pixel.means[2]*/ 0.0, out);
lisp_print_close_paren(out);
lisp_print_open_paren(out);
lisp_print_symbol("coeffs", out);
/*
for (i = 0; i < NUM_COEFFS; ++i)
fprintf(tables_file, " %d", highest_coeffs[i].index);
*/
lisp_print_close_paren(out);
lisp_print_close_paren(out);

lisp_print_open_paren(out);
lisp_print_symbol("subpixel", out);
for (channel = 0; channel < NUM_CHANNELS; ++channel)
Expand Down Expand Up @@ -190,14 +173,13 @@ read_tables (const char *library_dir, library_t *library)
pattern = lisp_read_from_string("(small-image #?(string) #?(string)"
" (size #?(integer) #?(integer) #?(real))"
" (flip #?(boolean) #?(boolean))"
" (wavelet (means #?(real) #?(real) #?(real)) (coeffs . #?(list)))"
" (subpixel (r . #?(list)) (g . #?(list)) (b . #?(list)))"
" (anti #?(integer) #?(integer)))");
assert(pattern != 0
&& lisp_type(pattern) != LISP_TYPE_EOF
&& lisp_type(pattern) != LISP_TYPE_PARSE_ERROR);
assert(lisp_compile_pattern(&pattern, &num_subs));
assert(num_subs == 16);
assert(num_subs == 12);

init_pools(&pools);
init_pools_allocator(&allocator, &pools);
Expand All @@ -211,12 +193,11 @@ read_tables (const char *library_dir, library_t *library)
type = lisp_type(obj);
if (type != LISP_TYPE_EOF && type != LISP_TYPE_PARSE_ERROR)
{
lisp_object_t *vars[16];
lisp_object_t *vars[12];

if (lisp_match_pattern(pattern, obj, vars, num_subs))
{
metapixel_t *pixel;
// coefficient_with_index_t coeffs[NUM_WAVELET_COEFFS];
lisp_object_t *lst;
int channel, i;

Expand All @@ -227,8 +208,8 @@ read_tables (const char *library_dir, library_t *library)
pixel->filename = strdup(lisp_string(vars[1]));
assert(pixel->filename != 0);

pixel->anti_x = lisp_integer(vars[14]);
pixel->anti_y = lisp_integer(vars[15]);
pixel->anti_x = lisp_integer(vars[10]);
pixel->anti_y = lisp_integer(vars[11]);

if (lisp_boolean(vars[5]))
pixel->flip |= FLIP_HOR;
Expand All @@ -242,35 +223,9 @@ read_tables (const char *library_dir, library_t *library)

++library->num_metapixels;

/*
for (channel = 0; channel < NUM_CHANNELS; ++channel)
pixel->means[channel] = lisp_real(vars[9 + channel]);
if (lisp_list_length(vars[12]) != NUM_WAVELET_COEFFS)
{
fprintf(stderr, "Error: wrong number of wavelet coefficients in `%s'\n", pixel->filename);
retval = 0;
goto done;
}
else
{
static float sums[NUM_WAVELET_COEFFS];
lst = vars[12];
for (i = 0; i < NUM_WAVELET_COEFFS; ++i)
{
coeffs[i].index = lisp_integer(lisp_car(lst));
lst = lisp_cdr(lst);
}
wavelet_generate_coeffs(&pixel->coeffs, sums, coeffs);
}
*/

for (channel = 0; channel < NUM_CHANNELS; ++channel)
{
lst = vars[11 + channel];
lst = vars[7 + channel];

if (lisp_list_length(lst) != NUM_SUBPIXELS)
{
Expand Down
23 changes: 6 additions & 17 deletions main.c
Expand Up @@ -126,11 +126,6 @@ init_metric (metric_t *metric, int kind)
{
if (kind == METRIC_SUBPIXEL)
metric_init(metric, METRIC_SUBPIXEL, COLOR_SPACE_YIQ, weight_factors);
/*
else if (kind == METRIC_WAVELET)
{
}
*/
else
assert(0);
}
Expand Down Expand Up @@ -423,11 +418,9 @@ read_rc_file (void)
for (i = 0; i < 3; ++i)
default_weight_factors[i] = lisp_real(vars[i]);
}
else if (lisp_match_string("(metric #?(or wavelet subpixel))", obj, vars))
else if (lisp_match_string("(metric #?(or subpixel))", obj, vars))
{
if (strcmp(lisp_symbol(vars[0]), "wavelet") == 0)
default_metric = METRIC_WAVELET;
else
if (strcmp(lisp_symbol(vars[0]), "subpixel") == 0)
default_metric = METRIC_SUBPIXEL;
}
else if (lisp_match_string("(search-method #?(or local global))", obj, vars))
Expand Down Expand Up @@ -509,7 +502,7 @@ usage (void)
" -i, --i-weight=WEIGHT assign relative weight for the I-channel\n"
" -q, --q-weight=WEIGHT assign relative weight for the Q-channel\n"
" -s --scale=SCALE scale input image by specified factor\n"
" -m, --metric=METRIC choose metric (subpixel or wavelet)\n"
" -m, --metric=METRIC choose metric (only subpixel is valid)\n"
" -e, --search=SEARCH choose search method (local or global)\n"
" -c, --collage collage mode\n"
" -d, --distance=DIST minimum distance between two instances of\n"
Expand Down Expand Up @@ -671,13 +664,11 @@ main (int argc, char *argv[])
break;

case 'm' :
if (strcmp(optarg, "wavelet") == 0)
metric = METRIC_WAVELET;
else if (strcmp(optarg, "subpixel") == 0)
if (strcmp(optarg, "subpixel") == 0)
metric = METRIC_SUBPIXEL;
else
{
fprintf(stderr, "metric must either be subpixel or wavelet\n");
fprintf(stderr, "metric must either be subpixel\n");
return 1;
}
break;
Expand Down Expand Up @@ -1093,13 +1084,11 @@ main (int argc, char *argv[])
this_cheat = val;

}
else if (lisp_match_string("(metric #?(or subpixel wavelet))",
else if (lisp_match_string("(metric #?(or subpixel))",
lisp_car(lst), &var))
{
if (strcmp(lisp_symbol(var), "subpixel") == 0)
this_metric = METRIC_SUBPIXEL;
else
this_metric = METRIC_WAVELET;
}
else if (lisp_match_string("(protocol #?(string))",
lisp_car(lst), &var))
Expand Down
35 changes: 1 addition & 34 deletions metapixel.c
Expand Up @@ -3,7 +3,7 @@
*
* metapixel
*
* Copyright (C) 1997-2004 Mark Probst
* Copyright (C) 1997-2009 Mark Probst
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -37,39 +37,8 @@ metapixel_complete_subpixel (metapixel_t *pixel)
static void
generate_coefficients (metapixel_t *pixel)
{
/*
static float sums[NUM_COEFFS];
static coefficient_with_index_t raw_coeffs[NUM_COEFFS];
*/

bitmap_t *scaled_bitmap;

/* generate wavelet coefficients */
/*
if (pixel->width != WAVELET_IMAGE_SIZE || pixel->height != WAVELET_IMAGE_SIZE)
{
scaled_bitmap = bitmap_scale(pixel->bitmap, WAVELET_IMAGE_SIZE, WAVELET_IMAGE_SIZE, FILTER_MITCHELL);
assert(scaled_bitmap != 0);
}
else
scaled_bitmap = pixel->bitmap;
for (i = 0; i < WAVELET_IMAGE_PIXELS * NUM_CHANNELS; ++i)
float_image[i] = scaled_bitmap->data[i];
if (scaled_bitmap != pixel->bitmap)
bitmap_free(scaled_bitmap);
transform_rgb_to_yiq(float_image, WAVELET_IMAGE_PIXELS);
wavelet_decompose_image(float_image);
wavelet_find_highest_coeffs(float_image, raw_coeffs);
wavelet_generate_coeffs(&pixel->coeffs, sums, raw_coeffs);
for (i = 0; i < NUM_CHANNELS; ++i)
pixel->means[i] = float_image[i];
*/

/* generate subpixel coefficients */
if (pixel->width != NUM_SUBPIXEL_ROWS_COLS || pixel->height != NUM_SUBPIXEL_ROWS_COLS)
{
Expand All @@ -84,8 +53,6 @@ generate_coefficients (metapixel_t *pixel)

//bitmap_write(scaled_bitmap, "/tmp/debug.png");

assert(NUM_SUBPIXELS <= WAVELET_IMAGE_PIXELS);

assert(scaled_bitmap->color == COLOR_RGB_8);
assert(scaled_bitmap->pixel_stride == NUM_CHANNELS);
assert(scaled_bitmap->row_stride == NUM_SUBPIXEL_ROWS_COLS * NUM_CHANNELS);
Expand Down

0 comments on commit a2b979e

Please sign in to comment.