示例#1
0
static typename std::enable_if<std::is_integral<Src>::value, void>::type
run_constexpr_clamp_cast_test(Src, Dst) {
  constexpr auto kSrcMax = std::numeric_limits<Src>::max();
  constexpr auto kSrcMin = std::numeric_limits<Src>::min();

  constexpr auto kDstMax = std::numeric_limits<Dst>::max();
  constexpr auto kDstMin = std::numeric_limits<Dst>::min();

  // value in range -> same value
  EXPECT_EQ(Dst(0), folly::constexpr_clamp_cast<Dst>(Src(0)));
  EXPECT_EQ(Dst(123), folly::constexpr_clamp_cast<Dst>(Src(123)));

  // int -> uint
  if (std::is_signed<Src>::value && std::is_unsigned<Dst>::value) {
    EXPECT_EQ(Dst(0), folly::constexpr_clamp_cast<Dst>(Src(-123)));
  }

  if (sizeof(Src) > sizeof(Dst)) {
    // range clamping
    EXPECT_EQ(kDstMax, folly::constexpr_clamp_cast<Dst>(kSrcMax));

    // int -> int
    if (std::is_signed<Src>::value && std::is_signed<Dst>::value) {
      EXPECT_EQ(kDstMin, folly::constexpr_clamp_cast<Dst>(kSrcMin));
    }

  } else if (
      std::is_unsigned<Src>::value && std::is_signed<Dst>::value &&
      sizeof(Src) == sizeof(Dst)) {
    // uint -> int, same size
    EXPECT_EQ(kDstMax, folly::constexpr_clamp_cast<Dst>(kSrcMax));
  }
}
示例#2
0
static typename std::enable_if<std::is_floating_point<Src>::value, void>::type
run_constexpr_clamp_cast_test(Src, Dst) {
  constexpr auto kQuietNaN = std::numeric_limits<Src>::quiet_NaN();
  constexpr auto kSignalingNaN = std::numeric_limits<Src>::signaling_NaN();
  constexpr auto kPositiveInf = std::numeric_limits<Src>::infinity();
  constexpr auto kNegativeInf = -kPositiveInf;

  constexpr auto kDstMax = std::numeric_limits<Dst>::max();
  constexpr auto kDstMin = std::numeric_limits<Dst>::min();

  // Check f != f trick for identifying NaN.
  EXPECT_TRUE(kQuietNaN != kQuietNaN);
  EXPECT_TRUE(kSignalingNaN != kSignalingNaN);
  EXPECT_FALSE(kPositiveInf != kPositiveInf);
  EXPECT_FALSE(kNegativeInf != kNegativeInf);

  // NaN -> 0
  EXPECT_EQ(0, folly::constexpr_clamp_cast<Dst>(kQuietNaN));
  EXPECT_EQ(0, folly::constexpr_clamp_cast<Dst>(kSignalingNaN));

  // Inf -> Max/Min
  EXPECT_EQ(kDstMax, folly::constexpr_clamp_cast<Dst>(kPositiveInf));
  EXPECT_EQ(kDstMin, folly::constexpr_clamp_cast<Dst>(kNegativeInf));

  // barely out of range -> Max/Min
  EXPECT_EQ(kDstMax, folly::constexpr_clamp_cast<Dst>(Src(kDstMax) * 1.001));
  EXPECT_EQ(kDstMin, folly::constexpr_clamp_cast<Dst>(Src(kDstMin) * 1.001));

  // value in range -> same value
  EXPECT_EQ(Dst(0), folly::constexpr_clamp_cast<Dst>(Src(0)));
  EXPECT_EQ(Dst(123), folly::constexpr_clamp_cast<Dst>(Src(123)));
}
示例#3
0
void RendererGL::draw( float x, float y, string Name ) {

	Sprite sprite = SpriteManager::getInstance()->getSprite( Name );
	Rect Src( sprite.getAtlasX(), sprite.getAtlasY(), sprite.getWidth(), sprite.getHeight() );

	 glBindTexture(GL_TEXTURE_2D, pAtlas_GL);

		   const double texture_w = pAtlas->w;    // szerokość atlasu
		   const double texture_h = pAtlas->h;    // wysokość atlasu

		   const double left = Src.x / texture_w;
		   const double right =  left + (Src.w / texture_w );
		   const double bottom =  Src.y / texture_h;
		   const double top =  bottom + (Src.h  / texture_h);

		   glPushMatrix();  {
		     glTranslatef(0, 0, 0);
		     glBegin(GL_QUADS);
		     {
		         glTexCoord2f(right, top);//1
		         glVertex2f( x+Src.w, y+Src.h );

		         glTexCoord2f(left, top);//2
		         glVertex2f( x, y+Src.h );

	             glTexCoord2f(left, bottom);//3
		         glVertex2f( x, y );

		         glTexCoord2f(right, bottom);//4
		         glVertex2f( x+Src.w, y );
		     }
		     glEnd();
		   }
		   glPopMatrix();
}
示例#4
0
/**
 * Saves a 24Bit BMP file to disk
 * 
 * @param Pattern filename with path, must not be 0, if with "bmp" extension (e.g. "out.bmp") the filename stays like this, if without (e.g. "out") automatic index numbers are addended (e.g. "out00002.bmp")
 * @param DataWidth - Width of the bitmap supplied in Data >0
 * @param DataHeight - Height of the bitmap supplied in Data >0
 * @param Data must not be 0
 * @param SubRectangle optional, specifies a sub-rectangle of the source image to save out. If NULL, the whole bitmap is saved
 * @param FileManager must not be 0
 * @param OutFilename optional, if specified filename will be output
 *
 * @return true if success
 */
