Exemple #1
0
void		aff(t_tree *tree, int pos)
{
  int		i;

  i = -5;
  if (tree)
    {
      while (i < pos)
	{
	  printf("_");
	  i++;
	}
      printf("%d %s\n", pos, strdup(tree->data));
      if (tree->left)
	{
	  printf("left ");
	  aff(tree->left, pos - 2);
	}
      if (tree->right)
	{
	  printf("right ");
	  aff(tree->right, pos + 3);
	}
    }
}
Exemple #2
0
/*
** Check la présence d'erreur avant de lancer les instructions
*/
int		error(int ac, char **av)
{
  if (ac != 2)
    aff("\n ! Vous devez avoir un argument au programme !\n\n");
  else if (!file_exists(av[1]))
    aff("Votre fichier n'existe pas");
  else
    return (0);
  return (1);
}
Exemple #3
0
void aff(ABRe *abr, int h)
{
    int i;
    for (i=0;i<h;i++)
    {
        printf("|___ ");
    }
 
    printf("%d\n", abr->n->u);
    if (abr->g) aff(abr->g, h+1);
    if (abr->d) aff(abr->d, h+1);
}
void		aff_arena(t_glob *g)
{
	int		i;
	int		j;
	char	*s;

	i = 0;
	g->e->x_0 = 30;
	g->e->y_0 = 40;
	j = 0;
	while (i < MEM_SIZE)
	{
		if (j == 64)
		{
			g->e->x_0 = 30;
			g->e->y_0 += 20;
			j = 0;
		}
		s = ft_itoa_base_unsigned(g->arena[i], 16);
		aff(i, g, s);
		g->e->x_0 += 30;
		i++;
		j++;
		free(s);
	}
	aff_legend(g);
}
int main() {
/*
    int numPoints = 20;
    cv::Mat in0(numPoints, 3, CV_32F);
    cv::Mat in1(numPoints, 3, CV_32F);
    cv::Mat affinTransform(3, 4, CV_32F);
    cv::Mat inliers;

    for (int i=0; i<20; i++) {
        in0.at<float>(i,0) = i;
        in0.at<float>(i,1) = 0;
        in0.at<float>(i,2) = 0;

        in1.at<float>(i,0) = i;
        in1.at<float>(i,1) = 1;
        in1.at<float>(i,2) = 1;
    }

    cv::estimateAffine3D(in0, in1, affinTransform, inliers);
*/
    std::vector<cv::Point3f> first, second;
    std::vector<uchar> inliers;
    cv::Mat aff(3,4,CV_64F);

    for (int i = 0; i <6; i++)
    {
        first.push_back(cv::Point3f(i,i%3,1));
        second.push_back(cv::Point3f(i,i%3,1));
    }

    int ret = cv::estimateAffine3D(first, second, aff, inliers);
    std::cout << aff << std::endl;

}
Exemple #6
0
void	gere_event(t_graph *g, int *cont, int i, int dec)
{
  Uint32	pause;
  Uint32	to;
  SDL_Event	event;

  pause = SDL_GetTicks();
  if (dec)
    set_cursor(g);
  to = SDL_GetTicks();
  while ((to - pause < 1 && *cont) || (i && *cont))
    {
      if (g->key)
	iterate(g);
      aff(g, i);
      while (SDL_PollEvent(&event))
	{
	  if (event.type == SDL_KEYDOWN)
	    keydown(g, event, cont);
	  if (event.type == SDL_KEYUP)
	    keyup(g, event);
	  if (event.type == SDL_MOUSEMOTION)
	    mousemove(g, event);
	}
      to = SDL_GetTicks();
    }
  if (i)
    *cont = -1;
}
	//------------------------------------------------------------
	void get_render_vector(
		const double frame, const TAffine affine, TPointD &rend_vect)
	{
		/*--- ベクトルを得て、render用単位にする ---*/
		if (0 == this->m_depend_move->getValue()) {
			rend_vect.x = this->m_x2->getValue(frame) -
						  this->m_x1->getValue(frame);
			rend_vect.y = this->m_y2->getValue(frame) -
						  this->m_y1->getValue(frame);

			rend_vect = rend_vect * ino::pixel_per_mm();
			/* 単位変換(mm --> render_pixel) */
		} else {
			rend_vect = -this->getAttributes()->getSpeed();
		}

		/*--- 回転と拡大縮小のGeometryを反映させる ---*/
		/*
		toonz/main/sources/stdfx/motionblurfx.cpp
		750-768行を参照して書いた
		*/
		TAffine aff(affine);
		aff.a13 = aff.a23 = 0; /* 移動変換をしないで... */

		rend_vect = aff * rend_vect;

		/*--- ユーザー指定による、強弱を付加する ---*/
		rend_vect = rend_vect * (this->m_scale->getValue(frame) / ino::param_range());
		/*--- shrinkはGeometry(affine)に含まれる...らしい ---*/
		// rend_vect = rend_vect
		//	* (1.0 / ((info.m_shrinkX + info.m_shrinkY)/2.));
	}
