Exemple #1
0
X BigInteger::convertToSignedPrimitive() const {
	if (sign == zero)
		return 0;
	else if (mag.getLength() == 1) {
		// The single block might fit in an X.  Try the conversion.
		Blk b = mag.getBlock(0);
		if (sign == positive) {
			X x = X(b);
			if (x >= 0 && Blk(x) == b)
				return x;
		} else {
			X x = -X(b);
			/* UX(...) needed to avoid rejecting conversion of
			 * -2^15 to a short. */
			if (x < 0 && Blk(UX(-x)) == b)
				return x;
		}
		// Otherwise fall through.
	}
	throw "BigInteger::to<Primitive>: "
		"Value is too big to fit in the requested type";
}
Exemple #2
0
void CImage::WriteHeader(ScsiWindow *pscsiwindow, int size, char *szMeta)
{
	TiffBitonal tiffbitonal;
	TiffGray tiffgray;
	TiffColor tiffcolor;

	if (pod.m_pfile)
	{
		fseek(pod.m_pfile,0,SEEK_SET);
		switch (pscsiwindow->ImageComposition)
		{
			default:
			case 1:
				memcpy(&tiffbitonal,&s_tiffbitonal,sizeof(tiffbitonal));
				tiffbitonal.tifftag[2].u32Value   = UX(pscsiwindow->Width) / (1200 / WX(pscsiwindow->X_resolution));
				tiffbitonal.tifftag[3].u32Value   = size / ((tiffbitonal.tifftag[2].u32Value + 7) / 8);
				tiffbitonal.tifftag[5].u32Value   = 1;
				tiffbitonal.tifftag[6].u32Value   = 1;
				tiffbitonal.tifftag[10].u32Value  = size / ((tiffbitonal.tifftag[2].u32Value + 7) / 8);
				tiffbitonal.tifftag[11].u32Value  = size;
				tiffbitonal.tifftag[14].u32Value  = 292;
				tiffbitonal.tifftag[14].u32Value  = 0;
				tiffbitonal.u32XResolution[0]     = WX(pscsiwindow->X_resolution);
				tiffbitonal.u32YResolution[0]     = WX(pscsiwindow->Y_resolution);
				fwrite(&tiffbitonal,1,sizeof(tiffbitonal),pod.m_pfile);
				if (szMeta)
				{
					sprintf
					(
						szMeta,
						"<sword>\n"
						"\t<pixel>bw</pixel>\n"
						"\t<resolution>%d</resolution>\n"
						"\t<size>%d</size>\n"
						"\t<width>%d</width>\n"
						"\t<height>%d</height>\n"
						"\t<bytesperrow>%d</bytesperrow>\n"
						"</sword>\n",
						WX(pscsiwindow->X_resolution),
						sizeof(tiffbitonal) + size,
						UX(tiffbitonal.tifftag[2].u32Value),
						UX(tiffbitonal.tifftag[3].u32Value),
						tiffbitonal.tifftag[10].u32Value
					);
				}
				break;
			case 2:
				memcpy(&tiffgray,&s_tiffgray,sizeof(tiffgray));
				tiffgray.tifftag[2].u32Value   = UX(pscsiwindow->Width) / (1200 / WX(pscsiwindow->X_resolution));
				tiffgray.tifftag[3].u32Value   = size / tiffgray.tifftag[2].u32Value;
				tiffgray.tifftag[5].u32Value   = 1;
				tiffgray.tifftag[9].u32Value   = size / tiffgray.tifftag[2].u32Value;
				tiffgray.tifftag[10].u32Value  = size;
				tiffgray.u32XResolution[0]     = WX(pscsiwindow->X_resolution);
				tiffgray.u32YResolution[0]     = WX(pscsiwindow->Y_resolution);
				fwrite(&tiffgray,1,sizeof(tiffgray),pod.m_pfile);
				if (szMeta)
				{
					sprintf
					(
						szMeta,
						"<sword>\n"
						"\t<pixel>gray</pixel>\n"
						"\t<resolution>%d</resolution>\n"
						"\t<size>%d</size>\n"
						"\t<width>%d</width>\n"
						"\t<height>%d</height>\n"
						"\t<bytesperrow>%d</bytesperrow>\n"
						"</sword>\n",
						WX(pscsiwindow->X_resolution),
						sizeof(tiffgray) + size,
						tiffgray.tifftag[2].u32Value,
						tiffgray.tifftag[3].u32Value,
						tiffgray.tifftag[9].u32Value
					);
				}
				break;
			case 5:
				memcpy(&tiffcolor,&s_tiffcolor,sizeof(tiffcolor));
				tiffcolor.tifftag[2].u32Value   = UX(pscsiwindow->Width) / (1200 / WX(pscsiwindow->X_resolution));
				tiffcolor.tifftag[3].u32Value   = size / (tiffcolor.tifftag[2].u32Value * 3);
				tiffcolor.tifftag[5].u32Value   = 1;
				tiffcolor.tifftag[9].u32Value   = size / (tiffcolor.tifftag[2].u32Value * 3);
				tiffcolor.tifftag[10].u32Value  = size;
				tiffcolor.u32XResolution[0]     = WX(pscsiwindow->X_resolution);
				tiffcolor.u32YResolution[0]     = WX(pscsiwindow->Y_resolution);
				fwrite(&tiffcolor,1,sizeof(tiffcolor),pod.m_pfile);
				if (szMeta)
				{
					sprintf
					(
						szMeta,
						"<sword>\n"
						"\t<pixel>color</pixel>\n"
						"\t<resolution>%d</resolution>\n"
						"\t<size>%d</size>\n"
						"\t<width>%d</width>\n"
						"\t<height>%d</height>\n"
						"\t<bytesperrow>%d</bytesperrow>\n"
						"</sword>\n",
						WX(pscsiwindow->X_resolution),
						sizeof(tiffcolor) + size,
						UX(tiffcolor.tifftag[2].u32Value),
						UX(tiffcolor.tifftag[3].u32Value),
						tiffcolor.tifftag[9].u32Value
					);
				}
				break;
		}
	}
}