示例#1
0
void checkImageN(int n)
{
  int minx, maxx, miny, maxy;
  int i,j;
  if (show != n+1) return;
      /* Get the Bounding Box for this Cropping */

      minx = *(gXStart+n);
      maxx = minx + *(gWidth+n);
      miny = *(gYStart+n);
      maxy = miny + *(gHeight+n);

      printf("\n  [%3d ]|",n+1);
      for (i=minx;i<maxx;i+=2) { printf("_"); }
      printf("\n        |");

      for (j=maxy-1;j>=miny;j--)
	{
	  if (j%2) continue;
	  unsigned char *line = newgetaline(j,0);
	  for (i=minx;i<maxx;i++)
	    {
	      int d = line[i];
	      if (i%2) {
		if ( BLACK(d) ) printf("@"); else printf(" ");
	      }
	    }
	  printf("|\n%3d %3d |",j-miny, (maxy-j));
	}
      for (i=minx;i<maxx;i+=2) { printf("_"); } printf("\n");
}
示例#2
0
void CFade::Initialize(void)
{
	Self = new CFade;
	Self->Vtx[0] = VECTOR3(SCREEN_WIDTH,0,0);
	Self->Vtx[1] = VECTOR3(0,0,0);
	Self->Vtx[2] = VECTOR3(SCREEN_WIDTH,SCREEN_HEIGHT,0);
	Self->Vtx[3] = VECTOR3(0,SCREEN_HEIGHT,0);
	Self->_Color = BLACK(1.0f);
	Self->_State = FADE_NONE;
}
示例#3
0
void FlcDoOneFrame()
{ int ChunkCount; 
  ChunkCount=flc.FrameChunks;
  flc.pChunk=flc.pMembuf;
  if ( SDL_LockSurface(flc.mainscreen) < 0 )
    return;
  // if (!ChunkCount) printf("Empty frame! %d\n", flc.FrameCount); // this is normal and used for delays
  while(ChunkCount--) {
    ReadU32(&flc.ChunkSize, flc.pChunk+0);
    ReadU16(&flc.ChunkType, flc.pChunk+4);

#ifdef DEBUG
    printf("flc.ChunkSize: %d\n", flc.ChunkSize);
    printf("flc.ChunkType: %d aka %x\n", flc.ChunkType, flc.ChunkType);
	if (flc.DelayOverride) printf("DelayOverride: %d\n", flc.DelayOverride);
#endif

    switch(flc.ChunkType) {
      case 4:
        COLORS256();
      break;
      case 7:
        SS2();
      break;
      case 11:
        DECODE_COLOR();
      break;
      case 12:
        DECODE_LC();
      break;
      case 13:
        BLACK();
      break;
      case 15:
        DECODE_BRUN();
      break;
      case 16:
        DECODE_COPY();
      break;
      case 18:
#ifdef DEBUG
        printf("Chunk 18 not yet done.\n");
#endif
      break;
      default:
        Log(LOG_WARNING) << "Ieek an non implemented chunk type:" << flc.ChunkType;
    }
    flc.pChunk+=flc.ChunkSize;
  }
  SDL_UnlockSurface(flc.mainscreen);
} /* FlcDoOneFrame */
示例#4
0
void checkImage(void)
{
   printf("  |");
   int i,j;
   for (j=0;j<h;j++) {
     unsigned char *line = newgetaline(j,0);
      for (i=0;i<w;i++) {

	int d = line[i];
	if (i%2) { if ( BLACK(d) ) printf("@"); else printf(" "); }
      }
      printf("|\n  |");
   }
}
示例#5
0
static void
hello_world			(void)
{
	int ch = 0;
	int i;

	pgno = -1;

	prints (" HELLO WORLD! ");
	PAUSE (30);

	ch = 4;
	TEXT_RESTART;
	prints ("Character set - Text 1");
	CR; CR;
	for (i = 32; i <= 127; i++) {
		printc (i);
		if ((i & 15) == 15)
			CR;
	}
	MIDROW (italic, 0);
	for (i = 32; i <= 127; i++) {
		printc (i);
		if ((i & 15) == 15)
			CR;
	}
	MIDROW (white, underline);
	for (i = 32; i <= 127; i++) {
		printc (i);
		if ((i & 15) == 15)
			CR;
	}
	MIDROW (white, 0);
	prints ("Special: ");
	for (i = 0; i <= 15; i++) {
		SPECIAL_CHAR (i);
	}
	CR;
	prints ("DONE - Text 1 ");
	PAUSE (50);

	ch = 5;
	TEXT_RESTART;
	prints ("Styles - Text 2");
	CR; CR;
	MIDROW (white, 0); prints ("WHITE"); CR;
	MIDROW (red, 0); prints ("RED"); CR;
	MIDROW (green, 0); prints ("GREEN"); CR;
	MIDROW (blue, 0); prints ("BLUE"); CR;
	MIDROW (yellow, 0); prints ("YELLOW"); CR;
	MIDROW (cyan, 0); prints ("CYAN"); CR;
	MIDROW (magenta, 0); prints ("MAGENTA"); BLACK (0); CR;
	BACKG (white, opaque); prints ("WHITE"); BACKG (black, opaque); CR;
	BACKG (red, opaque); prints ("RED"); BACKG (black, opaque); CR;
	BACKG (green, opaque); prints ("GREEN"); BACKG (black, opaque); CR;
	BACKG (blue, opaque); prints ("BLUE"); BACKG (black, opaque); CR;
	BACKG (yellow, opaque); prints ("YELLOW"); BACKG (black, opaque); CR;
	BACKG (cyan, opaque); prints ("CYAN"); BACKG (black, opaque); CR;
	BACKG (magenta, opaque); prints ("MAGENTA"); BACKG (black, opaque); CR;
	TRANSP;
	prints (" TRANSPARENT BACKGROUND ");
	BACKG (black, opaque); CR;
	MIDROW (white, 0); FLASH_ON;
	prints (" Flashing Text  (if implemented) "); CR;
	MIDROW (white, 0); prints ("DONE - Text 2 ");
	PAUSE (50);

	ch = 0;
	ROLL_UP (2);
	ERASE_DISPLAY;
	prints (" ROLL-UP TEST "); CR; PAUSE (20);
	prints (">> A young Jedi named Darth"); CR; PAUSE (20);
	prints ("Vader, who was a pupil of"); CR; PAUSE (20);
	prints ("mine until he turned to evil,"); CR; PAUSE (20);
	prints ("helped the Empire hunt down"); CR; PAUSE (20);
	prints ("and destroy the Jedi Knights."); CR; PAUSE (20);
	prints ("He betrayed and murdered your"); CR; PAUSE (20);
	prints ("father. Now the Jedi are all"); CR; PAUSE (20);
	prints ("but extinct. Vader was seduced"); CR; PAUSE (20);
	prints ("by the dark side of the Force."); CR; PAUSE (20);                        
	prints (">> The Force?"); CR; PAUSE (20);
	prints (">> Well, the Force is what gives"); CR; PAUSE (20);
	prints ("a Jedi his power. It's an energy"); CR; PAUSE (20);
	prints ("field created by all living"); CR; PAUSE (20);
	prints ("things."); CR; PAUSE (20);
	prints ("It surrounds us and penetrates"); CR; PAUSE (20);
	prints ("us."); CR; PAUSE (20);
	prints ("It binds the galaxy together."); CR; PAUSE (20);
	CR; PAUSE (30);
	prints (" DONE - Caption 1 ");
	PAUSE (30);

	ch = 1;
	RESUME_DIRECT;
	ERASE_DISPLAY;
	MIDROW (yellow, 0);
	INDENT (2, 10, 0); prints (" FOO "); CR;
	INDENT (3, 10, 0); prints (" MIKE WAS HERE "); CR; PAUSE (20);
	MIDROW (red, 0);
	INDENT (6, 13, 0); prints (" AND NOW... "); CR;
	INDENT (8, 13, 0); prints (" HE'S HERE "); CR; PAUSE (20);
	PREAMBLE (12, cyan, 0);
	prints ("01234567890123456789012345678901234567890123456789"); CR;
	MIDROW (white, 0);
	prints (" DONE - Caption 2 "); CR;
	PAUSE (30);
}
示例#6
0
extern "C" DLLEXPORT miBoolean physical_light(
	miColor			*result,
	miState			*state,
	struct physical_light	*parms)
{
	struct physical_light	p, *paras = &p;	/* mi_eval'ed parameters */
	miTag			light = 0;
	miColor			visibility = {1.0, 1.0, 1.0};
	miVector		normal, u, v, axis, spotdir, dir;
	miScalar		cosine, r=state->dist, r2, f, d, area, radius;
	miScalar		exponent, spread;
	miScalar		maxcolor;
	int			type, areatype;