int main(int argc, char *argv[])
{
    (void)argc;
    (void)argv;

    std::ofstream dic ("hunspell-test.dic");
    dic << "2\nHello\nWorld";
    dic.close();
    std::ofstream aff ("hunspell-test.aff");
    aff << "SET UTF-8\nTRY loredWH\nMAXDIFF 1";
    aff.close();
    Hunspell h("hunspell-test.aff", "hunspell-test.dic");

    if (h.spell("Hello") == 0)
    {
        std::cerr << "Error: hunspell marked correct word as wrong" << std::endl;
    }
    if (h.spell("wrld") != 0)
    {
        std::cerr << "Error: hunspell marked wrong word as correct" << std::endl;
    }

    char ** result;
    int n = h.suggest(&result, "ell");
    for (int i = 0; i < n; i++) std::cout << result[i];

    return 0;
}
Exemple #9
0
Fichier : main.c Projet : nd4pa/tp
int main()
{
	Noeud *racine = create("salut");
	printf("fils D : %d, fils G %d\n",right(racine),left(racine));
	printf("racine :");
	aff(racine->val);
	return 0;
}
Exemple #10
0
static void		rec_treeprefix(t_tree *a, int (*aff)(), char *sep)
{
	if (!a)
		return ;
	aff(a->content);
	if (sep)
		ft_putstr(sep);
	rec_treeprefix(a->left, aff, sep);
	rec_treeprefix(a->right, aff, sep);
}
Exemple #11
0
Picture* OnlineHandwritingPicture::distort(RNG& rng, batchType type) {
  OnlineHandwritingPicture* pic=new OnlineHandwritingPicture(*this);
  if (type==TRAINBATCH) {
    arma::mat aff=arma::eye(2,2);
    aff(0,0)+=rng.uniform(-0.3,0.3); //x stretch
    aff(1,1)+=rng.uniform(-0.3,0.3); //y stretch
    int r=rng.randint(3);
    float alpha=rng.uniform(-0.3,0.3);
    arma::mat x=arma::eye(2,2);
    if (r==0) x(0,1)=alpha;
    if (r==1) x(1,0)=alpha;
    if (r==2) {x(0,0)=cos(alpha);x(0,1)=-sin(alpha);x(1,0)=sin(alpha);x(1,1)=cos(alpha);}
    aff=aff*x;
    arma::mat y(1,2);
    y(0,0)=renderSize*rng.uniform(-0.1875,0.1875);
    y(0,1)=renderSize*rng.uniform(-0.1875,0.1875);
    for (int i=0;i<ops.size();++i)
      pic->ops[i]=pic->ops[i]*aff+arma::repmat(y,pic->ops[i].n_rows,1);
    pic->offset3d=rng.uniform(-0.1,0.1);
  }
  return pic;
}
PERF_TEST_P( EstimateAffine, EstimateAffine2D, ESTIMATE_PARAMS )
{
    AffineParams params = GetParam();
    const int n = get<0>(params);
    const double confidence = get<1>(params);
    const int method = get<2>(params);
    const size_t refining = get<3>(params);

    Mat aff(2, 3, CV_64F);
    cv::randu(aff, -2., 2.);

    // LMEDS can't handle more than 50% outliers (by design)
    int m;
    if (method == LMEDS)
        m = 3*n/5;
    else
        m = 2*n/5;
    const float shift_outl = 15.f;
    const float noise_level = 20.f;

    Mat fpts(1, n, CV_32FC2);
    Mat tpts(1, n, CV_32FC2);

    randu(fpts, 0., 100.);
    transform(fpts, tpts, aff);

    /* adding noise to some points */
    Mat outliers = tpts.colRange(m, n);
    outliers.reshape(1) += shift_outl;

    Mat noise (outliers.size(), outliers.type());
    randu(noise, 0., noise_level);
    outliers += noise;

    Mat aff_est;
    vector<uchar> inliers (n);

    warmup(inliers, WARMUP_WRITE);
    warmup(fpts, WARMUP_READ);
    warmup(tpts, WARMUP_READ);

    TEST_CYCLE()
    {
        aff_est = estimateAffine2D(fpts, tpts, inliers, method, 3, 2000, confidence, refining);
    }

    // we already have accuracy tests
    SANITY_CHECK_NOTHING();
}
	void update()
	{
		TPointD p0 = m_controlPoints[0];
		TPointD p1 = m_controlPoints[2];
		TPointD p2 = m_controlPoints[4];
		double a00 = p0.x - p2.x, a01 = p1.x - p2.x, a10 = p0.y - p2.y, a11 = p1.y - p2.y;
		TAffine aff(a00, a01, 0, a10, a11, 0);
		aff = aff.inv();
		TPointD d = -(aff * p2);
		aff.a13 = d.x;
		aff.a23 = d.y;
		m_aff = aff;
		m_delta.resize(3);
		m_delta[0] = m_controlPoints[1] - p0;
		m_delta[1] = m_controlPoints[3] - p1;
		m_delta[2] = m_controlPoints[5] - p2;
	}