bool FFileHelper::CreateBitmap( const TCHAR* Pattern, int32 SourceWidth, int32 SourceHeight, const FColor* Data, struct FIntRect* SubRectangle, IFileManager* FileManager /*= &IFileManager::Get()*/, FString* OutFilename /*= NULL*/, bool bInWriteAlpha /*= false*/ )
{
#if ALLOW_DEBUG_FILES
	FIntRect Src(0, 0, SourceWidth, SourceHeight);
	if (SubRectangle == NULL || SubRectangle->Area() == 0)
	{
		SubRectangle = &Src;
	}

	FString File;
	// if the Pattern already has a .bmp extension, then use that the file to write to
	if (FPaths::GetExtension(Pattern) == TEXT("bmp"))
	{
		File = Pattern;
	}
	else
	{
		if (GenerateNextBitmapFilename(Pattern, TEXT("bmp"), File, FileManager))
		{
			if ( OutFilename )
			{
				*OutFilename = File;
			}
		}
		else
		{
			return false;
		}
	}

	FArchive* Ar = FileManager->CreateDebugFileWriter( *File );
	if( Ar )
	{
		// Types.
		#if PLATFORM_SUPPORTS_PRAGMA_PACK
			#pragma pack (push,1)
		#endif
		struct BITMAPFILEHEADER
		{
			uint16 bfType GCC_PACK(1);
			uint32 bfSize GCC_PACK(1);
			uint16 bfReserved1 GCC_PACK(1); 
			uint16 bfReserved2 GCC_PACK(1);
			uint32 bfOffBits GCC_PACK(1);
		} FH; 
		struct BITMAPINFOHEADER
		{
			uint32 biSize GCC_PACK(1); 
			int32  biWidth GCC_PACK(1);
			int32  biHeight GCC_PACK(1);
			uint16 biPlanes GCC_PACK(1);
			uint16 biBitCount GCC_PACK(1);
			uint32 biCompression GCC_PACK(1);
			uint32 biSizeImage GCC_PACK(1);
			int32  biXPelsPerMeter GCC_PACK(1); 
			int32  biYPelsPerMeter GCC_PACK(1);
			uint32 biClrUsed GCC_PACK(1);
			uint32 biClrImportant GCC_PACK(1); 
		} IH;
void cToolboxSprites::paintEvent(QPaintEvent*) {

    mScaleWidth = (static_cast<double>(size().width()) / static_cast<double>(mImage.width()));
    mScaleHeight = (static_cast<double>(size().height() - 20) / static_cast<double>(mImage.height()));

	QPainter painter(this);
	QRectF Dest(0, 0, size().width(), size().height() - 20);
	QRectF Src(0, 0, mImage.width(), mImage.height());

	painter.drawImage(Dest, mImage, Src);
}
示例#6
0
//============================================================================
//グレースケール描画
//============================================================================
//[input]
//	pRender:レンダラー用デバイス
//===========================================================================
void CSprite::DrawGrayScale( Renderer::IRender *pRender )
{
	if( m_pTex != NULL )
	{
		Math::Rect2DF Dst( m_vPos.x, m_vPos.y, m_fSize.x, m_fSize.y );
		
		Math::Rect2DF Src( 0, 0, m_fSize.x, m_fSize.y );
		
		pRender->DrawGrayscale( Dst, CColor( 255, 254, 255 ), Src, m_pTex );
		
		
	}
}
示例#7
0
bool FileUtil::CopyFile(const char* sSrc, const char* sDest)
{
	File Src(sSrc);
	File Dest(sDest);
	const unsigned int uBufSize = 4096;
	char sBuf[uBufSize] = {0};
	unsigned int uReadSize = 0;
	do {
		if (Src.Read(sBuf, 1, uBufSize, &uReadSize) == false) {
			return false;
		}
		if (uReadSize) {
			if (Dest.Write(&sBuf, 1, uReadSize) == false) {
				return false;
			}
		}
	} while(uReadSize);
	return true;
}
示例#8
0
int main( int argc, char* argv[] ) {
	printf("Test quaternions.\n");

	{
		printf("\n=== 1 =============================================\n");
		CQuaternion Q1;
		Dump(Q1);
	}

	{
		printf("\n=== 2 =============================================\n");
		CQuaternion Q2( CVector(0.0f,0.0f,666.0f), (float)CONST_PI );
		Dump(Q2);
	}

	{
		printf("\n=== 3 =============================================\n");
		CQuaternion Q3( 1, 1, 1, 1 );
		Dump(Q3);
		printf("%f\n", Q3.Norm() );
		printf("%f\n", Q3.Length() );
		Q3.Normalize();
		Dump(Q3);
	}

	{
		printf("\n=== 4 =============================================\n");
		CQuaternion Q4( 1, 1, 1, 1 );
		Dump(Q4);
		CQuaternion Q41 = !Q4;
		Dump(Q41);
		CQuaternion Q42 = -Q4;
		Dump(Q42);
	}

	{
		printf("\n=== 5 =============================================\n");
		CQuaternion Q51( 1, 2, 3, 4 );
		Dump(Q51);
		CQuaternion Q52( 1, 2, 3, -4 );
		Dump(Q52);
		printf("%f\n", Q51^Q52 );
	}

	{
		printf("\n=== 6 =============================================\n");
		CQuaternion Q61( 1, 2, 3, 4 );
		Dump(Q61);
		CQuaternion Q62( 5, 6, 7, 8 );
		Dump(Q62);
		Dump( Q61 + Q62 );
		Dump( Q61 - Q62 );
		Dump( Q61 += Q62 );
		Dump( Q61 -= Q62 );
	}

	{
		printf("\n=== 7 =============================================\n");
		CQuaternion Q71( 1, 2, 3, 4 );
		Q71.Normalize();
		Dump(Q71);
		printf("%f\n",Q71.Length());

		//CQuaternion Q72( 5, 6, 7, 8 );
		//Q72.Normalize();
		//Dump(Q72);
		//Dump( Q71 * Q72 );

		CQuaternion Q73 = -Q71;
		Dump( Q73 );
		printf("%f\n",Q73.Length());

		CQuaternion Product = Q71 * Q73;
		Dump( Product );
		printf("%f\n",Product.Length());

		Dump( Q71*=Q73 );
	}

	{
		printf("\n=== 8 =============================================\n");
		CQuaternion Q8( CVector(0.0f,0.0f,1.0f), (float)CONST_PI_2 );
		//CQuaternion Q8( CVector(0,0,1), CONST_PI );
		Dump(Q8);
		CVector Src(1,0,0);
		CVector Dst = RotateVectorByQuaternion( Src, Q8 );
		printf("%f %f %f\n",Dst.x,Dst.y,Dst.z);
	}

	{
		printf("\n=== 9 =============================================\n");
		CQuaternion Q81( CVector(0,0,1), 0 );
		Dump(Q81);
		CQuaternion Q82( CVector(0,0,1), CONST_PI );
		Dump(Q82);
		for( float t=0.0f; t<1.0f; t+=0.1f ) {
			CQuaternion R = SLerp(Q81,Q82,t);
			Dump( R );
		}
	}

	{
		printf("\n=== 10 ============================================\n");
		CQuaternion Q10( CVector(0,0,1), CONST_PI_2 );
		//CQuaternion Q10( CVector(0,0,1), CONST_PI );
		Dump(Q10);

		CVector V;
		float A;
		Q10.ToAxisAngle( V, A );
		printf("%f %f %f\n",V.x,V.y,V.z);
		printf("%f\n",A);

		CVector Src(1,0,0);
		CVector Dst1 = RotateVectorByQuaternion( Src, Q10 );
		printf("%f %f %f\n",Dst1.x,Dst1.y,Dst1.z);
		CVector Dst11 = Src*Q10;
		printf("%f %f %f\n",Dst11.x,Dst11.y,Dst11.z);

		CMatrix M( Q10.ToMatrix() );
		CVector Dst2 = Src*M;
		printf("%f %f %f\n",Dst2.x,Dst2.y,Dst2.z);

		CMatrix M3;
		M3.ConstructRotation( CVector(0,0,1), CONST_PI_2 );
		CVector Dst3 = Src*M3;
		printf("%f %f %f\n",Dst3.x,Dst3.y,Dst3.z);

		CMatrix M4;
		M4.ConstructRotationZ( CONST_PI_2 );
		CVector Dst4 = Src*M4;
		printf("%f %f %f\n",Dst4.x,Dst4.y,Dst4.z);
	}

	{
		printf("\n=== 11 =============================================\n");
		CMatrix M11;
		M11.ConstructRotation( CVector(0.3f,-0.78f,-0.9f), 0.666 );
		CQuaternion Q11 = CreateNonUnitQuaternionFromRotationMatrix( M11 );
		Q11.Normalize();
		CQuaternion Q111 = CreateUnitQuaternionFromRotationMatrix( M11 );
		Q111.Normalize();

		CVector V11( 0.0f, 0.0f, 1.0f );

		CVector R1 = V11*M11;
		printf("%f %f %f\n",R1.x,R1.y,R1.z);

		CVector R2 = RotateVectorByQuaternion( V11, Q11 );
		printf("%f %f %f\n",R2.x,R2.y,R2.z);

		CVector R3 = RotateVectorByQuaternion( V11, Q111 );
		printf("%f %f %f\n",R3.x,R3.y,R3.z);
	}

	{
		printf("\n=== 12 =============================================\n");
		CQuaternion Q1( CVector(1.0f,1.0f,1.0f), (float)CONST_PI_3 );
		Q1.Normalize();
		CQuaternion Q2( CVector(1.0f,1.0f,1.0f), (float)CONST_PI_3 );
		Q2.Normalize();
		CQuaternion Q3 = SLerp(Q1,Q2,0.5f);
		Dump(Q3);
	}
}
示例#9
0
void HTMLScript::Update(WEBC_PFBYTE o, WEBC_PFBYTE data)
{
#if (WEBC_SUPPORT_JSCRIPT)
HTMLDocument *pDoc = GetDocument();
WebcJSDocumentContext *jsMgr = (pDoc)? pDoc->GetJSMgr() : 0;

	if (mpScript || !jsMgr)
	{
		return;
	}

	WEBC_NEW_VERBOSE(mpScript, WebcJSScript(jsMgr, jsMgr->GetGlobalObject()),"WebcJSDocumentContext");

	if (mpScript)
	{
		if (Src())
		{
			LoadScript *pJob;
			if (pDoc)
			{
				HTMLBrowser *pBrowser = pDoc->GetBrowser();
				if (pBrowser)
				{
					WebcCharset charset = (mCharset == WEBC_CHARSET_UNKNOWN)? pDoc->GetCharset() : mCharset;
					WEBC_NEW_VERBOSE(pJob, LoadScript(this, pDoc, charset),"LoadScript");
					if (pJob)
					{
						pBrowser->ProcessLoadJob(pJob, pJob->GetURL(), pDoc->BaseURL(), pDoc, WEBC_TRUE /* urgent */);
					}
					webc_free_string_copy(mpSrc, __FILE__, __LINE__);
					mpSrc = 0;
				}
			}
		}
		else // compile the contents of this tag as the script to execute
		{
			HTMLElement *pChild = mpFirstChild;
			WEBC_CHAR* pStr;
			long iLen;
			for (; pChild != WEBC_NULL; pChild = pChild->mpNext)
			{
				if (pChild->Type() == HTML_STRING_ELEMENT)
				{
					pStr = ((HTMLString*)(pChild))->GetString();
					iLen = webc_strlen(pStr);
					if (mpScript->Write(pStr, iLen) < iLen)
					{
						mpScript->Destroy();
						mpScript = 0;
						break;
					}
				}
			}

			if (mpScript)
			{
				mpScript->Compile();
			}

			DeleteChildren();
		}
	}

#endif
}
int
main(int argc, char **argv)
{
    /* Plant signal catcher. */
    {
	static int getsigs[] = {
	    /* signals to catch */
#ifdef SIGHUP
	    SIGHUP,			/* hangup */
#endif
#ifdef SIGINT
	    SIGINT,			/* interrupt */
#endif
#ifdef SIGQUIT
	    SIGQUIT,		/* quit */
#endif
#ifdef SIGPIPE
	    SIGPIPE,		/* write on a broken pipe */
#endif
#ifdef SIGTERM
	    SIGTERM,		/* software termination signal */
#endif
	    0
	};
	int i;

	for (i = 0; getsigs[i] != 0; ++i)
	    if (signal(getsigs[i], SIG_IGN) != SIG_IGN)
		(void)signal(getsigs[i], Sig_Catcher);
    }

    /* Process arguments. */
    {
	int c;
	bool_t errors = 0;

	while ((c = bu_getopt(argc, argv, OPTSTR)) != -1)
	    switch (c) {
		default:	/* '?': invalid option */
		    errors = 1;
		    break;

		case 'a':	/* -a */
		    sample = 1;
		    break;

		case 'f':	/* -f in_fb */
		    src_file = bu_optarg;
		    break;

		case 'F':	/* -F out_fb */
		    dst_file = bu_optarg;
		    break;

		case 'n':	/* -n height */
		    if ((src_height = atoi(bu_optarg)) <= 0)
			errors = 1;

		    break;

		case 'N':	/* -N height */
		    if ((dst_height = atoi(bu_optarg)) <= 0)
			errors = 1;

		    break;

		case 's':	/* -s size */
		    if ((src_height = src_width = atoi(bu_optarg))
			<= 0
			)
			errors = 1;

		    break;

		case 'S':	/* -S size */
		    if ((dst_height = dst_width = atoi(bu_optarg))
			<= 0
			)
			errors = 1;

		    break;

		case 'v':
		    verbose = 1;
		    break;

		case 'w':	/* -w width */
		    if ((src_width = atoi(bu_optarg)) <= 0)
			errors = 1;

		    break;

		case 'W':	/* -W width */
		    if ((dst_width = atoi(bu_optarg)) <= 0)
			errors = 1;

		    break;

		case 'x':	/* -x x_scale */
		    if ((x_scale = atof(bu_optarg)) <= 0) {
			Message("Nonpositive x scale factor");
			errors = 1;
		    }

		    break;

		case 'y':	/* -y y_scale */
		    if ((y_scale = atof(bu_optarg)) <= 0) {
			Message("Nonpositive y scale factor");
			errors = 1;
		    }

		    break;
	    }

	if (argc == 1 && isatty(fileno(stdin)) && isatty(fileno(stdout)))
	    errors = 1;

	if (errors)
	    bu_exit(1, "Usage: %s\n%s\n%s\n", USAGE1, USAGE2, USAGE3);
    }

    if (bu_optind < argc) {
	/* dst_file */
	if (bu_optind < argc - 1 || dst_file != NULL) {
	    bu_log("Usage: %s\n%s\n%s", USAGE1, USAGE2, USAGE3);
	    Stretch_Fatal("Can't handle multiple output frame buffers!");
	}

	dst_file = argv[bu_optind];
    }

    if (dst_file == NULL)
	dst_file = getenv("FB_FILE");

    /* Figure out what scale factors to use before messing up size info. */

    if (x_scale < 0.0) {
	if (src_width == 0 || dst_width == 0)
	    x_scale = 1.0;
	else
	    x_scale = (double)dst_width / (double)src_width;
    }

    if (y_scale < 0.0) {
	if (src_height == 0 || dst_height == 0)
	    y_scale = 1.0;
	else
	    y_scale = (double)dst_height / (double)src_height;
    }

    if (verbose)
	Message("Scale factors %gx%g", x_scale, y_scale);

    /* Open frame buffer(s) for unbuffered input/output. */

    if ((src_fbp = fb_open(src_file == NULL ? dst_file : src_file,
			   src_width, src_height
	     )
	    ) == FB_NULL
	)
	Stretch_Fatal("Couldn't open input image");
    else {
	int wt, ht;	/* actual frame buffer size */

	/* Use smaller input size in preference to requested size. */

	if ((wt = fb_getwidth(src_fbp)) < src_width)
	    src_width = wt;

	if ((ht = fb_getheight(src_fbp)) < src_height)
	    src_height = ht;

	if (verbose)
	    Message("Source image %dx%d", src_width, src_height);

	if (dst_width == 0)
	    dst_width = src_width * x_scale + EPSILON;

	if (dst_height == 0)
	    dst_height = src_height * y_scale + EPSILON;

	if (verbose)
	    Message("Requested output size %dx%d",
		    dst_width, dst_height
		);

	if (src_file == NULL
	    || (dst_file != NULL && BU_STR_EQUAL(src_file, dst_file))
	    )
	    dst_fbp = src_fbp;	/* No No No Not a Second Time */
	else if ((dst_fbp = fb_open(dst_file, dst_width, dst_height))
		 == FB_NULL
	    )
	    Stretch_Fatal("Couldn't open output frame buffer");

	/* Use smaller output size in preference to requested size. */

	if ((wt = fb_getwidth(dst_fbp)) < dst_width)
	    dst_width = wt;

	if ((ht = fb_getheight(dst_fbp)) < dst_height)
	    dst_height = ht;

	if (verbose)
	    Message("Destination image %dx%d",
		    dst_width, dst_height
		);
    }

    /* Determine compression/expansion directions. */

    x_compress = x_scale < 1 - EPSILON;
    y_compress = y_scale < 1 - EPSILON;

    /* Allocate input/output scan line buffers.  These could overlap, but
       I decided to keep them separate for simplicity.  The algorithms are
       arranged so that source and destination can access the same image; if
       at some future time offsets are supported, that would no longer hold.
       calloc is used instead of malloc just to avoid integer overflow. */

    if ((src_buf = (unsigned char *)calloc(
	     y_compress ? (int)(1 / y_scale + 1 - EPSILON) * src_width
	     : src_width,
	     sizeof(RGBpixel)
	     )
	    ) == NULL
	|| (dst_buf = (unsigned char *)calloc(
		y_compress ? dst_width
		: (int)(y_scale + 1 - EPSILON) * dst_width,
		sizeof(RGBpixel)
		)
	    ) == NULL
	)
	Stretch_Fatal("Insufficient memory for scan line buffers.");

#define Src(x, y)	(&src_buf[(x) + src_width * (y) * sizeof(RGBpixel)])
#define Dst(x, y)	(&dst_buf[(x) + dst_width * (y) * sizeof(RGBpixel)])

    /* Do the horizontal/vertical expansion/compression.  I wanted to merge
       these but didn't like the extra bookkeeping overhead in the loops. */

    if (x_compress && y_compress) {
	int src_x, src_y;	/* source rect. pixel coords. */
	int dst_x, dst_y;	/* destination pixel coords. */
	int top_x, top_y;	/* source rect. upper bounds */
	int bot_x, bot_y;	/* source rect. lower bounds */

	/* Compute coords. of source rectangle and destination pixel. */

	dst_y = 0;
    ccyloop:
	if (dst_y >= dst_height)
	    goto done;	/* that's all folks */

	bot_y = dst_y / y_scale + EPSILON;

	if ((top_y = (dst_y + 1) / y_scale + EPSILON) > src_height)
	    top_y = src_height;

	if (top_y <= bot_y) {
	    /* End of image. */

	    /* Clear beginning of output scan line buffer. */

	    dst_x = src_width * y_scale + EPSILON;

	    if (dst_x < dst_width)
		++dst_x;	/* sometimes needed */

	    while (--dst_x >= 0) {
		assert(dst_x < dst_width);
		Dst(dst_x, 0)[RED] = 0;
		Dst(dst_x, 0)[GRN] = 0;
		Dst(dst_x, 0)[BLU] = 0;
	    }

	    /* Clear out top margin. */

	    for (; dst_y < dst_height; ++dst_y)
		if (fb_write(dst_fbp, 0, dst_y,
			     (unsigned char *)Dst(0, 0),
			     dst_width
			) == -1
		    )
		    Stretch_Fatal("Error writing top margin");

	    goto done;	/* that's all folks */
	}

	assert(0 <= bot_y && bot_y < top_y && top_y <= src_height);
	assert(0 <= dst_y && dst_y <= bot_y);
	assert(top_y - bot_y <= (int)(1 / y_scale + 1 - EPSILON));

	/* Fill input scan line buffer. */

	for (src_y = bot_y; src_y < top_y; ++src_y)
	    if (fb_read(src_fbp, 0, src_y,
			(unsigned char *)Src(0, src_y - bot_y),
			src_width
		    ) == -1
		)
		Stretch_Fatal("Error reading scan line");

	dst_x = 0;
    ccxloop:
	if (dst_x >= dst_width)
	    goto ccflush;

	bot_x = dst_x / x_scale + EPSILON;

	if ((top_x = (dst_x + 1) / x_scale + EPSILON) > src_width)
	    top_x = src_width;

	if (top_x <= bot_x) {
	ccflush:		/* End of band; flush buffer. */

	    if (fb_write(dst_fbp, 0, dst_y,
			 (unsigned char *)Dst(0, 0),
			 dst_width
		    ) == -1
		)
		Stretch_Fatal("Error writing scan line");

	    ++dst_y;
	    goto ccyloop;
	}

	assert(0 <= bot_x && bot_x < top_x && top_x <= src_width);
	assert(0 <= dst_x && dst_x <= bot_x);
	assert(top_x - bot_x <= (int)(1 / x_scale + 1 - EPSILON));

	/* Copy sample or averaged source pixel(s) to destination. */

	if (sample) {
	    Dst(dst_x, 0)[RED] = Src(bot_x, 0)[RED];
	    Dst(dst_x, 0)[GRN] = Src(bot_x, 0)[GRN];
	    Dst(dst_x, 0)[BLU] = Src(bot_x, 0)[BLU];
	} else {
	    int sum[3];	/* pixel value accumulator */
	    float tally;	/* # of pixels accumulated */

	    /* "Read in" source rectangle and average pixels. */

	    sum[RED] = sum[GRN] = sum[BLU] = 0;

	    for (src_y = top_y - bot_y; --src_y >= 0;)
		for (src_x = bot_x; src_x < top_x; ++src_x) {
		    sum[RED] += Src(src_x, src_y)[RED];
		    sum[GRN] += Src(src_x, src_y)[GRN];
		    sum[BLU] += Src(src_x, src_y)[BLU];
		}

	    tally = (top_x - bot_x) * (top_y - bot_y);
	    assert(tally > 0.0);
	    Dst(dst_x, 0)[RED] = sum[RED] / tally + 0.5;
	    Dst(dst_x, 0)[GRN] = sum[GRN] / tally + 0.5;
	    Dst(dst_x, 0)[BLU] = sum[BLU] / tally + 0.5;
	}

	++dst_x;
	goto ccxloop;
    } else if (x_compress && !y_compress) {
	int src_x, src_y;	/* source rect. pixel coords. */
	int dst_x, dst_y;	/* dest. rect. pixel coords. */
	int bot_x, top_x;	/* source rectangle bounds */
	int bot_y, top_y;	/* destination rect. bounds */

	/* Compute coords. of source and destination rectangles. */

	src_y = (dst_height - 1) / y_scale + EPSILON;
    ceyloop:
	if (src_y < 0)
	    goto done;	/* that's all folks */

	bot_y = src_y * y_scale + EPSILON;

	if ((top_y = (src_y + 1) * y_scale + EPSILON) > dst_height)
	    top_y = dst_height;

	assert(0 <= src_y && src_y <= bot_y && src_y < src_height);
	assert(bot_y < top_y && top_y <= dst_height);
	assert(top_y - bot_y <= (int)(y_scale + 1 - EPSILON));

	/* Fill input scan line buffer. */

	if (fb_read(src_fbp, 0, src_y, (unsigned char *)Src(0, 0),
		    src_width
		) == -1
	    )
	    Stretch_Fatal("Error reading scan line");

	dst_x = 0;
    cexloop:
	if (dst_x >= dst_width)
	    goto ceflush;

	bot_x = dst_x / x_scale + EPSILON;

	if ((top_x = (dst_x + 1) / x_scale + EPSILON) > src_width)
	    top_x = src_width;

	if (top_x <= bot_x) {
	ceflush:		/* End of band; flush buffer. */

	    for (dst_y = top_y; --dst_y >= bot_y;)
		if (fb_write(dst_fbp, 0, dst_y,
			     (unsigned char *)Dst(0, dst_y - bot_y
				 ),
			     dst_width
			) == -1
		    )
		    Stretch_Fatal("Error writing scan line");

	    --src_y;
	    goto ceyloop;
	}

	assert(0 <= bot_x && bot_x < top_x && top_x <= src_width);
	assert(0 <= dst_x && dst_x <= bot_x);
	assert(top_x - bot_x <= (int)(1 / x_scale + 1 - EPSILON));

	/* Replicate sample or averaged source pixel(s) to dest. */

	if (sample) {
	    for (dst_y = top_y - bot_y; --dst_y >= 0;) {
		Dst(dst_x, dst_y)[RED] = Src(bot_x, 0)[RED];
		Dst(dst_x, dst_y)[GRN] = Src(bot_x, 0)[GRN];
		Dst(dst_x, dst_y)[BLU] = Src(bot_x, 0)[BLU];
	    }
	} else {
	    int sum[3];	/* pixel value accumulator */
	    float tally;	/* # of pixels accumulated */

	    /* "Read in" source rectangle and average pixels. */

	    sum[RED] = sum[GRN] = sum[BLU] = 0;

	    for (src_x = bot_x; src_x < top_x; ++src_x) {
		sum[RED] += Src(src_x, 0)[RED];
		sum[GRN] += Src(src_x, 0)[GRN];
		sum[BLU] += Src(src_x, 0)[BLU];
	    }

	    tally = top_x - bot_x;
	    assert(tally > 0.0);
	    sum[RED] = sum[RED] / tally + 0.5;
	    sum[GRN] = sum[GRN] / tally + 0.5;
	    sum[BLU] = sum[BLU] / tally + 0.5;

	    for (dst_y = top_y - bot_y; --dst_y >= 0;) {
		Dst(dst_x, dst_y)[RED] = sum[RED];
		Dst(dst_x, dst_y)[GRN] = sum[GRN];
		Dst(dst_x, dst_y)[BLU] = sum[BLU];
	    }
	}

	++dst_x;
	goto cexloop;
    } else if (!x_compress && y_compress) {
	int src_x, src_y;	/* source rect. pixel coords. */
	int dst_x, dst_y;	/* dest. rect. pixel coords. */
	int bot_x, top_x;	/* destination rect. bounds */
	int bot_y, top_y;	/* source rectangle bounds */

	assert(dst_width >= src_width);	/* (thus no right margin) */

	/* Compute coords. of source and destination rectangles. */

	dst_y = 0;
    ecyloop:
	if (dst_y >= dst_height)
	    goto done;	/* that's all folks */

	bot_y = dst_y / y_scale + EPSILON;

	if ((top_y = (dst_y + 1) / y_scale + EPSILON) > src_height)
	    top_y = src_height;

	if (top_y <= bot_y) {
	    /* End of image. */

	    /* Clear output scan line buffer. */

	    for (dst_x = dst_width; --dst_x >= 0;) {
		Dst(dst_x, 0)[RED] = 0;
		Dst(dst_x, 0)[GRN] = 0;
		Dst(dst_x, 0)[BLU] = 0;
	    }

	    /* Clear out top margin. */

	    for (; dst_y < dst_height; ++dst_y)
		if (fb_write(dst_fbp, 0, dst_y,
			     (unsigned char *)Dst(0, 0),
			     dst_width
			) == -1
		    )
		    Stretch_Fatal("Error writing top margin");

	    goto done;	/* that's all folks */
	}

	assert(0 <= bot_y && bot_y < top_y && top_y <= src_height);
	assert(0 <= dst_y && dst_y <= bot_y);
	assert(top_y - bot_y <= (int)(1 / y_scale + 1 - EPSILON));

	/* Fill input scan line buffer. */

	for (src_y = bot_y; src_y < top_y; ++src_y)
	    if (fb_read(src_fbp, 0, src_y,
			(unsigned char *)Src(0, src_y - bot_y),
			src_width
		    ) == -1
		)
		Stretch_Fatal("Error reading scan line");

	src_x = (dst_width - 1) / x_scale + EPSILON;
    ecxloop:
	if (src_x < 0) {
	    /* End of band; flush buffer. */
	    if (fb_write(dst_fbp, 0, dst_y,
			 (unsigned char *)Dst(0, 0),
			 dst_width
		    ) == -1
		)
		Stretch_Fatal("Error writing scan line");

	    ++dst_y;
	    goto ecyloop;
	}

	bot_x = src_x * x_scale + EPSILON;

	if ((top_x = (src_x + 1) * x_scale + EPSILON) > dst_width)
	    top_x = dst_width;

	assert(0 <= src_x && src_x <= bot_x && src_x <= src_width);
	assert(bot_x < top_x && top_x <= dst_width);
	assert(top_x - bot_x <= (int)(x_scale + 1 - EPSILON));

	/* Replicate sample or averaged source pixel(s) to dest. */

	if (sample) {
	    for (dst_x = top_x; --dst_x >= bot_x;) {
		Dst(dst_x, 0)[RED] = Src(src_x, 0)[RED];
		Dst(dst_x, 0)[GRN] = Src(src_x, 0)[GRN];
		Dst(dst_x, 0)[BLU] = Src(src_x, 0)[BLU];
	    }
	} else {
	    int sum[3];	/* pixel value accumulator */
	    float tally;	/* # of pixels accumulated */

	    /* "Read in" source rectangle and average pixels. */

	    sum[RED] = sum[GRN] = sum[BLU] = 0;

	    for (src_y = top_y - bot_y; --src_y >= 0;) {
		sum[RED] += Src(src_x, src_y)[RED];
		sum[GRN] += Src(src_x, src_y)[GRN];
		sum[BLU] += Src(src_x, src_y)[BLU];
	    }

	    tally = top_y - bot_y;
	    assert(tally > 0.0);
	    sum[RED] = sum[RED] / tally + 0.5;
	    sum[GRN] = sum[GRN] / tally + 0.5;
	    sum[BLU] = sum[BLU] / tally + 0.5;

	    for (dst_x = top_x; --dst_x >= bot_x;) {
		Dst(dst_x, 0)[RED] = sum[RED];
		Dst(dst_x, 0)[GRN] = sum[GRN];
		Dst(dst_x, 0)[BLU] = sum[BLU];
	    }
	}

	--src_x;
	goto ecxloop;
    } else if (!x_compress && !y_compress) {
	int src_x, src_y;	/* source pixel coords. */
	int dst_x, dst_y;	/* dest. rect. pixel coords. */
	int bot_x, bot_y;	/* dest. rect. lower bounds */
	int top_x, top_y;	/* dest. rect. upper bounds */

	assert(dst_width >= src_width);	/* (thus no right margin) */

	/* Compute coords. of source and destination rectangles. */

	src_y = (dst_height - 1) / y_scale + EPSILON;
    eeyloop:
	if (src_y < 0)
	    goto done;	/* that's all folks */

	bot_y = src_y * y_scale + EPSILON;

	if ((top_y = (src_y + 1) * y_scale + EPSILON) > dst_height)
	    top_y = dst_height;

	assert(0 <= src_y && src_y <= bot_y && src_y < src_height);
	assert(bot_y < top_y && top_y <= dst_height);
	assert(top_y - bot_y <= (int)(y_scale + 1 - EPSILON));

	/* Fill input scan line buffer. */
	if (fb_read(src_fbp, 0, src_y, (unsigned char *)Src(0, 0),
		    src_width
		) == -1
	    )
	    Stretch_Fatal("Error reading scan line");

	src_x = (dst_width - 1) / x_scale + EPSILON;
    eexloop:
	if (src_x < 0) {
	    /* End of band; flush buffer. */

	    for (dst_y = top_y; --dst_y >= bot_y;)
		if (fb_write(dst_fbp, 0, dst_y,
			     (unsigned char *)Dst(0, dst_y - bot_y
				 ),
			     dst_width
			) == -1
		    )
		    Stretch_Fatal("Error writing scan line");

	    --src_y;
	    goto eeyloop;
	}

	bot_x = src_x * x_scale + EPSILON;

	if ((top_x = (src_x + 1) * x_scale + EPSILON) > dst_width)
	    top_x = dst_width;

	assert(0 <= src_x && src_x <= bot_x && src_x <= src_width);
	assert(bot_x < top_x && top_x <= dst_width);
	assert(top_x - bot_x <= (int)(x_scale + 1 - EPSILON));

	/* Replicate sample source pixel to destination. */

	for (dst_y = top_y - bot_y; --dst_y >= 0;)
	    for (dst_x = top_x; --dst_x >= bot_x;) {
		Dst(dst_x, dst_y)[RED] = Src(src_x, 0)[RED];
		Dst(dst_x, dst_y)[GRN] = Src(src_x, 0)[GRN];
		Dst(dst_x, dst_y)[BLU] = Src(src_x, 0)[BLU];
	    }

	--src_x;
	goto eexloop;
    }

done:
    /* Close the frame buffers. */

    assert(src_fbp != FB_NULL && dst_fbp != FB_NULL);

    if (fb_close(src_fbp) == -1)
	Message("Error closing input frame buffer");

    if (dst_fbp != src_fbp && fb_close(dst_fbp) == -1)
	Message("Error closing output frame buffer");

    return 0;
}
示例#11
0
int CModelListHelper::BuildList(LPCTSTR SectName, char* pGroup, CComboBox* pCB, CTreeCtrl *pTree, CProfINIFile *pPF)
  {
  LPCTSTR InitialSelect = pPF?pPF->RdStr(SectName, "$LastInsert", (char*)DefaultLastUnit):"?";
  if (!InitialSelect)
    InitialSelect ="";

  DWORD LicCat = gs_License.LicCatagories();
  Strng Desc;
  RequestModelInfoRec MInfo;
  HTREEITEM hSelected=NULL, hFirst=NULL;

  CString Sect(SectName);
  Sect+=".Tree";

  int nValidModels = 0;
  int nModels = 0;
  while (gs_pPrj->RequestModelInfoByGroupIndex(pGroup, nModels, MInfo))
    {
    const bool ModelGroupOK = ((LicCat & TOC_MDL_MASK & MInfo.Category)!=0);
    const bool SolveModeOK = ((LicCat & TOC_SOLVE_MASK & MInfo.Category)!=0);
    if (MInfo.IsSelectable && ModelGroupOK && SolveModeOK)
      {
      char* pSlctText = MInfo.ShortDesc() ? MInfo.ShortDesc() : MInfo.Class();
      if (pCB)
        pCB->AddString(pSlctText);
      Desc.Set("%s:%s", pSlctText, (MInfo.Desc() ? MInfo.Desc() : "No Description Available"));
      m_ModelDescLst.Append(Desc());
      m_ModelBaseTagLst.Append(MInfo.TagInitialID());
      m_ModelClassLst.Append(MInfo.Class());
      m_ModelDrwGroupLst.Append(MInfo.DrwGroup());

      if (0)
        {
        // temporary code to Restructure FlwSymbols 
        for (int Pass=0; Pass<4; Pass++)
          {
          Strng Path;
          Path.Set("%s%s.*.%s", Pass<2?BaseGrfSymbolFiles():GrfSymbolFiles(), MInfo.TagInitialID(), Pass%2==0?"DXF":"BMP");
          WIN32_FIND_DATA fd;
          HANDLE H = FindFirstFile(Path(), &fd);
          bool AllDone = (H==INVALID_HANDLE_VALUE);
          while (!AllDone)
            {
            Strng Folder, Src, Dst;
            Folder.Set("%s%s", BaseGrfSymbolFiles(), MInfo.DrwGroup());
            Src.Set("%s%s", BaseGrfSymbolFiles(), fd.cFileName);
            Dst.Set("%s%s\\%s", BaseGrfSymbolFiles(), MInfo.DrwGroup(), &fd.cFileName[MInfo.TagInitialID.Length()+1]);
            dbgpln("MOVE %-60s >> %s", Src(), Dst());

            Strng E;
            if (FnCreatePath(Folder(), E))
              {
              Move_FileEx(Src(), Dst(), MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH);
              }

            AllDone = !FindNextFile(H, &fd);
            }
          FindClose(H);
          }
        }

      if (pTree)
        {
        HTREEITEM hParent = TVI_ROOT, hItem;
        char Buff[2048];
        char *pS=Buff, *pE;
        strcpy(Buff, pSlctText);
        while ((pE=strchr(pS, ':'))!=NULL)
          {
          *pE=0;
          XStrTrim(pS, " ");
          for (hItem=pTree->GetNextItem(hParent, TVGN_CHILD);
               hItem!=NULL; 
               hItem=pTree->GetNextItem(hItem, TVGN_NEXT))
            {
            CString S=pTree->GetItemText(hItem);
            if (S.CompareNoCase(pS)==0)
              break;
            }
          if (hItem==NULL)
            {
            XStrTrim(pS, " ");
            hItem=pTree->InsertItem(pS, 0, 0, hParent);
            pTree->SortChildren(hParent);
            pTree->SetItemData(hItem, 0xFFFF);
            pTree->SetItemImage(hItem, 0, 1);
            }
          hParent=hItem;
          pS=pE+1;
          }

        XStrTrim(pS, " ");
        hItem=pTree->InsertItem(pS, 0, 0, hParent);
        if (_stricmp(MInfo.Class(), InitialSelect)==0)
          hSelected=hItem;
        if (hFirst==NULL)
          hFirst=hItem;
        pTree->SetItemData(hItem, nValidModels);
        pTree->SortChildren(hParent);
        pTree->SetItemImage(hItem, 2, 3);

        if (pPF)
          {
          // Restore State of Tree
          HTREEITEM hParent = TVI_ROOT, hItem;
          CString Txt[10];
          long iDepth=0;
          hItem=pTree->GetNextItem(TVI_ROOT, TVGN_CHILD);
          while (hItem && iDepth>=0)
            {
            UINT State=pTree->GetItemState(hItem, TVIS_EXPANDED );
            if (1)
              {
              CString S;
              for (int i=0; i<iDepth; i++)
                S+=Txt[i];
              S+=pTree->GetItemText(hItem);        
              UINT State=(UINT)pPF->RdInt(Sect, S, 0);
              if (State&TVIS_EXPANDED)
                {
                pTree->Expand(hItem, TVE_EXPAND);        
                //??????????
                }
              }
            
            HTREEITEM h=pTree->GetNextItem(hItem, TVGN_CHILD);
            if (h)
              {
              Txt[iDepth]=pTree->GetItemText(hItem);        
              Txt[iDepth]+=":";        
              iDepth++;
              hItem=h;
              }
            else
              {
              h=pTree->GetNextItem(hItem, TVGN_NEXT);
              if (h)
                {
                hItem=h;
                }
              else
                {
                // Go One up & One along 
                hItem=pTree->GetNextItem(hItem, TVGN_PARENT);
                if (hItem)
                  hItem=pTree->GetNextItem(hItem, TVGN_NEXT);
                iDepth--;
                }
              }
            }
          }
        }
      nValidModels++;
      }
    nModels++;
    }
  if (pTree)
    {
    if (!hSelected)
      hSelected=hFirst;
    pTree->Select(hSelected, TVGN_CARET);
    //pTree->SelectSetFirstVisible(hSelected);
    }
  return nValidModels;
  }