view task/Run.cc @ 8:ec2c1003f9b6 default tip

fix mandel
author yutaka@localhost.localdomain
date Mon, 12 Apr 2010 23:58:19 +0900
parents febf899d0043
children
line wrap: on
line source

#include <stdio.h>
#include <math.h>
#include "Run.h"

#define DIB_BYTE (8);

typedef struct {

  float red;
  float green;
  float bule;
  float alpha;

} rgb_t;

void*
div(void *buff, int size)
{

  char* p;
  p = (char*)buff;
  p = p + size;

  return p;

}

void
mandelbrot(float &za, float &zb, float cx, float cy) {

  float tmp_za = za;
  float tmp_zb = zb;

  za = tmp_za * tmp_za - tmp_zb * tmp_zb + cx;
  zb = 2 * tmp_za * tmp_zb + cy;

}

void
set_rgb(rgb_t rgb, int *pixels)
{

  *pixels = ((char)rgb.alpha) << 24 | ((char)rgb.red) << 16 | ((char)rgb.green) << 8 | ((char)rgb.bule);

}

void
run(void *in, void *out, int size_in, int size_out)
{

  int *pixels = (int*)out;
  int *params = (int*)in;

  int location = params[0];
  int width = params[1];
  int height = params[2];
  int bpp = params[3];
  int params_size = params[4];
  int color_table_size = params[5];

  char *color = (char*)div(in,params_size);

  //byte単位
  int pixel_size = bpp / DIB_BYTE;

  int center_x = width / 2;
  int center_y = height / 2;
  int x_move = 200;
  float scale = 500.f;

  for (int l = location; l <= location + size_out; l += pixel_size) {

    int x = l / pixel_size % width;
    int y = l / pixel_size / width;

    float a = 0;
    float b = 0;

    float cx = (x - (center_x + x_move)) / scale;
    float cy = (y - center_y) / scale;
    
    int i;
    for (i = 0; i < 255; i++) {

      mandelbrot(a, b, cx, cy);

      if( a*a + b*b > 4) {
	break;
      }

    }

    rgb_t rgb;
    rgb.red = color[i];
    rgb.green = color[i];
    rgb.bule = color[i];
    rgb.alpha = 1;
    
    set_rgb( rgb, &pixels[(l - location) / pixel_size] );
  }

}