	p.color     = *mi_eval_color (&parms->color);
	p.cone      = *mi_eval_scalar(&parms->cone);
	p.threshold = *mi_eval_scalar(&parms->threshold);
	p.cos_exp   = *mi_eval_scalar(&parms->cos_exp);

	miASSERT(paras->color.r >= 0.0 && paras->color.g >= 0.0 &&
		 paras->color.b >= 0.0);   /* no 'light suckers', please */

	mi_query(miQ_INST_ITEM,  state, state->light_instance,	&light);
	mi_query(miQ_LIGHT_TYPE, state, light,			&type);
	mi_query(miQ_LIGHT_AREA, state, light,			&areatype);

	if (state->type == miRAY_LIGHT) {
		/*
		 * compute irradiance from this light source at the surface of
		 * object
		 */
		mi_query(miQ_LIGHT_EXPONENT, state, light, &exponent);
		r2 = exponent == 0 || exponent == 2 ? r*r : pow(r, exponent);

		switch(areatype) {
		  case miLIGHT_NONE:		/* point, spot or directional*/
			/*
			 * distance attenuation: 4 Pi r^2 is the area of a
			 * sphere around the point. Same normalization as for
			 * spherical light
			 */
			f = type==miLIGHT_DIRECTION ? 1 : 1 / (4 * M_PI * r2);
			break;

		  case miLIGHT_RECTANGLE:	/* rectangular area light */
			mi_query(miQ_LIGHT_AREA_R_EDGE_U, state, light, &u);
			mi_query(miQ_LIGHT_AREA_R_EDGE_V, state, light, &v);
			mi_vector_prod(&normal, &u, &v);
			mi_vector_normalize(&normal);
			mi_vector_to_light(state, &dir, &state->dir);
			mi_vector_normalize(&dir);
			/*
			 * Compute area-to-point form factor (except cos at
			 * the receiver). <cosine> is cos at sender. Returning
			 * 2 means "no color and stop sampling".
			 */
			cosine = mi_vector_dot(&normal, &dir);
			if (cosine <= 0)
				return((miBoolean)2);
			if (paras->cos_exp != 0 && paras->cos_exp != 1)
				cosine = pow(cosine, paras->cos_exp);
			/*
			 * cos term and distance attenuation. No area term
			 * since "color" of the light is energy, not radiance.
			 */
			f = cosine / (M_PI * r2);
			break;

		  case miLIGHT_DISC:		/* disc area light */
			mi_query(miQ_LIGHT_AREA_D_NORMAL, state,light,&normal);
			mi_vector_to_light(state, &dir, &state->dir);
			mi_vector_normalize(&dir);

			cosine = mi_vector_dot(&normal, &dir);
			if (cosine <= 0)
				return((miBoolean)2);
			if (paras->cos_exp != 0 && paras->cos_exp != 1)
				cosine = pow(cosine, paras->cos_exp);
			f = cosine / (M_PI * r2);
			break;

		  case miLIGHT_SPHERE:		/* spherical area light */
		  case miLIGHT_CYLINDER:	/* cylindrical area light */
			f = 1 / (4 * M_PI * r2);
			break;

		  case miLIGHT_OBJECT:
		        /* two sided */
			/*
			 * this is legal for object lights only: state->child
			 * is set according to the intersection with the light
			 * geometry itself
			 */
		        cosine = -state->child->dot_nd;
			if (cosine <= 0)
				return(miFALSE);
			if (paras->cos_exp != 0 && paras->cos_exp != 1)
				cosine = pow(cosine, paras->cos_exp);
		        f = cosine / (4 * M_PI * r2);
			break;

		  default:
			mi_error("physical_light: unknown light source type");
		}
		if (type == miLIGHT_SPOT) {	/* spot light source */
			mi_query(miQ_LIGHT_DIRECTION, state, light, &spotdir);
			miASSERT(fabs(mi_vector_norm(&spotdir) - 1.) < miEPS);
			mi_vector_to_light(state, &dir, &state->dir);
			mi_vector_normalize(&dir);
			d = mi_vector_dot(&dir, &spotdir);
			if (d <= 0)
				return(miFALSE);
			mi_query(miQ_LIGHT_SPREAD, state, light, &spread);
			if (d < spread)
				return(miFALSE);
			if (d < paras->cone)
				f *= 1 - (d - paras->cone) /
					 (spread - paras->cone);
		}

		/*
		 * Return false without checking occlusion (shadow ray) if
		 * color is very dark. (This introduces bias which could be
		 * avoided if probabilities were used to decide whether to
		 * carry on or return here.)
		 */
		maxcolor = mi_MAX3(paras->color.r, paras->color.g,
							paras->color.b);
		if (f * maxcolor < paras->threshold)
			return(miFALSE);

		/*
		 * Check for occlusion by an opaque object and compute
		 * visibility
		 */
		if (!mi_trace_shadow(&visibility, state) || BLACK(visibility))
			return(miFALSE);

		/*
		 * Compute result. Visibility is always (1 1 1) here for
		 * dgs_material() so the multiplication by visibility could be
		 * avoided. But for base light shaders visibility can be less.
		 */
		result->r = f * paras->color.r * visibility.r;
		result->g = f * paras->color.g * visibility.g;
		result->b = f * paras->color.b * visibility.b;
	} else {		/* Visible area light source: return radiance*/
		switch (areatype) {
		  case miLIGHT_RECTANGLE:	/* rectangular area light */
			mi_query(miQ_LIGHT_AREA_R_EDGE_U, state, light, &u);
			mi_query(miQ_LIGHT_AREA_R_EDGE_V, state, light, &v);
			mi_vector_prod(&normal, &u, &v);
			/* Compute radiance: result = paras->color / area */
			mi_normal_to_light(state, &dir, &state->normal);
			if (mi_vector_dot(&normal, &dir) > 0) {
				area = 4.0 * mi_vector_norm(&normal);
				miASSERT(area > 0.0);
				result->r = paras->color.r / area;
				result->g = paras->color.g / area;
				result->b = paras->color.b / area;
			} else
				*result = black;   /* back side is black */
			break;

		  case miLIGHT_DISC:		/* disc area light source */
			mi_query(miQ_LIGHT_AREA_D_NORMAL, state,light,&normal);
			mi_normal_to_light(state, &dir, &state->normal);
			if (mi_vector_dot(&normal, &dir) > 0) {
				mi_query(miQ_LIGHT_AREA_D_RADIUS, state,
							light, &radius);
				area = M_PI * radius * radius;
				miASSERT(area > 0.0);
				result->r = paras->color.r / area;
				result->g = paras->color.g / area;
				result->b = paras->color.b / area;
			} else
				*result = black;
			break;

		  case miLIGHT_SPHERE:		/* spherical area light */
			mi_query(miQ_LIGHT_AREA_S_RADIUS, state,light,&radius);
			area = 4.0 * M_PI * radius * radius;
			miASSERT(area > 0.0);
			result->r = paras->color.r / area;
			result->g = paras->color.g / area;
			result->b = paras->color.b / area;
			break;

		  case miLIGHT_CYLINDER:	/* cylindrical area light */
			mi_query(miQ_LIGHT_AREA_C_RADIUS, state,light,&radius);
			mi_query(miQ_LIGHT_AREA_C_AXIS, state, light, &axis);
			/* area = pi*radius^2 * h = pi*radius^2 * 2 * |axis| */
			area = 2 * M_PI * radius * radius *
						mi_vector_norm(&axis);
			miASSERT(area > 0.0);
			result->r = paras->color.r / area;
			result->g = paras->color.g / area;
			result->b = paras->color.b / area;
			break;

		  case miLIGHT_OBJECT:
		        mi_query(miQ_INST_AREA, state,
				 state->light_instance, &area);
			result->r = paras->color.r / area;
			result->g = paras->color.g / area;
			result->b = paras->color.b / area;
			break;

		  case miLIGHT_NONE:		/* point, spot or directional*/
			miASSERT(0);
			break;

		  default:
			mi_error("physical_light: unknown light source type");
		}
	}
	miASSERT(result->r >= 0 && result->g >= 0 && result->b >= 0);
	return(miTRUE);
}
示例#7
0
/*! Method for restoring red-black properties after deletion. */
void GsTreeBase::_fix_remove ( GsTreeNode *x )
 {
   GS_TRACE1("Fix Remove");

   while ( x!=_root && BLACK(x) )
    {
      if ( x==x->parent->left )
       { GsTreeNode *w = x->parent->right;
         if ( RED(w) )
          { w->color = GsTreeNode::Black;
            x->parent->color = GsTreeNode::Red;
            _rotate_left ( x->parent );
            w = x->parent->right;
          }
         if ( BLACK(w->left) && BLACK(w->right) )
          { w->color = GsTreeNode::Red;
            x = x->parent;
          } 
         else
          { if ( BLACK(w->right) )
             { w->left->color = GsTreeNode::Black;
               w->color = GsTreeNode::Red;
               _rotate_right ( w );
               w = x->parent->right;
             }
            w->color = x->parent->color;
            x->parent->color = GsTreeNode::Black;
            w->right->color = GsTreeNode::Black;
            _rotate_left ( x->parent );
            x = _root;
          }
       }
      else
       { GsTreeNode *w = x->parent->left;
         if ( RED(w) )
          { w->color = GsTreeNode::Black;
            x->parent->color = GsTreeNode::Red;
            _rotate_right ( x->parent );
            w = x->parent->left;
          }
         if ( BLACK(w->left) && BLACK(w->right) )
          { w->color = GsTreeNode::Red;
            x = x->parent;
          }
         else
          { if ( BLACK(w->left) )
             { w->right->color = GsTreeNode::Black;
               w->color = GsTreeNode::Red;
               _rotate_left ( w );
               w = x->parent->left;
             }
            w->color = x->parent->color;
            x->parent->color = GsTreeNode::Black;
            w->left->color = GsTreeNode::Black;
            _rotate_right ( x->parent );
            x = _root;
          }
       }
    }

   x->color = GsTreeNode::Black;
 }
