Beispiel #1
0
static void writePngs(char *outputDir, wlImages cursors)
{
    int i;
    char *oldDir;
    char filename[6];
    
    oldDir = getcwd(NULL, 0);
    if (chdir(outputDir))
    {
        die("Unable to change to output directory %s: %s\n", outputDir,
                strerror(errno));
        return;
    }
    for (i = 0; i < 8; i++)
    {
        sprintf(filename, "%i.png", i);
        writePng(filename, cursors, i); 
    }
    if (chdir(oldDir))
    {
        die("Unable to change to directory %s: %s\n", outputDir,
                strerror(errno));
        return;
    }
    free(oldDir);
}
Beispiel #2
0
int main(int argc, char *argv[])
{  
    char *source, *dest;
    wlImage pic;
    
    /* Process options and reset argument pointer */
    check_options(argc, argv);
    argc -= optind;
    argv += optind;
    
    /* Terminate if wrong number of parameters are specified */
    if (argc != 2) die("Wrong number of parameters.\nUse --help to show syntax.\n");

    /* Process parameters */
    source = argv[0];
    dest = argv[1];
    
    /* Read the pic file */
    pic = wlPicReadFile(source);
    if (!pic)
    {
        die("Unable to read PIC file %s: %s\n", source, strerror(errno));
    }

    /* Write the PNG file */
    writePng(dest, pic);
    
    /* Free resources */
    wlImageFree(pic);
    
    /* Success */
    return 0;
}
Beispiel #3
0
void GImage::savePng(const char* szFilename)
{
	FILE* pFile = fopen(szFilename, "wb");
	if(!pFile)
		throw Ex("Failed to create file: ", szFilename);
	writePng(this, pFile, true);
	fclose(pFile);
}
Beispiel #4
0
bool
PngScreen::imageToFile (CompString &path,
			CompString &format,
			CompSize   &size,
			int	   stride,
			void	   *data)
{
    bool          status = false;
    std::ofstream file;
    CompString    fileName = fileNameWithExtension (path);

    if (format == "png")
    {
	file.open (fileName.c_str ());
	if (file.is_open ())
	{
	    status = writePng ((unsigned char *) data, file, size, stride);
	    file.close ();
	}

	if (status)
	    return true;
    }

    status = screen->imageToFile (path, format, size, stride, data);

    if (!status)
    {
	file.open (fileName.c_str ());
	if (file.is_open ())
	{
	    status = writePng ((unsigned char *) data, file, size, stride);
	    file.close ();
	}
    }

    return status;
}
Beispiel #5
0
// Prints the nap to the console
void Map::printMap()
{
	for (int i = 0; i < height; i++)
	{
		for (int j = 0; j < width; j++)
		{
			std::cout <<  matrix[i][j] << "";
		}

		std::cout << std::endl;
	}

	writePng("helloyair.png", image, width, height);
}
Beispiel #6
0
void Map::expand()
{
	int robotSizeInPixels = 12;

	// Init the matrix values
	for (int i = 0; i < width * height * 4; i += 4)
	{
		unsigned int r = image[i];
		unsigned int g = image[i + 1];
		unsigned int b = image[i + 2];

		// If its a Black pixel - expand it
		if ((r == 0) & (g == 0) & (b == 0))
		{
			expandPixel(i, robotSizeInPixels);
		}
	}

	writePng("AfterExpandRED.jpg", image, width, height);

	// Transform red to black
	for (int i = 0; i < width * height * 4; i += 4)
	{
		unsigned int r = image[i];
		unsigned int g = image[i + 1];
		unsigned int b = image[i + 2];

		// If its a red pixel - make it black
		if ((r == 255) & (g == 0) & (b == 0))
		{
			image[i] = 0;
		}
	}

	writePng("AfterExpandBLACK.jpg", image, width, height);
}
static void chopBothWays(const SkDConic& dConic, double t, const char* name) {
    SkConic conic;
    for (int index = 0; index < 3; ++index) {
        conic.fPts[index] = dConic.fPts[index].asSkPoint();
    }
    conic.fW = dConic.fWeight;
    SkConic chopped[2];
    SkDConic dChopped[2];
    conic.chopAt(SkDoubleToScalar(t), chopped);
    dChopped[0] = dConic.subDivide(0, t);
    dChopped[1] = dConic.subDivide(t, 1);
#if DEBUG_VISUALIZE_CONICS
    dConic.dump();
#endif
    chopCompare(chopped, dChopped);
#if DEBUG_VISUALIZE_CONICS
    writePng(conic, chopped, name);
#endif
}
Beispiel #8
0
Bytes Bitmap::writePng(const uint8_t *data, uint32_t width, uint32_t height, Format format, bool invert) {
	return writePng(data, width, height, 0, format, invert);
}
static Bool
pngImageToFile (CompDisplay *d,
		const char  *path,
		const char  *name,
		const char  *format,
		int	    width,
		int	    height,
		int	    stride,
		void	    *data)
{
    Bool status = FALSE;
    char *extension = pngExtension (name);
    char *file;
    FILE *fp;
    int  len;

    PNG_DISPLAY (d);

    len = (path ? strlen (path) : 0) + strlen (name) + strlen (extension) + 2;

    file = malloc (len);
    if (file)
    {
	if (path)
	    sprintf (file, "%s/%s%s", path, name, extension);
	else
	    sprintf (file, "%s%s", name, extension);
    }

    if (file && strcasecmp (format, "png") == 0)
    {
	fp = fopen (file, "wb");
	if (fp)
	{
	    status = writePng (data, stdioWriteFunc, fp, width, height, stride);
	    fclose (fp);
	}

	if (status)
	{
	    free (file);
	    return TRUE;
	}
    }

    UNWRAP (pd, d, imageToFile);
    status = (*d->imageToFile) (d, path, name, format, width, height, stride,
				data);
    WRAP (pd, d, imageToFile, pngImageToFile);

    if (!status && file)
    {
	fp = fopen (file, "wb");
	if (fp)
	{
	    status = writePng (data, stdioWriteFunc, fp, width, height, stride);
	    fclose (fp);
	}
    }

    if (file)
	free (file);

    return status;
}
Beispiel #10
0
void Map::convertToGrid()
{
	// Define variables.
	double MapResolutionCM = 2.5;
	double GridResolutionCM = 10;
	double GridResolutionPixels = GridResolutionCM / MapResolutionCM; // 4 pixels
	std::vector<unsigned char> newImage(((int)((width * height * 4) / GridResolutionPixels)));
	bool foundBlack;
	unsigned int newLocation;
	unsigned int newRow;
	unsigned int newCol;
	unsigned int location;
	gridWidth = (width - 2)/4;
	gridHeight = height/ 4;

	// Going on the given map rows.
	for (int row = 0; row < height * width * 4; row += width * GridResolutionPixels * 4)
	{
		// Going on the given map columns.
		for (int col = 0; col < (width - 2) * 4; col += GridResolutionPixels *4)
		{
			// Calculating the current cell (location).
			location = row + col;

			foundBlack = false;

			// Going on the square which will be equal to one cell on the Grid Map.
			// Going on the rows.
			for (int y = 0; y < GridResolutionPixels; y++)
			{
				// Going on the columns.
				for (int x = 0; x < GridResolutionPixels; x++)
				{
					// Calculating how many cells we should skip in order to get to the cell.
					int shifting = location + (x + (y * width)) * 4;
					unsigned int r = image[shifting];
					unsigned int g = image[shifting + 1];
					unsigned int b = image[shifting + 2];

					// It's enough to find one black pixel on the current square,
					// in order to set the whole cell as black on the Grid Map.
					if (r == 0 && g == 0 && b == 0)
					{
						foundBlack = true;
					}
				}
			}

			// Calculating the current row,column and cell eventually on the Grid.
			newRow = (row / (int)(width * GridResolutionPixels * 4)) *
						((width-2)/GridResolutionPixels) * 4;
			newCol = (col / GridResolutionPixels);
			newLocation = newRow + newCol;

			// Paint the cell.
			if (foundBlack)
			{
				newImage[newLocation] = 0;
				newImage[newLocation + 1] = 0;
				newImage[newLocation + 2] = 0;
				newImage[newLocation + 3] = 255;
			}
			else
			{
				newImage[newLocation] = 255;
				newImage[newLocation + 1] = 255;
				newImage[newLocation + 2] = 255;
				newImage[newLocation + 3] = 255;
			}
		}
	}

	grid = newImage;
	writePng("galvemoris.png", newImage, width / GridResolutionPixels, height / GridResolutionPixels);
}
Beispiel #11
0
/******************************************************************************
 * Render the current scene
 * uses the global variables from the parser
 *****************************************************************************/
