gegl r2306 - in branches/branch_zhangjb: . operations/frequency
- From: zhangjb svn gnome org
- To: svn-commits-list gnome org
- Subject: gegl r2306 - in branches/branch_zhangjb: . operations/frequency
- Date: Sat, 17 May 2008 18:03:37 +0000 (UTC)
Author: zhangjb
Date: Sat May 17 18:03:37 2008
New Revision: 2306
URL: http://svn.gnome.org/viewvc/gegl?rev=2306&view=rev
Log:
* operations/freqency/dft.c: applied a patch from pippin, and replaced
all tabs to spaces.
Modified:
branches/branch_zhangjb/ChangeLog
branches/branch_zhangjb/operations/frequency/dft.c
Modified: branches/branch_zhangjb/operations/frequency/dft.c
==============================================================================
--- branches/branch_zhangjb/operations/frequency/dft.c (original)
+++ branches/branch_zhangjb/operations/frequency/dft.c Sat May 17 18:03:37 2008
@@ -23,89 +23,95 @@
static gint fft_complex_get_half_id(gint x, gint y, gint width, gint height)
{
- if (x >= FFT_HALF(x)) {
- if (y == 0)
- return ELEM_ID_HALF_MATRIX(width-x, y, width);
- else
- return ELEM_ID_HALF_MATRIX(width-x, height-y, width);
- } else
- return 0;
+ if (x >= FFT_HALF(x)) {
+ if (y == 0)
+ return ELEM_ID_HALF_MATRIX(width-x, y, width);
+ else
+ return ELEM_ID_HALF_MATRIX(width-x, height-y, width);
+ } else
+ return 0;
}
static void prepare(GeglOperation *operation)
{
- Babl *image_format = babl_format("RGB float");
- Babl *frequency_format = babl_format("Y float"); /* use "Y_float" temporarily */
-
- gegl_operation_set_format(operation, "input", image_format);
- gegl_operation_set_format(operation, "output", frequency_format);
+ Babl *image_format = babl_format_new(babl_model("RGB"),
+ babl_type("double"),
+ babl_component("R"),
+ babl_component("G"),
+ babl_component("B"),
+ NULL);
+ Babl *frequency_format = babl_format_new(babl_model("Y"),
+ babl_type("double"),
+ babl_component("Y"),
+ NULL);
+ gegl_operation_set_format(operation, "input", image_format);
+ gegl_operation_set_format(operation, "output", frequency_format);
}
static gboolean process(GeglOperation *operation,
- GeglBuffer *input,
- GeglBuffer *output,
- const GeglRectangle *result)
+ GeglBuffer *input,
+ GeglBuffer *output,
+ const GeglRectangle *result)
{
- gint width= gegl_buffer_get_width(input);
- gint height= gegl_buffer_get_height(input);
- gfloat *src_buf, *dst_buf;
- gint i, j;
- fftw_complex *fft_out;
- fftw_plan fftplan;
-
- src_buf = g_new0 (gfloat, gegl_buffer_get_pixel_count (input) * 3);
- gegl_buffer_get(input, 1.0, NULL, babl_format("RGB float"), src_buf,
- GEGL_AUTO_ROWSTRIDE);
-
- /* fetch R component pixes */
- dst_buf = g_new0 (gfloat, height*width);
- for (i=0; i<width*height; i++) {
- dst_buf[i] = src_buf[3 * i];
- }
-
- /* take DFT for the 'R' component of a RGB image */
- fft_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * height
- * FFT_HALF(width));
- fftplan = fftw_plan_dft_r2c_2d(height, width, (float *)dst_buf, fft_out,
- FFTW_ESTIMATE);
- fftw_execute(fftplan);
-
- /* just for test: output the real component of the frequncy domain */
- for (i=0; i<height; i++) {
- for (j=0; j<width; j++) {
- if (j<FFT_HALF(width))
- dst_buf[ELEM_ID_MATRIX(j, i, width)] =
- fft_out[ELEM_ID_HALF_MATRIX(j, i, width)][0]/33614026;
- else
- dst_buf[ELEM_ID_MATRIX(j, i, width)] =
- fft_out[fft_complex_get_half_id(i, i, width, height)][0]/33614026;
- }
- }
- gegl_buffer_set(output, NULL, babl_format("Y float"), dst_buf, GEGL_AUTO_ROWSTRIDE);
-
- fftw_destroy_plan(fftplan);
- fftw_free(fft_out);
+ gint width= gegl_buffer_get_width(input);
+ gint height= gegl_buffer_get_height(input);
+ gdouble *src_buf, *dst_buf;
+ gint i, j;
+ fftw_complex *fft_out;
+ fftw_plan fftplan;
+
+ src_buf = g_new0(gdouble, gegl_buffer_get_pixel_count(input) * 3);
+ gegl_buffer_get(input, 1.0, NULL, NULL, src_buf, GEGL_AUTO_ROWSTRIDE);
+
+ /* fetch R component pixes */
+ dst_buf = g_new0(gdouble, height*width);
+ for (i=0; i<width*height; i++) {
+ dst_buf[i] = src_buf[3 * i];
+ }
+
+ /* take DFT for the 'R' component of a RGB image */
+ fft_out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * height
+ * FFT_HALF(width));
+ fftplan = fftw_plan_dft_r2c_2d(height, width, (double *)dst_buf, fft_out,
+ FFTW_ESTIMATE);
+ fftw_execute(fftplan);
+#if 1
+
+ /* just for test: output the real component of the frequncy domain */
+ for (i=0; i<height; i++) {
+ for (j=0; j<width; j++) {
+ if (j<FFT_HALF(width))
+ dst_buf[ELEM_ID_MATRIX(j, i, width)] = fft_out[ELEM_ID_HALF_MATRIX(j, i, width)][0]/33614026;
+ else
+ dst_buf[ELEM_ID_MATRIX(j, i, width)] = fft_out[fft_complex_get_half_id(i, i, width, height)][0]/33614026;
+ }
+ }
+#endif
+ gegl_buffer_set(output, NULL, NULL, dst_buf, GEGL_AUTO_ROWSTRIDE);
+
+ fftw_destroy_plan(fftplan);
+ fftw_free(fft_out);
- return TRUE;
+ return TRUE;
}
static void gegl_chant_class_init(GeglChantClass *klass)
{
- GeglOperationClass *operation_class;
- GeglOperationFilterClass *filter_class;
+ GeglOperationClass *operation_class;
+ GeglOperationFilterClass *filter_class;
- operation_class = GEGL_OPERATION_CLASS(klass);
- filter_class = GEGL_OPERATION_FILTER_CLASS(klass);
+ operation_class = GEGL_OPERATION_CLASS(klass);
+ filter_class = GEGL_OPERATION_FILTER_CLASS(klass);
- filter_class->process = process;
- operation_class->prepare = prepare;
+ filter_class->process = process;
+ operation_class->prepare = prepare;
- operation_class->name = "dft";
- operation_class->categories = "frequency";
- operation_class->description
- = "Perform 2-D Discrete Fourier Transform for the image.\n"
- "Note this operation is just for test, which can NOT be "
- "used to do anything by now.";
+ operation_class->name = "dft";
+ operation_class->categories = "frequency";
+ operation_class->description
+ = "Perform 2-D Discrete Fourier Transform for the image.\n"
+ "Note this operation is just for test, which can NOT be "
+ "used to do anything by now.";
}
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]