示例#8
0
extern "C" DLLEXPORT miBoolean maya_light_point(
	miColor		*result,
	miState		*state,
	struct maya_light_point *paras)
{
	miScalar	d, t, start, stop;

	/***********************************************************
	 * MAYA
	 *
	 * Pointers to access the shader state
	 ***********************************************************/
	miBoolean *diffuse = NULL, *specular = NULL;

	*result = *mi_eval_color(&paras->color);
	if (state->type != miRAY_LIGHT)			/* visible area light*/
		return(miTRUE);
	if (*mi_eval_boolean(&paras->atten)) {			/* dist atten*/
		stop = *mi_eval_scalar(&paras->stop);
		if (state->dist >= stop)
			return(miFALSE);

		start = *mi_eval_scalar(&paras->start);
		if (state->dist > start && fabs(stop - start) > EPS) {
			t = 1.0F - (
			((float)(state->dist) - start) / (stop - start));
			result->r *= t;
			result->g *= t;
			result->b *= t;
		}
	}
	if (*mi_eval_boolean(&paras->shadow)) {			/* shadows: */
		d = *mi_eval_scalar(&paras->factor);
		if (d < 1) {
			miColor filter;
			filter.r = filter.g = filter.b = filter.a = 1;
								/* opaque */
			if (!mi_trace_shadow(&filter,state) || BLACK(filter)) {
				result->r *= d;
				result->g *= d;
				result->b *= d;
				if (d == 0)
					return(miFALSE);
			} else {				/* transparnt*/
				float omf = 1 - d;
				result->r *= d + omf * filter.r;
				result->g *= d + omf * filter.g;
				result->b *= d + omf * filter.b;
			}
		}
	}

	/***********************************************************
	 * MAYA
	 *
	 * Set custom Maya light properties.
	 *
	 * mayabase_stateitem_get returns pointer to
	 * specified MbStateItem in the shader state.
	 * MBSI_LIGHTDIFFUSE and MBSI_LIGHTSPECULAR
	 * contains information whether the light
	 * emits diffuse and/or specular.
	 * These values are used by material shaders.
	 * The variable-length parameter should terminated
	 * with MBSI_NULL.
	 ***********************************************************/
	if (mayabase_stateitem_get(state,
		MBSI_LIGHTDIFFUSE, &diffuse,
		MBSI_LIGHTSPECULAR, &specular,
		MBSI_NULL)) {

		/***********************************************************
		 * MAYA
		 *
		 * Sets
		 * MBSI_LIGHTDIFFUSE and MBSI_LIGHTSPECULAR
		 * 
		 ***********************************************************/
		*diffuse  = *mi_eval_boolean(&paras->emitDiffuse);
		*specular = *mi_eval_boolean(&paras->emitSpecular);
	}

	return(miTRUE);
}