Esempio n. 1
0
Pixel* interpolate(Image *img, double x, double y) {
  assert(x >= 0 && y >= 0); // This is normally hidden by the cast to uint
  Coord tl_coord = {
    .x = (uint16_t) x,
    .y = (uint16_t) y
  };
  Pixel *tl_pix = get_at(img, tl_coord);

  Coord br_coord = {
    .x = (uint16_t) (x+1),
    .y = (uint16_t) (y+1)
  };
  Pixel *br_pix = get_at(img, br_coord);

  Coord tr_coord = {
    .x = br_coord.x,
    .y = tl_coord.y
  };
  Pixel *tr_pix = get_at(img, tr_coord);

  Coord bl_coord = {
    .x = tl_coord.x,
    .y = br_coord.y
  };
  Pixel *bl_pix = get_at(img, bl_coord);

  double resid_x = x - tl_coord.x;
  double resid_y = y - tl_coord.y;

  Pixel *result = malloc(sizeof *result);
  if(!result) {
    EPRINT("Error: Unable to allocate memory for a pixel!\n");
    exit(-1);
  }
  Pixel temp;
  weighted_average_pixel(br_pix, bl_pix, result, resid_x);
  weighted_average_pixel(tr_pix, tl_pix, &temp, resid_x);
  weighted_average_pixel(result, &temp, result, resid_y);
  return result;
}

static Pixel* get_at(Image *img, Coord coord) {
  assert(coord.x < img->width && coord.y < img->height);
    // Dont need to check lower bound because it is underflow.
  return img->data + (coord.y * img->width + coord.x);
}

/* Averages the RGB values of two pixels based on a weighting. The resulting
 * value is stored in the result pixel, so make sure it can be clobbered.
 */
static void weighted_average_pixel(Pixel *first, Pixel *second, Pixel *result, double weight) {
  result->red = (uint8_t)(first->red*weight + second->red*(1-weight));
  result->green = (uint8_t)(first->green*weight + second->green*(1-weight));
  result->blue = (uint8_t)(first->blue*weight + second->blue*(1-weight));
}
Esempio n. 2
0
        void Matrix::do_jacobi_rotation(int p, int q, /*out*/ Matrix & current_transformation)
        {
            check_index(p);
            check_index(q);
            
            // check for invalid rotation
            if(p == q)
            {
                Logger::warning("incorrect jacobi rotation: `p` and `q` must be different indices", __FILE__, __LINE__);
                return;
            }
            
            // if element is already zeroed
            if(0 == get_at(p,q))
                return;

            // r is the remaining index: not p and not q
            int r = 3 - p - q;

            // theta is cotangent of Real rotation angle
            Real theta = (get_at(q,q) - get_at(p,p))/get_at(p,q)/2;
            // t is sin/cos of rotation angle
            // it is determined from equation t^2 + 2*t*theta - 1 = 0,
            // which implies from definition of theta as (cos^2 - sin^2)/(2*sin*cos)
            Real t = (0 != theta) ? sign(theta)/(abs(theta) + sqrt(theta*theta + 1)) : 1;
            Real cosine = 1/sqrt(t*t + 1);
            Real sine = t*cosine;
            // tau is tangent of half of rotation angle
            Real tau = sine/(1 + cosine);

            add_at(p, p, - t*get_at(p,q));
            add_at(q, q, + t*get_at(p,q));
            
            // correction to element at (r,p)
            Real rp_correction = - sine*(get_at(r,q) + tau*get_at(r,p));
            // correction to element at (r,q)
            Real rq_correction = + sine*(get_at(r,p) - tau*get_at(r,q));
            add_at(r, p, rp_correction);
            add_at(p, r, rp_correction);
            add_at(r, q, rq_correction);
            add_at(q, r, rq_correction);
            set_at(p, q, 0);
            set_at(q, p, 0);

            // construct matrix of applied jacobi rotation
            Matrix rotation = Matrix::IDENTITY;
            rotation.set_at(p, p, cosine);
            rotation.set_at(q, q, cosine);
            rotation.set_at(p, q, sine);
            rotation.set_at(q, p, - sine);
            current_transformation = current_transformation*rotation;
        }