int main() {
  ABR *a=NULL;
  a=insertion(a,2);
  a=insertion(a,5);
  a=insertion(a,9);
  a=insertion(a,1);
  a=insertion(a,12);
  a=insertion(a,15);
  a=insertion(a,20);
  a=insertion(a,50);
  a=insertion(a,90);
  a=insertion(a,10);
  a=insertion(a,120);
  a=insertion(a,150);
  aff(a,0);
  return 0;
}
inline affinity_graph_ptr<T>
read_affinity_graph_from_file( const std::string& fname,
                               std::size_t xsize,
                               std::size_t ysize,
                               std::size_t zsize )
{
    affinity_graph_ptr<T> aff(new affinity_graph<T>
                              (boost::extents[xsize][ysize][zsize][3],
                               boost::fortran_storage_order()));

    if ( !read_from_file(fname, aff->data(), xsize*ysize*zsize*3) )
    {
        throw 0;
    }

    return aff;
}
Exemple #16
0
void	ft_ldcputnext(t_ldc *list, void(*aff)(), char *sep)
{
	if (!list)
	{
		ft_putendl(NULL);
		return ;
	}
	if (list->content == NULL)
		list = list->next;
	while (list->content)
	{
		aff(list->content);
		if (list->next->content)
			ft_putstr(sep);
		list = list->next;
	}
	ft_putchar('\n');
}
Exemple #17
0
  //------------------------------------------------------------
  double get_render_real_radius(const double frame, const TAffine affine) {
    /*--- ベクトルにする --- */
    TPointD rend_vect;
    rend_vect.x = this->m_radius->getValue(frame);
    rend_vect.y = 0.0;
    /*--- render用単位にする ---*/
    rend_vect = rend_vect * ino::pixel_per_mm();
    /* 単位変換(mm --> render_pixel) */
    /*--- 回転と拡大縮小のGeometryを反映させる ---*/
    /* 以下は、
toonz/main/sources/stdfx/motionblurfx.cpp
586-592行を参照して書いた
*/
    TAffine aff(affine);
    aff.a13 = aff.a23 = 0; /* 移動変換をしないで... */
    rend_vect         = aff * rend_vect;
    /*--- 方向は無視して長さを返す ---*/
    return sqrt(rend_vect.x * rend_vect.x + rend_vect.y * rend_vect.y);
  }
