Esempio n. 1
0
/**
 * WriteImage(): Write an image.
 * @param filename Filename to write to.
 * @param format Image format.
 * @param w Width of the image.
 * @param h Height of the image.
 * @param pitch Pitch of the image. (measured in pixels)
 * @param screen Pointer to screen buffer.
 * @param bpp Bits per pixel.
 * @param alpha Alpha channel specification. (32-bit color only.)
 * @return 0 on success; non-zero on error.
 */
int ImageUtil::WriteImage(const char* filename, const ImageFormat format,
			  const int w, const int h, const int pitch,
			  const void *screen, const int bpp, const AlphaChannel alpha)
{
	if (!filename)
		return 1;
	
	// Write an image file.
	FILE *fImg = fopen(filename, "wb");
	if (!fImg)
	{
		LOG_MSG(gens, LOG_MSG_LEVEL_CRITICAL,
			"Error opening %s.", filename);
		return 2;
	}
	
	int rval;
#ifdef GENS_PNG
	if (format == IMAGEFORMAT_PNG)
	{
		rval = WritePNG(fImg, w, h, pitch, screen, bpp, alpha);
	}
	else
#endif /* GENS_PNG */
	{
		rval = WriteBMP(fImg, w, h, pitch, screen, bpp);
	}
	
	fclose(fImg);
	return rval;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
  int row, col, depth, width, maxdepth;
  double cx, cy, dx, dy, x, y, x2, y2;
  unsigned char *cnt;
  struct timeval start, end;

  printf("Fractal v1.3 [serial]\n");

  // check command line
  if (argc != 3) {fprintf(stderr, "usage: %s edge_length max_depth\n", argv[0]); exit(-1);}
  width = atoi(argv[1]);
  if (width < 10) {fprintf(stderr, "edge_length must be at least 10\n"); exit(-1);}
  maxdepth = atoi(argv[2]);
  if (maxdepth < 10) {fprintf(stderr, "max_depth must be at least 10\n"); exit(-1);}

  printf("computing %d by %d fractal with a maximum depth of %d\n", width, width, maxdepth);

  // allocate array
  cnt = (unsigned char *)malloc(width * width * sizeof(unsigned char));
  if (cnt == NULL) {fprintf(stderr, "could not allocate memory\n"); exit(-1);}

  // start time
  gettimeofday(&start, NULL);

  // compute fractal
  dx = (xMax - xMin) / width;
  dy = (yMax - yMin) / width;
  for (row = 0; row < width; row++) {
    cy = yMin + row * dy;
    for (col = 0; col < width; col++) {
      cx = xMin + col * dx;
      x = -cx;
      y = -cy;
      depth = maxdepth;
      do {
        x2 = x * x;
        y2 = y * y;
        y = 2 * x * y - cy;
        x = x2 - y2 - cx;
        depth--;
      } while ((depth > 0) && ((x2 + y2) <= 5.0));
      cnt[row * width + col] = depth & 255;
    }
  }

  // end time
  gettimeofday(&end, NULL);
  double runtime = end.tv_sec + end.tv_usec / 1000000.0 - start.tv_sec - start.tv_usec / 1000000.0;
  printf("compute time: %.4f s\n", runtime);

  // verify result by writing it to a file
  if (width <= 1024) {
    WriteBMP(width, width, cnt, "fractal.bmp");
  }

  free(cnt);
  return 0;
}
Esempio n. 3
0
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	
	//
	glReadPixels(0, 0, 500, 500,GL_BGR_EXT, GL_UNSIGNED_BYTE, PixelData);
	WriteBMP(PixelData,"test.bmp",500,500);
	//
	glutSwapBuffers();
	//xrot = xrot + 1;
	yrot = yrot + 1;
	//zrot = zrot + 1;
	//Sleep(100);
}
Esempio n. 4
0
File: azura.cpp Progetto: kyuu/azura
    //--------------------------------------------------------------
    bool WriteImage(Image* image, File* file, FileFormat::Enum ff)
    {
        if (!image || !file) {
            return false;
        }

        switch (ff) {
            case FileFormat::BMP:
                return WriteBMP(image, file);
            case FileFormat::PNG:
                return WritePNG(image, file);
            case FileFormat::JPEG:
                return WriteJPEG(image, file);
            default:
                return false;
        }
    }
Esempio n. 5
0
//==================================================================================
//==================================================================================
geBoolean DRIVERCC GMain_ScreenShot(const char *Name)
{
	uint16		*Buffer;
	
	Buffer = (uint16*)malloc(sizeof(uint16*)*ClientWindow.Width*ClientWindow.Height);
	
	if (!grLfbReadRegion(GR_BUFFER_FRONTBUFFER,0,0,ClientWindow.Width,ClientWindow.Height,
		ClientWindow.Width*2, (void*)Buffer))
	{
		SetLastDrvError(DRV_ERROR_GENERIC, "GLIDE: Could not save BMP.");
		return FALSE;
	}
	
	WriteBMP(Buffer, Name, ClientWindow.Width, ClientWindow.Height);

	free(Buffer);

	return GE_TRUE;
}
Esempio n. 6
0
int R2Image::
Write(const char *filename) const
{
  // Parse input filename extension
  char *input_extension;
  if (!(input_extension = (char*)strrchr(filename, '.'))) {
    fprintf(stderr, "Input file has no extension (e.g., .jpg).\n");
    return 0;
  }
  
  // Write file of appropriate type
  if (!strncmp(input_extension, ".bmp", 4)) return WriteBMP(filename);
  else if (!strncmp(input_extension, ".ppm", 4)) return WritePPM(filename, 1);
  else if (!strncmp(input_extension, ".jpg", 5)) return WriteJPEG(filename);
  else if (!strncmp(input_extension, ".jpeg", 5)) return WriteJPEG(filename);

  // Should never get here
  fprintf(stderr, "Unrecognized image file extension");
  return 0;
}
Esempio n. 7
0
static void Printscreen()
{
	WriteBMP("./test.bmp",GPU_screen);
}
Esempio n. 8
0
void  on_menu_pscreen_activate (GtkMenuItem *menuitem, gpointer user_data) {  WriteBMP("./test.bmp",(u16*)GPU_screen); }
int main()
{
	unsigned char img[w*h*3];
	for(int i=0;i<w*h*3;i++)img[i]=rand()%256;
	WriteBMP(img,"test.bmp");
}
Esempio n. 10
0
void CImage::WriteBMP (const char *dir, const char *filename) {
    string path = dir;
    path += SEP;
    path += filename;
    WriteBMP (path.c_str());
}