Exemple #1
0
void test_DCT_transform_array_of_8_elements_and_should_invert_back_to_original_by_IDCT(){
  float imageMatrix[8] = {1,2,3,4,5,6,7,8};

  oneD_DCT_row(imageMatrix, sizeof(imageMatrix)/sizeof(float));
  
  TEST_ASSERT_FLOAT_WITHIN(0.001, 12.727, imageMatrix[0]);
  TEST_ASSERT_FLOAT_WITHIN(0.001, -6.442, imageMatrix[1]);
  TEST_ASSERT_FLOAT_WITHIN(0.001, 0, imageMatrix[2]);
  TEST_ASSERT_FLOAT_WITHIN(0.001, -0.673, imageMatrix[3]);
  TEST_ASSERT_FLOAT_WITHIN(0.001, 0, imageMatrix[4]);
  TEST_ASSERT_FLOAT_WITHIN(0.001, -0.200, imageMatrix[5]);
  TEST_ASSERT_FLOAT_WITHIN(0.001, 0, imageMatrix[6]);
  TEST_ASSERT_FLOAT_WITHIN(0.001, -0.050, imageMatrix[7]);
  
  oneD_IDCT_row(imageMatrix, 8);
  round_float(imageMatrix, 8);
  
  TEST_ASSERT_EQUAL(1,imageMatrix[0]);
  TEST_ASSERT_EQUAL(2,imageMatrix[1]);
  TEST_ASSERT_EQUAL(3,imageMatrix[2]);
  TEST_ASSERT_EQUAL(4,imageMatrix[3]);
  TEST_ASSERT_EQUAL(5,imageMatrix[4]);
  TEST_ASSERT_EQUAL(6,imageMatrix[5]);
  TEST_ASSERT_EQUAL(7,imageMatrix[6]);
  TEST_ASSERT_EQUAL(8,imageMatrix[7]);
}
Exemple #2
0
static void
abs_rect_to_ent_surface_rect(VisibleEnt *ent, const SDL_Rect *src, SDL_Rect *dest)
{
    SDL_Rect result = *src;
    const SDL_Rect *image_rect = VisibleEnt_GET(image_rect, ent);
    const vec2 *position = Ent_GET(position, ent);
    
    // Make rectangle relative to ent position
    result.x -= (int)round_float(position->x);
    result.y -= (int)round_float(position->y);

    // Then convert relative positions to absolute positions inside the surface
    result.x += image_rect->x;
    result.y += image_rect->y;
    result.w = min(image_rect->w, result.w);
    result.h = min(image_rect->h, result.h);

    *dest = result;
}
Exemple #3
0
void test_DCT_transform_array_of_3_elements_and_should_invert_back_to_original_by_IDCT(){
  float imageMatrix[3] = {1, 2, 3};
  
  oneD_DCT_row(imageMatrix, sizeof(imageMatrix)/sizeof(float));
  
  TEST_ASSERT_FLOAT_WITHIN(0.001, 3.464, imageMatrix[0]);
  TEST_ASSERT_FLOAT_WITHIN(0.001, -1.414, imageMatrix[1]);
  TEST_ASSERT_FLOAT_WITHIN(0.001, 0, imageMatrix[2]);
  
  oneD_IDCT_row(imageMatrix, 3);
  round_float(imageMatrix, 3);
  
  TEST_ASSERT_EQUAL(1,imageMatrix[0]);
  TEST_ASSERT_EQUAL(2,imageMatrix[1]);
  TEST_ASSERT_EQUAL(3,imageMatrix[2]);
}
Exemple #4
0
int FadeBend::jog()
{
	int direction = (m_fade->get_fade_type() == FadeCurve::FadeIn) ? 1 : -1;
	
	float dx = (float(origY - cpointer().y()) / CURSOR_SPEED);

	if (m_fade->get_raster()) {
		float value = round_float(oldValue + dx * direction);
		m_fade->set_bend_factor(value);
	} else {
		m_fade->set_bend_factor(oldValue + dx * direction);
	}

	oldValue = m_fade->get_bend_factor();
	newBend = oldValue;
	cpointer().setCursorText(QByteArray::number(newBend, 'f', 2));
	
	origY = cpointer().y();
	
	return 1;
}
Exemple #5
0
int FadeStrength::jog()
{
	float dy = float(origY - cpointer().y()) / CURSOR_SPEED;
	
	if (m_fade->get_bend_factor() >= 0.5) {
		m_fade->set_strength_factor(oldValue + dy );
	} else {
		if (m_fade->get_raster()) {
			float value = round_float(oldValue + dy);
			m_fade->set_strength_factor(value);
		} else {
			m_fade->set_strength_factor(oldValue - dy);
		}
	}
	
	oldValue = m_fade->get_strength_factor();
	newStrength = oldValue;
	cpointer().setCursorText(QByteArray::number(newStrength, 'f', 2));

	origY = cpointer().y();

	return 1;
}
Exemple #6
0
static void
Boat_update_image(Boat *boat)
{
    SDL_Rect rect = {0, 0, BOAT_SPRITE_SIZE, BOAT_SPRITE_SIZE};
    int row, col, new_image_index;

    float angle = angle_normalize(Ent_GET(rotation, boat));
    if(angle < 0)
        angle = 360 + angle;

    new_image_index = (int)round_float(angle / BOAT_SPRITE_ANGLE_INTERVAL);
    if(new_image_index == Boat_GET(image_index, boat))
        return;
    
    row = new_image_index / BOAT_SPRITE_COLS;
    col = new_image_index % BOAT_SPRITE_COLS;
    rect.x = col * BOAT_SPRITE_SIZE;
    rect.y = row * BOAT_SPRITE_SIZE;

    VisibleEnt_SET(image_rect, boat, &rect);
    Boat_SET(image_index, boat, new_image_index);
    Ent_SET(bounds_width, boat, rect.w);
    Ent_SET(bounds_height, boat, rect.h);
}