int ntlWorld::renderScene( void )
{
#ifndef ELBEEM_PLUGIN
	char nrStr[5];														// nr conversion 
	std::ostringstream outfn_conv("");  			// converted ppm with other suffix 
  ntlRenderGlobals *glob;                  	// storage for global rendering parameters 
  myTime_t timeStart,totalStart,timeEnd; 		// measure user running time 
  myTime_t rendStart,rendEnd;            		// measure user rendering time 
  glob = mpGlob;

	// deactivate for all with index!=0 
	if((glob_mpactive)&&(glob_mpindex>0)) return(0);

	/* check if picture already exists... */
	if(!glob->getSingleFrameMode() ) {
		snprintf(nrStr, 5, "%04d", glob->getAniCount() );

		if(glob_mpactive) {
			outfn_conv  << glob->getOutFilename() <<"_"<<glob_mpindex<<"_" << nrStr << ".png"; /// DEBUG!
		} else {
			// ORG
			outfn_conv  << glob->getOutFilename() <<"_" << nrStr << ".png";
		}
		
		//if((mpGlob->getDisplayMode() == DM_RAY)&&(mpGlob->getFrameSkip())) {
		if(mpGlob->getFrameSkip()) {
			struct stat statBuf;
			if(stat(outfn_conv.str().c_str(),&statBuf) == 0) {
				errorOut("ntlWorld::renderscene Warning: file "<<outfn_conv.str()<<" already exists - skipping frame..."); 
				glob->setAniCount( glob->getAniCount() +1 );
				return(2);
			}
		} // RAY mode
	} else {
		// single frame rendering, overwrite if necessary...
		outfn_conv << glob->getSingleFrameFilename();
	}

  /* start program */
	timeStart = getTime();

	/* build scene geometry, calls buildScene(t,false) */
	glob->getRenderScene()->prepareScene(mSimulationTime);

  /* start program */
	totalStart = getTime();


	/* view parameters are currently not animated */
	/* calculate rays through projection plane */
	ntlVec3Gfx direction = glob->getLookat() - glob->getEye();
	/* calculate width of screen using perpendicular triangle diven by
	 * viewing direction and screen plane */
	gfxReal screenWidth = norm(direction)*tan( (glob->getFovy()*0.5/180.0)*M_PI );

	/* calculate vector orthogonal to up and viewing direction */
	ntlVec3Gfx upVec = glob->getUpVec();
	ntlVec3Gfx rightVec( cross(upVec,direction) );
	normalize(rightVec);

	/* calculate screen plane up vector, perpendicular to viewdir and right vec */
	upVec = ntlVec3Gfx( cross(rightVec,direction) );
	normalize(upVec);

	/* check if vectors are valid */
	if( (equal(upVec,ntlVec3Gfx(0.0))) || (equal(rightVec,ntlVec3Gfx(0.0))) ) {
		errMsg("ntlWorld::renderScene","Invalid viewpoint vectors! up="<<upVec<<" right="<<rightVec);
		return(1);
	}

	/* length from center to border of screen plane */
	rightVec *= (screenWidth*glob->getAspect() * -1.0);
	upVec *= (screenWidth * -1.0);

	/* screen traversal variables */
	ntlVec3Gfx screenPos;                          /* current position on virtual screen */
	int Xres = glob->getResX();                  /* X resolution */
	int Yres = glob->getResY();                  /* Y resolution */
	ntlVec3Gfx rightStep = (rightVec/(Xres/2.0));  /* one step right for a pixel */
	ntlVec3Gfx upStep    = (upVec/(Yres/2.0));     /* one step up for a pixel */
    

	/* anti alias init */
	char  showAAPic = 0;
	int   aaDepth = glob->getAADepth();
	int   aaLength;
	if(aaDepth>=0) aaLength = (2<<aaDepth);
	else           aaLength = 0;
	float aaSensRed   = 0.1;
	float aaSensGreen = 0.1;
	float aaSensBlue  = 0.1;
	int   aaArrayX = aaLength*Xres+1;
	int   aaArrayY = ( aaLength+1 );
	ntlColor *aaCol = new ntlColor[ aaArrayX*aaArrayY ];
	char  *aaUse = new char[ aaArrayX*aaArrayY ];

	/* picture storage */
	int picX = Xres;
	int picY = Yres;
	if(showAAPic) {
		picX = Xres *aaLength+1;
		picY = Yres *aaLength+1;
	}
	ntlColor *finalPic = new ntlColor[picX * picY];


	/* reset picture vars */
	for(int j=0;j<aaArrayY;j++) {
		for(int i=0;i<aaArrayX;i++) {
			aaCol[j*aaArrayX+i] = ntlColor(0.0, 0.0, 0.0);
			aaUse[j*aaArrayX+i] = 0;
		}
	}
	for(int j=0;j<picY;j++) {
		for(int i=0;i<picX;i++) {
			finalPic[j*picX+i] = ntlColor(0.0, 0.0, 0.0);
		}
	}

	/* loop over all y lines in screen, from bottom to top because
	 * ppm format wants 0,0 top left */
	rendStart = getTime();
	glob->setCounterShades(0);
	glob->setCounterSceneInter(0);
	for (int scanline=Yres ; scanline > 0 ; --scanline) {
    
		debugOutInter( "ntlWorld::renderScene: Line "<<scanline<<
								 " ("<< ((Yres-scanline)*100/Yres) <<"%) ", 2, 2000 );
		screenPos = glob->getLookat() + upVec*((2.0*scanline-Yres)/Yres)
			- rightVec;

		/* loop over all pixels in line */
		for (int sx=0 ; sx < Xres ; ++sx) {

			if((sx==glob->getDebugPixelX())&&(scanline==(Yres-glob->getDebugPixelY()) )) {
				// DEBUG!!!
				glob->setDebugOut(10);
			} else glob->setDebugOut(0);
			
			/* compute ray from eye through current pixel into scene... */
			ntlColor col;
			if(aaDepth<0) {
				ntlVec3Gfx dir(screenPos - glob->getEye());
				ntlRay the_ray(glob->getEye(), getNormalized(dir), 0, 1.0, glob );

				/* ...and trace it */
				col = the_ray.shade();
			} else {
				/* anti alias */
				int ai,aj;                   /* position in grid */
				int aOrg = sx*aaLength;      /* grid offset x */
				int currStep = aaLength;     /* step size */
				char colDiff = 1;            /* do colors still differ too much? */
				ntlColor minCol,maxCol;         /* minimum and maximum Color Values */
				minCol = ntlColor(1.0,1.0,1.0);
				maxCol = ntlColor(0.0,0.0,0.0);

				while((colDiff) && (currStep>0)) {
					colDiff = 0;
	    
					for(aj = 0;aj<=aaLength;aj+= currStep) {
						for(ai = 0;ai<=aaLength;ai+= currStep) {

							/* shade pixel if not done */
							if(aaUse[aj*aaArrayX +ai +aOrg] == 0) {
								aaUse[aj*aaArrayX +ai +aOrg] = 1;
								ntlVec3Gfx aaPos( screenPos +
																(rightStep * (ai- aaLength/2)/(gfxReal)aaLength ) +
																(upStep    * (aj- aaLength/2)/(gfxReal)aaLength ) );

								ntlVec3Gfx dir(aaPos - glob->getEye());
								ntlRay the_ray(glob->getEye(), getNormalized(dir), 0, 1.0, glob );

								/* ...and trace it */
								ntlColor newCol= the_ray.shade();
								aaCol[aj*aaArrayX +ai +aOrg]= newCol;
							} /* not used? */

						}
					}

					/* check color differences */
					for(aj = 0;aj<aaLength;aj+= currStep) {
						for(ai = 0;ai<aaLength;ai+= currStep) {

							char thisColDiff = 0;
							if( 
								 (fabs(aaCol[aj*aaArrayX +ai +aOrg][0] - 
											 aaCol[(aj+0)*aaArrayX +(ai+currStep) +aOrg][0])> aaSensRed ) ||
								 (fabs(aaCol[aj*aaArrayX +ai +aOrg][1] - 
											 aaCol[(aj+0)*aaArrayX +(ai+currStep) +aOrg][1])> aaSensGreen ) ||
								 (fabs(aaCol[aj*aaArrayX +ai +aOrg][2] - 
											 aaCol[(aj+0)*aaArrayX +(ai+currStep) +aOrg][2])> aaSensBlue ) ) {
								thisColDiff = 1;
							} else
								if( 
									 (fabs(aaCol[aj*aaArrayX +ai +aOrg][0] - 
												 aaCol[(aj+currStep)*aaArrayX +(ai+0) +aOrg][0])> aaSensRed ) ||
									 (fabs(aaCol[aj*aaArrayX +ai +aOrg][1] - 
												 aaCol[(aj+currStep)*aaArrayX +(ai+0) +aOrg][1])> aaSensGreen ) ||
									 (fabs(aaCol[aj*aaArrayX +ai +aOrg][2] - 
												 aaCol[(aj+currStep)*aaArrayX +(ai+0) +aOrg][2])> aaSensBlue ) ) {
									thisColDiff = 1;
								} else
									if( 
										 (fabs(aaCol[aj*aaArrayX +ai +aOrg][0] - 
													 aaCol[(aj+currStep)*aaArrayX +(ai+currStep) +aOrg][0])> aaSensRed ) ||
										 (fabs(aaCol[aj*aaArrayX +ai +aOrg][1] - 
													 aaCol[(aj+currStep)*aaArrayX +(ai+currStep) +aOrg][1])> aaSensGreen ) ||
										 (fabs(aaCol[aj*aaArrayX +ai +aOrg][2] - 
													 aaCol[(aj+currStep)*aaArrayX +(ai+currStep) +aOrg][2])> aaSensBlue ) ) {
										thisColDiff = 1;
									} 

							//colDiff =1;
							if(thisColDiff) {
								/* set diff flag */
								colDiff = thisColDiff;
								for(int bj=aj;bj<=aj+currStep;bj++) {
									for(int bi=ai;bi<=ai+currStep;bi++) {
										if(aaUse[bj*aaArrayX +bi +aOrg]==2) {
											//if(showAAPic) 
											aaUse[bj*aaArrayX +bi +aOrg] = 0;
										}
									}
								}
							} else {
								/* set all values */
								ntlColor avgCol = (
																	 aaCol[(aj+0       )*aaArrayX +(ai+0       ) +aOrg] +
																	 aaCol[(aj+0       )*aaArrayX +(ai+currStep) +aOrg] +
																	 aaCol[(aj+currStep)*aaArrayX +(ai+0       ) +aOrg] +
																	 aaCol[(aj+currStep)*aaArrayX +(ai+currStep) +aOrg] ) *0.25;
								for(int bj=aj;bj<=aj+currStep;bj++) {
									for(int bi=ai;bi<=ai+currStep;bi++) {
										if(aaUse[bj*aaArrayX +bi +aOrg]==0) {
											aaCol[bj*aaArrayX +bi +aOrg] = avgCol; 
											aaUse[bj*aaArrayX +bi +aOrg] = 2;
										}
									}
								}
							} /* smaller values set */

						}
					}

					/* half step size */
					currStep /= 2;

				} /* repeat until diff not too big */

				/* get average color */
				gfxReal colNum = 0.0;
				col = ntlColor(0.0, 0.0, 0.0);
				for(aj = 0;aj<=aaLength;aj++) {
					for(ai = 0;ai<=aaLength;ai++) {
						col += aaCol[aj*aaArrayX +ai +aOrg];
						colNum += 1.0;
					}
				}
				col /= colNum;

			}

		  /* mark pixels with debugging */
			if( glob->getDebugOut() > 0) col = ntlColor(0,1,0);

			/* store pixel */
			if(!showAAPic) {
				finalPic[(scanline-1)*picX+sx] = col; 
			}
			screenPos +=  rightStep;

		} /* foreach x */

		/* init aa array */
		if(showAAPic) {
			for(int j=0;j<=aaArrayY-1;j++) {
				for(int i=0;i<=aaArrayX-1;i++) {
					if(aaUse[j*aaArrayX +i]==1) finalPic[((scanline-1)*aaLength +j)*picX+i][0] = 1.0;
				}
			}
		}

		for(int i=0;i<aaArrayX;i++) {
			aaCol[(aaArrayY-1)*aaArrayX+i] = aaCol[0*aaArrayX+i];
			aaUse[(aaArrayY-1)*aaArrayX+i] = aaUse[0*aaArrayX+i];
		}
		for(int j=0;j<aaArrayY-1;j++) {
			for(int i=0;i<aaArrayX;i++) {
				aaCol[j*aaArrayX+i] = ntlColor(0.0, 0.0, 0.0);
				aaUse[j*aaArrayX+i] = 0;
			}
		}

	} /* foreach y */
	rendEnd = getTime();


	/* write png file */
	{
		int w = picX;
		int h = picY;

		unsigned rowbytes = w*4;
		unsigned char *screenbuf, **rows;
		screenbuf = (unsigned char*)malloc( h*rowbytes );
		rows = (unsigned char**)malloc( h*sizeof(unsigned char*) );
		unsigned char *filler = screenbuf;

		// cutoff color values 0..1
		for(int j=0;j<h;j++) {
			for(int i=0;i<w;i++) {
				ntlColor col = finalPic[j*w+i];
				for (unsigned int cc=0; cc<3; cc++) {
					if(col[cc] <= 0.0) col[cc] = 0.0;
					if(col[cc] >= 1.0) col[cc] = 1.0;
				}
				*filler = (unsigned char)( col[0]*255.0 ); 
				filler++;
				*filler = (unsigned char)( col[1]*255.0 ); 
				filler++;
				*filler = (unsigned char)( col[2]*255.0 ); 
				filler++;
				*filler = (unsigned char)( 255.0 ); 
				filler++; // alpha channel
			}
		}

		for(int i = 0; i < h; i++) rows[i] = &screenbuf[ (h - i - 1)*rowbytes ];
		writePng(outfn_conv.str().c_str(), rows, w, h);
	}


	// next frame 
	glob->setAniCount( glob->getAniCount() +1 );

	// done 
	timeEnd = getTime();

	char resout[1024];
	snprintf(resout,1024, "NTL Done %s, frame %d/%d (took %s scene, %s raytracing, %s total, %d shades, %d i.s.'s)!\n", 
				 outfn_conv.str().c_str(), (glob->getAniCount()), (glob->getAniFrames()+1),
				 getTimeString(totalStart-timeStart).c_str(), getTimeString(rendEnd-rendStart).c_str(), getTimeString(timeEnd-timeStart).c_str(),
				 glob->getCounterShades(),
				 glob->getCounterSceneInter() );
	debMsgStd("ntlWorld::renderScene",DM_MSG, resout, 1 );

	/* clean stuff up */
	delete [] aaCol;
	delete [] aaUse;
	delete [] finalPic;
	glob->getRenderScene()->cleanupScene();

	if(mpGlob->getSingleFrameMode() ) {
		debMsgStd("ntlWorld::renderScene",DM_NOTIFY, "Single frame mode done...", 1 );
		return 1;
	}
#endif // ELBEEM_PLUGIN
	return 0;
}
Beispiel #12
0
int main(int argc, char *argv[]){
  KGString *tmp1, *tmp2, *test1, *test2, *filename;
  FILE *err;
  char errbuf[errorFileSize];
  char *pos, *cur;
  int dummy;
  int type;
  
  dummy = initDB();
  
  //set default
  kShotai = kMincho;
  //kShotai = kGothic;
  kSize = 200;
  kType = 0; //png
  kInput = 0; //ids or direct
  kResultText = kg_string_new("");
  kMode = 0;
  
  //confirm request
  type = 0;
  //GET request
  if(type == 0){
    tmp1 = kg_string_new((kgchar *)getenv("QUERY_STRING"));
    if(tmp1->len != 0) type = 2;
  }
  //argv(detect after GET request)
  if(type == 0){
    tmp1 = kg_string_new((kgchar *)argv[1]);
    if(tmp1->len != 0) type = 1;
  }
  //redirect
  if(type == 0){
    tmp1 = kg_string_new((kgchar *)getenv("REDIRECT_URL"));
    if(tmp1->len != 0) type = 3;
  }
  //error
  if(type == 0){
    fprintf(stderr, "Request Error.\n");
    return 0;
  }
  pos = tmp1->str;
  
  //separate token
  if(type == 1 || type == 2){ //argv or GET request
    while(1){
      cur = strchr(pos, '&');
      tmp2 = kg_string_new(pos);
      if(cur != NULL) kg_string_set_size(tmp2, cur - pos);
      //got request string
      if(strncmp(tmp2->str, "shotai=mincho", 13) == 0) kShotai = kMincho;
      else if(strncmp(tmp2->str, "shotai=gothic", 13) == 0) kShotai = kGothic;
      else if(strncmp(tmp2->str, "shotai=skeleton", 15) == 0) kShotai = kGothic;
      else if(strncmp(tmp2->str, "type=png", 8) == 0) kType = 0;
      else if(strncmp(tmp2->str, "type=svg", 8) == 0) kType = 1;
      else if(strncmp(tmp2->str, "type=eps", 8) == 0) kType = 2;
      else if(strncmp(tmp2->str, "type=raw", 8) == 0) kType = 3;
      else if(strncmp(tmp2->str, "input=ids", 9) == 0) kInput = 0;
      else if(strncmp(tmp2->str, "input=directwithadjust", 22) == 0) kInput = 2;
      else if(strncmp(tmp2->str, "input=direct", 12) == 0) kInput = 1;
      else if(strncmp(tmp2->str, "size=24", 7) == 0) kSize = 24;
      else if(strncmp(tmp2->str, "size=200", 8) == 0) kSize = 200;
      else test1 = kg_string_new(tmp2->str);
      if(cur == NULL) break;
      pos = cur + 1;
    }
  }
  else{ // redirected request
    kInput = 0;
    while(1){
      cur = strchr(pos, '/');
      tmp2 = kg_string_new(pos);
      if(cur != NULL) kg_string_set_size(tmp2, cur - pos);
      //got request string
      if(strncmp(tmp2->str, "mincho", 6) == 0) kShotai = kMincho;
      else if(strncmp(tmp2->str, "gothic", 6) == 0) kShotai = kGothic;
      else if(strncmp(tmp2->str, "skeleton", 8) == 0) kShotai = kGothic;
      else if(strncmp(tmp2->str, "v0.4", 4) == 0);
      else test1 = kg_string_new(tmp2->str);
      if(cur == NULL) break;
      pos = cur + 1;
    }
    if(strncmp(test1->str + test1->len - 4, ".png", 4) == 0) kType = 0;
    if(strncmp(test1->str + test1->len - 4, ".svg", 4) == 0) kType = 1;
    if(strncmp(test1->str + test1->len - 4, ".eps", 4) == 0) kType = 2;
    if(strncmp(test1->str + test1->len - 4, ".raw", 4) == 0) kType = 3;
    kg_string_set_size(test1, test1->len - 4);
  }
  
  //clear result buffer
  test2 = kg_string_new("");
  if(kType == 1){ //svg
    kg_string_append(kResultText, "<?xml version=\"1.0\"?>\n");
    kg_string_append(kResultText, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n");
    kg_string_append(kResultText, "<svg width=\"1024\" height=\"1024\" viewBox=\"0 0 1024 1024\">");
    kg_string_append(kResultText, "<g style=\"fill: black; stroke: black\">");
  }
  else if(kType == 2){ //eps
    kg_string_append(kResultText, "%!PS-Adobe-3.0 EPSF-3.0\n");
    kg_string_append(kResultText, "%%BoundingBox: 0 -208 1024 816\n");
    kg_string_append(kResultText, "%%Pages: 0\n");
    kg_string_append(kResultText, "%%Title: ");
    kg_string_append(kResultText, test1->str);
    kg_string_append(kResultText, "\n");
    kg_string_append(kResultText, "%%Creator: KAGE System\n");
    kg_string_append(kResultText, "%%CreationDate: 00:00 1-1-2004\n");
    kg_string_append(kResultText, "%%EndComments\n");
    kg_string_append(kResultText, "%%EndProlog\n");
    kg_string_append(kResultText, "%%Page \"");
    kg_string_append(kResultText, test1->str);
    kg_string_append(kResultText, "\" 1\n");
    kg_string_append(kResultText, "newpath\n");
  }
  kageCanvas = initPng(canvasWidth, canvasHeight);
  if(kInput == 0) generateGlyph(test1, test2);
  else{
    convert99(test1, test2);
    //	  kg_string_append(test2, test1->str);
  }
  
  if(test2->len != 0) test2 = finalAdjustment(test2);
  
  if(kType == 0){ //png(image)
    if(test2->len != 0){
      if(kInput != 1){ //0 and 2
	test2 = CalcSizes(test2, 1);
      }
      DrawBox();
      drawGlyph(test2, DRAW_GLYPH_MODE_NORMAL);
      //output to file
      filename = kg_string_new(pngFilePath);
      if(kShotai == kMincho) kg_string_append(filename, "mincho/");
      else if(kShotai == kGothic) kg_string_append(filename, "gothic/");//skeleton??
      kg_string_append(filename, test1->str);
      kg_string_append(filename, ".png");
      
      //skip for adjustment mode
      //fp = fopen(filename->str, "w");
      //writePng(pngWidth, pngHeight, kageCanvas, fp);
      //fclose(fp);
      //output to stdout
      if(type != 1) fprintf(stdout, "Content-type: image/png\n\n");
      writePng(pngWidth, pngHeight, kageCanvas, stdout);
      //done
      closePng(pngWidth, pngHeight, kageCanvas);
    }
    else{
      err = fopen(errorFileName, "r");
      fread(errbuf, sizeof(char), errorFileSize, err);
      //printf("An error occurred.\r\n");
      if(type != 1) fprintf(stdout, "Content-type: image/png\n\n");
      fwrite(errbuf, sizeof(char), errorFileSize, stdout);
      fclose(err);
    }
  }
  else if(kType == 1){ //svg(vector graphics)
    if(test2->len != 0){
      test2 = CalcSizes(test2, 1);
      kMode = 1;
      drawGlyph(test2, DRAW_GLYPH_MODE_NORMAL);
      kg_string_append(kResultText, "</g></svg>\n");
      if(type != 1) fprintf(stdout, "Content-type: image/svg-xml\n\n");
      fprintf(stdout, "%s", kResultText->str);
    }
    else{
      if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n");
      fprintf(stdout, "An error occurred.");
    }
  }
  else if(kType == 2){ //eps(vector graphics)
    if(test2->len != 0){
      test2 = CalcSizes(test2, 1);
      kMode = 2;
      drawGlyph(test2, DRAW_GLYPH_MODE_NORMAL);
      kg_string_append(kResultText, "fill\n");
      kg_string_append(kResultText, "%%EOF\n");
      if(type != 1) fprintf(stdout, "Content-type: application/postscript\n\n");
      fprintf(stdout, "%s", kResultText->str);
    }
    else{
      if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n");
      fprintf(stdout, "An error occurred.");
    }
  }
  else{ //raw(text)
    
    if(test2->len != 0){
      test2 = CalcSizes(test2, 1);
      if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n");
      fprintf(stdout, "result=%s", test2->str);
    }
    else{
      if(type != 1) fprintf(stdout, "Content-type: text/plain\n\n");
      fprintf(stdout, "result=nodata");
    }
  }
  dummy = closeDB();
  
  return 0;
}
Beispiel #13
0
int main( int argc, char ** argv) {
   //Source * s = new FileSource("color/illuminants/CIE-D65.txt");
   Source * s = new FileSource("color/illuminants/CIE-C.txt");
   //Source * s = new FileSource("color/illuminants/CIE-A-1nm.txt");
   //Source * s = new WhiteSource();

   fRGB rgb = s->tofRGB();
   fRGB rgbmax(0.0, 0.0, 0.0);
   printf("->RGB %f %f %f\n", rgb.r, rgb.g, rgb.b);

   World * world = new World(20, 20, 20);

   Film * f = new Film();
   Index * i1 = new FixedIndex(1.3);
   Index * i2 = new FixedIndex(1.5);
   /*
   f->addLayer(Layer(50.0, i1));
   f->addLayer(Layer(100.0, i2));
   f->addLayer(Layer(50.0, i1));
   */
   /*
   f->addLayer(Layer(250/1.5, i2));
   */
   f = new FakeFilm();

   world->light(s);

   Sphere * o = new Sphere(Point(10,10,10), 3);
   o->setFilm(f);
   o->addToWorld(world);
   
   o = new Sphere(Point(14, 15, 14), 2);
   o->addToWorld(world);
   
   o = new Sphere(Point(6, 15, 6), 2);
   o->addToWorld(world);

   FILE * out = fopen("out.png", "wb");

   // width, height and image buffer
   int w = 100; // do not make this 10
   if( argc > 1 ) sscanf(argv[1], "%d", &w);
   int h = w;
   fRGB * f_image = (fRGB*)malloc(sizeof(fRGB)*w*h);
   char * image = (char*)malloc(sizeof(char)*w*h*3);
   if( !image || !f_image ) {
      perror("malloc failed");
      return -1;
   }
   for( int y=0; y<h; y++ ) {
      printf("Rendering row %d\n", y);
      for( int x=0; x<w; x++ ) {
         //printf("Rendering (%d, %d)\n", x, y);
         // generate ray to cast
         //  depth here determines field-of-view
         Ray r(Point(10, 0, 10), Point(x - w/2, (w+h)/2, y - h/2));

         // cast ray and get rendered value
         rgb = world->trace(&r);
         rgbmax = max(rgbmax, rgb);
         f_image[y*w + x] = rgb;
      }
   }

   for( int y=0; y<h; y++ ) {
      for( int x=0; x<w; x++ ) {
         rgb = f_image[y*w + x];
         // place RGB value into output image
         int k = (y*w + x)*3;
         image[k + 0] = 255 * (rgb.r / rgbmax.r); // R
         image[k + 1] = 255 * (rgb.g / rgbmax.g); // G
         image[k + 2] = 255 * (rgb.b / rgbmax.b); // B
      }
   }

   writePng(out, w, h, image);
   fclose(out);
   free(image);

   return 0;
}