Esempio n. 3
0
bool
timecode_factory_v1_c::get_next(packet_cptr &packet) {
  packet->assigned_timecode = get_at(m_frameno);
  if (!m_preserve_duration || (0 >= packet->duration))
    packet->duration = get_at(m_frameno + 1) - packet->assigned_timecode;

  m_frameno++;
  if ((m_frameno > m_ranges[m_current_range].end_frame) && (m_current_range < (m_ranges.size() - 1)))
    m_current_range++;

  mxverb(4, boost::format("ext_timecodes v1: tc %1% dur %2% for %3%\n") % packet->assigned_timecode % packet->duration % (m_frameno - 1));

  return false;
}
Esempio n. 4
0
void *delete_at(List *l, size_t at)
{
	Node *elm = get_at(l, at);
	if (elm == NULL)
		return (void*)OutOfRange;

	if (elm->prev)
		elm->prev->next = elm->next;

	if (elm->next)
		elm->next->prev = elm->prev;

	void *tmp = elm->data;

	if (!elm->prev)
	l->head = elm->next;

	if (!elm->next)
		l->tail = elm->prev;

	free(elm);

	l->size--;
	return tmp;
}
Esempio n. 5
0
ErrorCode insert_at(List *l, size_t at, void *data)
{
	Node *elm = get_at(l, at); //находим элемент по индексу
	if (elm == NULL) {
		if (l->size == 0)
			return push_front(l, data);
		else
			return OutOfRange;
	}
	Node *ins = (Node*) malloc(sizeof(Node)); //создаем новый узел
	ins->data = data;
	//Меняем все адреса
	ins->prev = elm;
	ins->next = elm->next;
	if (elm->next)
		elm->next->prev = ins;

	elm->next = ins;

	if (!elm->prev)
		l->head = elm;
	if (!elm->next)
		l->tail = elm;

	l->size++;
	return (ErrorCode)NULL;
}
Esempio n. 6
0
void MakeSkin(RGBTRIPLE *pOutputBits, const RGBTRIPLE *pInputBits, const LPBITMAPINFOHEADER pbmih)
{
	const float a = (float) (pbmih->biWidth) / (float) (FRAME_WIDTH);
	const float b = (float) (pbmih->biHeight) / (float) (FRAME_HEIGHT);
	_tprintf("processing");
	for( int y_frame = 0; y_frame < Y_FRAMES; y_frame++ )
	{
		_tprintf("..");
		for( int x_frame = 0; x_frame < X_FRAMES; x_frame++ )
		{
			float angle = (float) ((Y_FRAMES - y_frame - 1) * X_FRAMES + x_frame) / (float) FRAME_COUNT * 6.2831853f;
			float s = sinf(angle), c = cosf(angle);
			for( int y = 0; y < FRAME_HEIGHT; y++ )
            for( int x = 0; x < FRAME_WIDTH; x++ )
			{
				float x0 = (x*a - (float) pbmih->biWidth * 0.5f) + 0.5f;
				float y0 = (y*b - (float) pbmih->biHeight * 0.5f)  + 0.5f;
				pixel( pOutputBits, 
					FRAME_WIDTH * X_FRAMES, 
					x + FRAME_WIDTH * x_frame, 
					y + FRAME_HEIGHT * y_frame
				) = get_at(	pInputBits, pbmih, 
					x0 * c - y0 * s + (float) pbmih->biWidth * 0.5f - 0.5f, 
					y0 * c + x0 * s + (float) pbmih->biHeight * 0.5f - 0.5f
				);
			}
		}
	}
	_tprintf(" done!\n");
}
Esempio n. 7
0
	bool contact_profile::unserialize(Ui::gui_coll_helper _coll)
	{
		aimid_ = _coll.get_value_as_string("aimid");
		first_name_ = _coll.get_value_as_string("firstname");
		last_name_ = _coll.get_value_as_string("lastname");
		friendly_ = _coll.get_value_as_string("friendly");
		displayid_ = _coll.get_value_as_string("displayid");
		relationship_ = _coll.get_value_as_string("relationship");
		about_ = _coll.get_value_as_string("about");
		birthdate_ = _coll.get_value_as_int64("birthdate");
		gender_ = _coll.get_value_as_string("gender");

		Ui::gui_coll_helper coll_address(_coll.get_value_as_collection("homeaddress"), false);
		home_address_.unserialize(coll_address);

        auto phones = _coll.get_value_as_array("phones");
        for (int i = 0; phones && i < phones->size(); ++i)
        {
            Ui::gui_coll_helper coll_phone(phones->get_at(i)->get_as_collection(), false);
            phone p;
            p.unserialize(coll_phone);
            phones_.push_back(p);
        }
        
		return true;
	}
Esempio n. 8
0
int summ_elements_from(List *l, size_t pos)
{
	int ret = 0;
	for (size_t i = pos; i < l->size; i++) {
		ret += *((int*)(get_at(l,i)->data));
	}
	return ret;
}
Esempio n. 9
0
        Vector Matrix::get_column(int column) const
        {
            Vector result;
            for(int i = 0; i < VECTOR_SIZE; ++i)
                result[i] = get_at(i, column);

            return result;
        }
Esempio n. 10
0
        Vector Matrix::get_row(int row) const
        {
            Vector result;
            for(int j = 0; j < VECTOR_SIZE; ++j)
                result[j] = get_at(row, j);

            return result;
        }