Exemple #18
0
int recu(char *tab, int line)
{
        static int solution = 0;
        int cas;
 
        if (line == 8) {
                aff(tab);
                return ++solution;
        }
 
        for (cas = 0; cas < 8; cas++) {
                if (!is_valid(tab, line, cas)) {
                        tab[line] = cas;          
                        recu(tab, line + 1);
                        tab[line] = 9;
                }
        }
 
        return solution;
}
Exemple #19
0
int	main(int argc,char *argv[])
{
//	char	*hd  = NULL ;
	char	*cfg  = NULL ;
	char	*obj  = NULL ;
	int	f ;
	int	nb ;
	char	nexttype = '\0' ;
	char	*pt;
	char	*file;
	int	nbr	= 0;

	char	*mem;
	struct	stat	st;


	if	( argc < 2 )
	{
		usage	() ;
		exit	(1) ;
	}


	XoInit	(0) ;

	for	( nb = 1 ; nb < argc ; nb++ )
	{
		pt	= argv[nb];
		file	= pt ;
		if	( memcmp(pt,"-xml",4) == 0 )
		{
			Xml	= 1;
			continue;
		}
		if	( memcmp(pt,"-shdico",7) == 0 )
		{
			XoLoadSharedDicoDir(".");
			continue;
		}
		if	( memcmp(pt,"-r",2) == 0 )
		{
			nexttype	= 'r' ;
			if	( *(pt+2) == '\0' )
				continue ;
			else
				file	= pt+2 ;
		}
		if	( memcmp(pt,"-d",2) == 0 )
		{
			nexttype	= 'd' ;
			if	( *(pt+2) == '\0' )
				continue ;
			else
				file	= pt+2 ;
		}
		if	( memcmp(pt,"-m",2) == 0 )
		{
			nexttype	= 'm' ;
			if	( *(pt+2) == '\0' )
				continue ;
			else
				file	= pt+2 ;
		}

		f	= open(file,XO_FIC_BINARY|O_RDONLY) ;
		if	( !f )
		{
			fprintf(stderr,"cannot open '%s'\n",file) ;
			fflush(stderr) ;
			exit(1) ;
		}
		switch	(nexttype)
		{
			case	'r':		/* references */
				cfg	= XoLoadRef(f) ;
				if	( !cfg )
				{
					fprintf(stderr,"\tload ref err : %s\n",
							file) ;	
					fflush(stderr) ;
					exit(1) ;
				}
				nbr++;
			break ;
			case	'd':		/* donnees */
				if (nbr == 0)
				{
					DefaultLoadRef();
					nbr	= -1;
				}
				obj	= XoLoad(f) ;
				if	( !obj )
				{
					fprintf(stderr,"\tload obj err : %s\n",
						file) ;	
					fflush(stderr) ;
					exit(1) ;
				}
				aff	(obj) ;
			break ;
			case	'm':		/* donnees */
				if (nbr == 0)
				{
					DefaultLoadRef();
					nbr	= -1;
				}
				if	(fstat(f,&st) < 0)
				{
					fprintf(stderr,"cannot fstat '%s'\n",
							file) ;
					fflush(stderr) ;
					exit(1) ;
				}
				mem	= (char *)malloc(st.st_size);
				if	(!mem)
				{
					fprintf(stderr,"cannot alloc %d '%s'\n",
							(int)st.st_size,file) ;
					fflush(stderr) ;
					exit(1) ;
				}
				if	(read(f,mem,st.st_size) != st.st_size)
				{
					fprintf(stderr,"cannot read %d '%s'\n",
							(int)st.st_size,file) ;
					fflush(stderr) ;
					exit(1) ;
				}
				obj	= XoLoadMem(mem,st.st_size) ;
				if	( !obj )
				{
					fprintf(stderr,"\tload obj err : %s\n",
						file) ;	
					fflush(stderr) ;
					exit(1) ;
				}
				aff	(obj) ;
				XoFree	(obj,1);
				free	(mem);
			break ;
		}
	}

	XoEnd();
	exit	(0) ;
}
Exemple #20
0
void R_LoadPCX ( const char *filename, byte **pic, int *width, int *height)
{
	byte	*end;
	pcx_t	*pcx;
	int		len;
	unsigned char	dataByte = 0, runLength = 0;
	byte	*out, *pix;
	unsigned short w, h;
	byte	*pic8;
	byte	*palette;
	int	i;
	unsigned size = 0;

	if (width)
		*width = 0;
	if (height)
		*height = 0;
	*pic = NULL;

	//
	// load the file
	//
	byte *buffer;
	len = og::FS->LoadFile( filename, &buffer );
	if (!buffer || len < 0) {
		return;
	}

	og::AutoFreeFile aff( buffer );

	if((unsigned)len < sizeof(pcx_t))
	{
		ri->Printf (PRINT_ALL, "PCX truncated: %s\n", filename);
		return;
	}

	//
	// parse the PCX file
	//
	pcx = (pcx_t *)buffer;
	end = buffer+len;

	w = LittleShort(pcx->xmax)+1;
	h = LittleShort(pcx->ymax)+1;
	size = w*h;

	if (pcx->manufacturer != 0x0a
		|| pcx->version != 5
		|| pcx->encoding != 1
		|| pcx->color_planes != 1
		|| pcx->bits_per_pixel != 8
		|| w >= 1024
		|| h >= 1024)
	{
		ri->Printf (PRINT_ALL, "Bad or unsupported pcx file %s (%dx%d@%d)\n", filename, w, h, pcx->bits_per_pixel);
		return;
	}

	pix = pic8 = (byte *)ri->Malloc ( size );

	buffer = pcx->data;
	// FIXME: should use bytes_per_line but original q3 didn't do that either
	while(pix < pic8+size)
	{
		if(runLength > 0) {
			*pix++ = dataByte;
			--runLength;
			continue;
		}

		if(buffer+1 > end)
			break;
		dataByte = *buffer++;

		if((dataByte & 0xC0) == 0xC0)
		{
			if(buffer+1 > end)
				break;
			runLength = dataByte & 0x3F;
			dataByte = *buffer++;
		}
		else
			runLength = 1;
	}

	if(pix < pic8+size)
	{
		ri->Printf (PRINT_ALL, "PCX file truncated: %s\n", filename);
		ri->Free (pic8);
	}

	if (buffer-(byte*)pcx >= end - (byte*)769 || end[-769] != 0x0c)
	{
		ri->Printf (PRINT_ALL, "PCX missing palette: %s\n", filename);
		ri->Free (pic8);
		return;
	}

	palette = end-768;

	pix = out = (byte *)ri->Malloc(4 * size );
	for (i = 0 ; i < size ; i++)
	{
		unsigned char p = pic8[i];
		pix[0] = palette[p*3];
		pix[1] = palette[p*3 + 1];
		pix[2] = palette[p*3 + 2];
		pix[3] = 255;
		pix += 4;
	}

	if (width)
		*width = w;
	if (height)
		*height = h;

	*pic = out;

	ri->Free (pic8);
}
Exemple #21
0
int main(int argc, char const *argv[]) {
  int A = 1;
  int B = 2;
  int C = 3;

  int *P1, *P2;

  P1 = &A;
  aff(A,B,C,P1,P2);
  P2 = &C;
aff(A,B,C,P1,P2);
  *P1 = (*P2)++;
aff(A,B,C,P1,P2);
  P1 = P2;
  aff(A,B,C,P1,P2);
  P2 = &B;
  aff(A,B,C,P1,P2);
  *P1 -= *P2;
  aff(A,B,C,P1,P2);
  ++*P2;
  aff(A,B,C,P1,P2);
  *P1*=*P2;
  aff(A,B,C,P1,P2);
  A=++*P2**P1;
  aff(A,B,C,P1,P2);
  P1 = &A;
  aff(A,B,C,P1,P2);
  *P2 =*P1/=*P2;
  aff(A,B,C,P1,P2);
  return 0;
}
Exemple #22
0
int main(int argc, char** argv) {

	if (argc < 8) {

		std::cout << "usage: watershed <aff_x_dir> <aff_y_dir> <aff_z_dir> <t_l> <t_h> <t_s> <ms>" << std::endl;
		return 1;
	}

	std::string aff_x_dir = argv[1];
	std::string aff_y_dir = argv[2];
	std::string aff_z_dir = argv[3];
	float t_l = boost::lexical_cast<float>(argv[4]);
	float t_h = boost::lexical_cast<float>(argv[5]);
	float t_s = boost::lexical_cast<float>(argv[6]);
	int   ms  = boost::lexical_cast<float>(argv[7]);

	std::cout
			<< "Performing affinity graph watershed on volumes "
			<< aff_x_dir << ", " << aff_y_dir << ", " << aff_z_dir
			<< std::endl;

	boost::filesystem::path aff_x_path(aff_x_dir);
	boost::filesystem::path aff_y_path(aff_y_dir);
	boost::filesystem::path aff_z_path(aff_z_dir);

	int size_z = num_files(aff_x_path);
	if (size_z != num_files(aff_y_dir) || size_z != num_files(aff_z_dir)) {

		std::cerr << "directories contain different number of files" << std::endl;
		return 1;
	}

	if (size_z == 0) {

		std::cerr << "directories contain no files" << std::endl;
		return 1;
	}

	std::vector<boost::filesystem::path> aff_x_files = files(aff_x_path);
	std::vector<boost::filesystem::path> aff_y_files = files(aff_y_path);
	std::vector<boost::filesystem::path> aff_z_files = files(aff_z_path);
	aff_x_files.resize(1); // one section only
	aff_y_files.resize(1); // one section only
	aff_z_files.resize(1); // one section only
	size_z = 1;

	std::sort(aff_x_files.begin(), aff_x_files.end());
	std::sort(aff_y_files.begin(), aff_y_files.end());
	std::sort(aff_z_files.begin(), aff_z_files.end());

	vigra::ImageImportInfo info(aff_x_files[0].native().c_str());
	int size_x = info.width();
	int size_y = info.height();

	std::cout << "reading affinity graph of size " << size_x << "x" << size_y << "x" << size_z << std::endl;

	affinity_graph_ptr<float> aff(
			new affinity_graph<float>(
					boost::extents[size_x][size_y][size_z][3],
					boost::fortran_storage_order()));

	for (int z = 0; z < size_z; z++) {

		auto slice = (*aff)[ boost::indices[range()][range()][z][range()] ];
		read_slice(slice, aff_x_files[z], aff_y_files[z], aff_z_files[z]);
	}

	std::cout << "performing simple_watershed" << std::endl;

	std::vector<std::size_t> counts;
	auto result = simple_watershed<uint32_t>(aff, t_l, t_h, counts);

	auto segmentation = result.first;
	int num_segments  = result.second;

	std::cout << "found " << num_segments << " segments" << std::endl;

	auto rg = get_region_graph<uint32_t,float>(aff, segmentation, num_segments);

	std::cout << "performing region merging" << std::endl;

	// I guess the last parameter is to discard regions smaller than that
	//merge_segments_with_function(result.first, rg, counts, 
	//dynamic_size_threshold(t_s, ms), 0);

	for (int z = 0; z < size_z; z++) {

		auto slice = (*segmentation)[ boost::indices[range()][range()][z] ];
		std::stringstream filename;
		filename << "watershed_" << std::setw(5) << std::setfill('0') << z << "_" << t_l << "_" << t_h << "_" << t_s << "_" << ms << ".tif";
		write_slice(slice, filename.str());
	}
}
Exemple #23
0
void R_LoadBMP( const char *name, byte **pic, int *width, int *height )
{
	int		columns, rows;
	unsigned	numPixels;
	byte	*pixbuf;
	int		row, column;
	byte	*buf_p;
	byte	*end;
	int		length;
	BMPHeader_t bmpHeader;
	byte		*bmpRGBA;

	*pic = NULL;

	if(width)
		*width = 0;

	if(height)
		*height = 0;

	//
	// load the file
	//
	byte *buffer;
	length = og::FS->LoadFile( name, &buffer );
	if (!buffer || length < 0) {
		return;
	}

	og::AutoFreeFile aff( buffer );

	if (length < 54)
	{
		ri->Error( ERR_DROP, "LoadBMP: header too short (%s)", name );
	}

	buf_p = buffer;
	end = buffer + length;

	bmpHeader.id[0] = *buf_p++;
	bmpHeader.id[1] = *buf_p++;
	bmpHeader.fileSize = LittleLong( * ( int * ) buf_p );
	buf_p += 4;
	bmpHeader.reserved0 = LittleLong( * ( int * ) buf_p );
	buf_p += 4;
	bmpHeader.bitmapDataOffset = LittleLong( * ( int * ) buf_p );
	buf_p += 4;
	bmpHeader.bitmapHeaderSize = LittleLong( * ( int * ) buf_p );
	buf_p += 4;
	bmpHeader.width = LittleLong( * ( int * ) buf_p );
	buf_p += 4;
	bmpHeader.height = LittleLong( * ( int * ) buf_p );
	buf_p += 4;
	bmpHeader.planes = LittleShort( * ( short * ) buf_p );
	buf_p += 2;
	bmpHeader.bitsPerPixel = LittleShort( * ( short * ) buf_p );
	buf_p += 2;
	bmpHeader.compression = LittleLong( * ( int * ) buf_p );
	buf_p += 4;
	bmpHeader.bitmapDataSize = LittleLong( * ( int * ) buf_p );
	buf_p += 4;
	bmpHeader.hRes = LittleLong( * ( int * ) buf_p );
	buf_p += 4;
	bmpHeader.vRes = LittleLong( * ( int * ) buf_p );
	buf_p += 4;
	bmpHeader.colors = LittleLong( * ( int * ) buf_p );
	buf_p += 4;
	bmpHeader.importantColors = LittleLong( * ( int * ) buf_p );
	buf_p += 4;

	if ( bmpHeader.bitsPerPixel == 8 )
	{
		if (buf_p + sizeof(bmpHeader.palette) > end)
			ri->Error( ERR_DROP, "LoadBMP: header too short (%s)", name );

		Com_Memcpy( bmpHeader.palette, buf_p, sizeof( bmpHeader.palette ) );
	}

	if (buffer + bmpHeader.bitmapDataOffset > end)
	{
		ri->Error( ERR_DROP, "LoadBMP: invalid offset value in header (%s)", name );
	}

	buf_p = buffer + bmpHeader.bitmapDataOffset;

	if ( bmpHeader.id[0] != 'B' && bmpHeader.id[1] != 'M' ) 
	{
		ri->Error( ERR_DROP, "LoadBMP: only Windows-style BMP files supported (%s)", name );
	}
	if ( bmpHeader.fileSize != length )
	{
		ri->Error( ERR_DROP, "LoadBMP: header size does not match file size (%u vs. %u) (%s)", bmpHeader.fileSize, length, name );
	}
	if ( bmpHeader.compression != 0 )
	{
		ri->Error( ERR_DROP, "LoadBMP: only uncompressed BMP files supported (%s)", name );
	}
	if ( bmpHeader.bitsPerPixel < 8 )
	{
		ri->Error( ERR_DROP, "LoadBMP: monochrome and 4-bit BMP files not supported (%s)", name );
	}

	switch ( bmpHeader.bitsPerPixel )
	{
		case 8:
		case 16:
		case 24:
		case 32:
			break;
		default:
			ri->Error( ERR_DROP, "LoadBMP: illegal pixel_size '%hu' in file '%s'", bmpHeader.bitsPerPixel, name );
			break;
	}

	columns = bmpHeader.width;
	rows = bmpHeader.height;
	if ( rows < 0 )
		rows = -rows;
	numPixels = columns * rows;

	if(columns <= 0 || !rows || numPixels > 0x1FFFFFFF // 4*1FFFFFFF == 0x7FFFFFFC < 0x7FFFFFFF
	    || ((numPixels * 4) / columns) / 4 != rows)
	{
	  ri->Error (ERR_DROP, "LoadBMP: %s has an invalid image size", name);
	}
	if(buf_p + numPixels*bmpHeader.bitsPerPixel/8 > end)
	{
	  ri->Error (ERR_DROP, "LoadBMP: file truncated (%s)", name);
	}

	if ( width ) 
		*width = columns;
	if ( height )
		*height = rows;

	bmpRGBA = (byte *)ri->Malloc( numPixels * 4 );
	*pic = bmpRGBA;


	for ( row = rows-1; row >= 0; row-- )
	{
		pixbuf = bmpRGBA + row*columns*4;

		for ( column = 0; column < columns; column++ )
		{
			unsigned char red, green, blue, alpha;
			int palIndex;
			unsigned short shortPixel;

			switch ( bmpHeader.bitsPerPixel )
			{
			case 8:
				palIndex = *buf_p++;
				*pixbuf++ = bmpHeader.palette[palIndex][2];
				*pixbuf++ = bmpHeader.palette[palIndex][1];
				*pixbuf++ = bmpHeader.palette[palIndex][0];
				*pixbuf++ = 0xff;
				break;
			case 16:
				shortPixel = * ( unsigned short * ) pixbuf;
				pixbuf += 2;
				*pixbuf++ = ( shortPixel & ( 31 << 10 ) ) >> 7;
				*pixbuf++ = ( shortPixel & ( 31 << 5 ) ) >> 2;
				*pixbuf++ = ( shortPixel & ( 31 ) ) << 3;
				*pixbuf++ = 0xff;
				break;

			case 24:
				blue = *buf_p++;
				green = *buf_p++;
				red = *buf_p++;
				*pixbuf++ = red;
				*pixbuf++ = green;
				*pixbuf++ = blue;
				*pixbuf++ = 255;
				break;
			case 32:
				blue = *buf_p++;
				green = *buf_p++;
				red = *buf_p++;
				alpha = *buf_p++;
				*pixbuf++ = red;
				*pixbuf++ = green;
				*pixbuf++ = blue;
				*pixbuf++ = alpha;
				break;
			}
		}
	}
}
Exemple #24
0
 /** Get an element of the N x (N + 1) matrix representing this transform. */
 Real operator()(int i, int j) const { return aff(i, j); }
Image Objet::affiche()
{
    Image aff(this->m_image);
    return aff;
}
Image point::affiche()
{
    Image aff(this->m_image);
    return aff;
}