Esempio n. 11
0
 bool Matrix::operator==(const Matrix &another) const
 {
     for(int i = 0; i < VECTOR_SIZE; ++i)
         for(int j = 0; j < VECTOR_SIZE; ++j)
             if( ! equal( get_at(i, j), another.get_at(i, j) ) )
                 return false;
     return true;
 }
Esempio n. 12
0
void matrix4::print() {
    printf("matrix4:\n");
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            printf("(%d, %d) = %f\n", i, j, get_at(i, j));
        }
    }
}
Esempio n. 13
0
void print_int(const struct t_list *plist)
{
	int i = 1;
	int len = get_length(plist);
	struct t_node *node = NULL;
	for (i = 1; i <= len; ++i) {
		node = get_at(plist, i);
		printf("%d%c", *(int *)node->val, i == len ? '\n' : ' ');
	}
}
Esempio n. 14
0
        bool Matrix::invert()
        {
            Real det = determinant();
            if(equal(0, det))
            {
                return false;
            }

            Matrix cofactors;
            Real value;
            for(int i = 0; i < VECTOR_SIZE; ++i)
            {
                for(int j = 0; j < VECTOR_SIZE; ++j)
                {
                    value = get_at((i+1)%3, (j+1)%3)*get_at((i+2)%3, (j+2)%3)
                        - get_at((i+1)%3, (j+2)%3)*get_at((i+2)%3, (j+1)%3);
                    cofactors.set_at(j, i, value); // already transposed
                }
            }
            *this = cofactors /= det;
            return true;
        }
Esempio n. 15
0
int main(void) { //Hlavni telo programu
        string str1, str2;
        int p; char zero;

        str1 = "Toto je nejaky text";
        str2 = strcat(str1, ", ktery jeste trochu obohatime");
        print(str1, '\n', str2, "\n");

        str1 = read_string();
        while ((int)(get_at(str1, p)) != 0)
        {
                p = p + 1;
        }
        print("\nDelka retezce \"", str1, "\", je ", p, " znaku.\n");
}
Esempio n. 16
0
int array::linear_search(const void * key, icomparer* compar,void*& presult)
{
    int nBegin= 0;
    int nLast  = m_nSize - 1;

    register void* p;
    while ( nLast >= nBegin ) {
        if ( get_at(nBegin, p) < 0 )
            return -1;

        register int res = compar->compare_linear(m_nObjectIndex,key,p);
        if ( res == 0 ) {
            memcpy((char*)presult,(char*)p,m_nRecordSize);
            return 1;
        }
        nBegin ++;
    }
    presult = 0;
    return 0;
}
Esempio n. 17
0
/**
 * qlist->popat(): Returns and remove the element at the specified
 * position in this list.
 *
 * @param list   qlist_t container pointer.
 * @param index  index at which the specified element is to be inserted
 * @param size   if size is not NULL, element size will be stored.
 *
 * @return a pointer of malloced element, otherwise returns NULL.
 * @retval errno will be set in error condition.
 *  -ERANGE : Index out of range.
 *  -ENOMEM : Memory allocation failure.
 *
 * @code
 *                     first           last
 *  Linked-list        [ A ]<=>[ B ]<=>[ C ]
 *  (positive index)     0       1       2
 *  (negative index)    -3      -2      -1
 * @endcode
 *
 * @note
 *  Negative index can be used for addressing a element from the end in this
 *  stack. For example, index -1 is same as poplast() and index 0 is same as
 *  popfirst();
 */
void *qlist_popat(qlist_t *list, int index, size_t *size) {
    return get_at(list, index, size, true, true);
}
Esempio n. 18
0
/**
 * qlist->getat(): Returns the element at the specified position in this
 * list.
 *
 * @param list    qlist_t container pointer.
 * @param index   index at which the specified element is to be inserted
 * @param size    if size is not NULL, element size will be stored.
 * @param newmem  whether or not to allocate memory for the element.
 *
 * @return a pointer of element, otherwise returns NULL.
 * @retval errno
 * @retval errno will be set in error condition.
 *  -ERANGE : Index out of range.
 *  -ENOMEM : Memory allocation failure.
 *
 * @code
 *                     first           last
 *  Linked-list        [ A ]<=>[ B ]<=>[ C ]
 *  (positive index)     0       1       2
 *  (negative index)    -3      -2      -1
 * @endcode
 *
 * @note
 *  Negative index can be used for addressing a element from the end in this
 *  stack. For example, index -1 is same as getlast() and index 0 is same as
 *  getfirst();
 */
void *qlist_getat(qlist_t *list, int index, size_t *size, bool newmem) {
    return get_at(list, index, size, newmem, false);
}