Пример #1
0
    //--------------------------------------------------------------
    Image::Ptr ReadImage(File* file, FileFormat::Enum ff, PixelFormat::Enum pf)
    {
        if (!file || (pf != PixelFormat::DontCare && pf < 0)) {
            return 0;
        }

        Image::Ptr image;

        switch (ff)
        {
            case FileFormat::BMP:
            {
                image = ReadBMP(file);
                break;
            }
            case FileFormat::PNG:
            {
                image = ReadPNG(file);
                break;
            }
            case FileFormat::JPEG:
            {
                image = ReadJPEG(file);
                break;
            }
            case FileFormat::AutoDetect:
            {
                int initial_pos = file->tell();

                // try reading as BMP
                image = ReadBMP(file);
                if (image) {
                    break;
                }

                file->seek(initial_pos);

                // try reading as PNG
                image = ReadPNG(file);
                if (image) {
                    break;
                }

                file->seek(initial_pos);

                // try reading as JPEG
                image = ReadJPEG(file);

                break;
            }
            default:
                return 0;
        }

        if (image && pf != PixelFormat::DontCare && image->getPixelFormat() != pf) {
            image = image->convert(pf);
        }

        return image;
    }
Пример #2
0
int R2Image::
Read(const char *filename)
{
  // Initialize everything
  if (pixels) { delete [] pixels; pixels = NULL; }
  width = height = 0;

  // Parse input filename extension
  const char *input_extension;
  if (!(input_extension = strrchr(filename, '.'))) {
    fprintf(stderr, "Input file has no extension (e.g., .jpg).\n");
    return 0;
  }
  
  // Read file of appropriate type
  if (!strncmp(input_extension, ".bmp", 4)) return ReadBMP(filename);
  else if (!strncmp(input_extension, ".ppm", 4)) return ReadPPM(filename);
  else if (!strncmp(input_extension, ".pfm", 4)) return ReadPFM(filename);
  else if (!strncmp(input_extension, ".jpg", 4)) return ReadJPEG(filename);
  else if (!strncmp(input_extension, ".jpeg", 5)) return ReadJPEG(filename);
  else if (!strncmp(input_extension, ".tif", 4)) return ReadTIFF(filename);
  else if (!strncmp(input_extension, ".tiff", 5)) return ReadTIFF(filename);
  else if (!strncmp(input_extension, ".raw", 4)) return ReadRAW(filename);
  else if (!strncmp(input_extension, ".grd", 4)) return ReadGRD(filename);
  
  // Should never get here
  fprintf(stderr, "Unrecognized image file extension");
  return 0;
}
Пример #3
0
static void term_load_bitmap(void)
{
	char path[1024];

	byte *temp = NULL;

	int bw, bh;

	/* Build the "graf" path */
	path_build(path, 1024, ANGBAND_DIR_XTRA, "graf");

	sprintf (path, "%s/8x13.bmp", path);

	/* See if the file exists */
	if (fd_close(fd_open(path, O_RDONLY)))
	{
		printf ("Unable to load bitmap data file %s, bailing out....\n", path);
		exit ( -1);
	}

	temp = ReadBMP(path, &bw, &bh);

	/* Blit bitmap into buffer */
	gl_putbox(0, 0, bw, bh, temp);

	FREE(temp, byte);

	return;
}
Пример #4
0
Bitmap *BitmapNew( char* filename ) {

	Bitmap *bmp = malloc(sizeof(Bitmap));
	bmp->parent = NULL;
	bmp->paint = &paint;
	ReadBMP( filename, bmp );
	return bmp;
}
Пример #5
0
void ImageBMP::ReadBMP(FILE* stream, bool transparent,
                       int& width, int& height, void*& pixels) {
    fseek(stream, 0, SEEK_END);
    long size = ftell(stream);
    fseek(stream, 0, SEEK_SET);
    std::vector<uint8_t> buffer(size);
    fread((void*) &buffer.front(), 1, size, stream);
    ReadBMP(&buffer.front(), (unsigned) size, transparent, width, height, pixels);
}
Пример #6
0
void ImageBMP::ReadBMP(FILE* stream, bool transparent,
					int& width, int& height, void*& pixels) {
	fseek(stream, 0, SEEK_END);
	long size = ftell(stream);
	fseek(stream, 0, SEEK_SET);
	std::vector<uint8_t> buffer(size);
	long size_read = fread((void*) &buffer.front(), 1, size, stream);
	if (size_read != size) {
		Output::Error("Error reading BMP file.");
		return;
	}
	ReadBMP(&buffer.front(), (unsigned) size, transparent, width, height, pixels);
}
Пример #7
0
LDraw::Bitmap* BitmapLoader::Load(IO::ISequentialByteStream* stream)
{
	int n;
	for (n = 0; n < 5; n++)
	{
		int ret = -1;

		switch (n)
		{
		case 0:
			{
				ret = ReadJPEG(this, stream);
			}
			break;

		case 1:
			{
				ret = ReadGIF(this, stream);
			}
			break;

		case 2:
			{
				ret = ReadPNG(this, stream);
			}
			break;

		case 3:
			{
				ret = ReadBMP(this, stream);
			}
			break;

		case 4:
			{
				ret = ReadTGA(this, stream);
			}
			break;
		}

		if (ret == 0)
			break;

		stream->Seek(0, System::IO::STREAM_SEEK_SET);
	}

	return m_bitmap;
}
Пример #8
0
BOOL CYangLiuImageProcess::ReadImage(LPCTSTR lpszPathName)
{
	IplImage *image = (IplImage*)voidImage;
	CString str = lpszPathName;
	str.MakeLower();
	if (str.Find(_TEXT(".bmp")) != -1)
	{
		m_nOpenMode = 1;
		if (!ReadBMP(lpszPathName)) return FALSE;
		
		CvSize size;
		size.height = imageHeight;
		size.width = imageWidth;
		image = cvCreateImageHeader(size, 8, m_nColorBits / 8);
		image->imageData = (char *)m_pBits;
	}
	if (str.Find(_TEXT(".jpg")) != -1)
	{
		m_nOpenMode = 2;
		image = cvLoadImage(lpszPathName);
		lpbmi = (LPBITMAPINFO) new char[sizeof(BITMAPINFO)+4 * (1 << 8)];
		lpbmi->bmiHeader.biBitCount = image->depth*image->nChannels;
		lpbmi->bmiHeader.biClrUsed = 0;
		lpbmi->bmiHeader.biHeight = image->height;
		lpbmi->bmiHeader.biWidth = image->width;
		lpbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
		lpbmi->bmiHeader.biSizeImage = image->width*image->height*image->nChannels;
		lpbmi->bmiHeader.biClrImportant = 0;
		lpbmi->bmiHeader.biCompression = 0;
		lpbmi->bmiHeader.biPlanes = 1; //image->nChannels;
		imageWidth = image->width;
		imageHeight = image->height;
		for (int i = 0; i<(1 << 8); i++)
		{
			RGBQUAD &o = lpbmi->bmiColors[i];
			o.rgbBlue = i;
			o.rgbGreen = i;
			o.rgbRed = i;
			o.rgbReserved = 0;
		}
		m_nColorBits = image->depth*image->nChannels;
		m_pBits = (unsigned char *)image->imageData;
	}
	voidImage = (void *)image;
	return TRUE;
}
Пример #9
0
/**
 * Read a image file into the DIB.  This method will check to see if the
 * file is a BMP or JPEG and call the appropriate reader.
 */
bool vtDIB::Read(const char *fname, bool progress_callback(int))
{
	FILE *fp = vtFileOpen(fname, "rb");
	if (!fp)
		return false;
	uchar buf[2];
	if (fread(buf, 2, 1, fp) != 1)
		return false;
	fclose(fp);
	if (buf[0] == 0x42 && buf[1] == 0x4d)
		return ReadBMP(fname, progress_callback);
	else if (buf[0] == 0xFF && buf[1] == 0xD8)
		return ReadJPEG(fname, progress_callback);
	else if (buf[0] == 0x89 && buf[1] == 0x50)
		return ReadPNG(fname, progress_callback);
	return false;
}
Пример #10
0
//*************************************************************************************
//	
//*************************************************************************************
CTexture *	CTextureManager::Create( const CString & filename, bool warn )
{
	CTexture *		p_texture( NULL );
	CFile * const	p_file( CFileSystem::Open( filename, "rb" ) );

	if ( p_file != NULL )
	{
		const CString	extension( p_file->GetExtension() );

		if ( extension == "png" || extension == "PNG" )
		{
			p_texture = ReadPNG( p_file );
		}
		else if ( extension == "tga" || extension == "TGA" )
		{
			p_texture = ReadTGA( p_file );
		}
		else if ( extension == "jpg" || extension == "JPG" )
		{
			p_texture = ReadJPG( p_file );
		}
		else if ( extension == "bmp" || extension == "BMP" )
		{
			p_texture = ReadBMP( p_file );
		}
		else
		{
			TRACE( "Unrecognised image extension %s\n", extension.GetPtr() );
			ASSERT( 0, "" );
		}

		CFileSystem::Close( p_file );
	}

	if ( p_texture == NULL )
	{
		if ( warn == true )
		{
			TRACE( "Failed to load image %s\n", filename.GetPtr() );
			ASSERT( 0, "" );
		}
	}

	return p_texture;
}
Пример #11
0
int main() {
	FILE *input;
	FILE *output;
	fileHeader fh;
	infoHeader ih;
	void *pixelArray = NULL;

	input = fopen("fireworks w crowd.bmp", "r");

	memset(&fh, 0x0, sizeof(fileHeader));
	memset(&ih, 0x0, sizeof(infoHeader));

	ReadBMP(input, &fh, &ih, &pixelArray);

	fclose(input);

	/*printf("File Header\n");
	printf("format : %u\n", fh.format);
	printf("file size : %u\n", fh.size);
	printf("reserved1 : %u\n", fh.reserved1);
	printf("reserved2 : %u\n", fh.reserved2);
	printf("pixel array offset : %u\n", fh.pixelArrayLoc);

	printf("Info Header\n");
	printf("size : %u\n", ih.size);
	printf("width : %u\n", ih.width);
	printf("height : %u\n", ih.height);
	printf("planes : %u\n", ih.planes);
	printf("depth : %u\n", ih.depth);
	printf("compression : %u\n", ih.compression);
	printf("imgSize : %u\n", ih.imgSize);
	printf("xRes : %u\n", ih.xRes);
	printf("yRes : %u\n", ih.yRes);
	printf("colorTableSize : %u\n", ih.colorTableSize);
	printf("colorImportant : %u\n", ih.colorImportant);*/

	output = fopen("fireworks w crowd.png", "w");
	BMPtoPNG(fh, ih, NULL, pixelArray, output);
	free(pixelArray);
	fclose(output);

	return 0;
}
Пример #12
0
void put_scen_info()
{
	short i;
	char place_str[256];
	char *ratings[] = {"G","PG","R","NC-17"};
	char *difficulty[] = {"Low","Medium","High","Very High"};

	for (i = 0; i < 3; i++)
	   if(store_scen_page_on * 3 + i < store_num_scen){
            if(scen_headers[store_scen_page_on * 3 + i].intro_pic == 100){//custom intro pic
           	sprintf(place_str,"scenarios/%s",data_store2[store_scen_page_on * 3 + i].scen_names);
           	place_str[strlen(place_str)-3]='b';
           	place_str[strlen(place_str)-2]='m';
           	place_str[strlen(place_str)-1]='p';
            spec_scen_g = ReadBMP(place_str);
            cd_set_pict(947, 6 + i * 3,2400);
            DeleteObject(spec_scen_g);
            }
            else
			cd_set_pict(947, 6 + i * 3,1600 + scen_headers[store_scen_page_on * 3 + i].intro_pic);
			sprintf((char *) place_str,
				"%s v%d.%d.%d - |  Difficulty: %s, Rating: %s |%s |%s",
				data_store2[store_scen_page_on * 3 + i].scen_header_strs[0],
				(short) scen_headers[store_scen_page_on * 3 + i].ver[0],
				(short) scen_headers[store_scen_page_on * 3 + i].ver[1],
				(short) scen_headers[store_scen_page_on * 3 + i].ver[2],
				difficulty[scen_headers[store_scen_page_on * 3 + i].difficulty],
				ratings[scen_headers[store_scen_page_on * 3 + i].default_ground],
				data_store2[store_scen_page_on * 3 + i].scen_header_strs[1],
				data_store2[store_scen_page_on * 3 + i].scen_header_strs[2]);
			csit(947,7 + i * 3,(char *) place_str);
			cd_activate_item(947,8 + i * 3,1);
			}
			else {
				cd_set_pict(947, 6 + i * 3,950);
				csit(947,7 + i * 3,"");
				cd_activate_item(947,8 + i * 3,0);
				}
}
Пример #13
0
static void
run (const gchar      *name,
     gint             nparams,
     const GimpParam  *param,
     gint             *nreturn_vals,
     GimpParam       **return_vals)
{
  static GimpParam  values[2];
  GimpRunMode       run_mode;
  GimpPDBStatusType status = GIMP_PDB_SUCCESS;
  gint32            image_ID;
  gint32            drawable_ID;
  GimpExportReturn  export = GIMP_EXPORT_CANCEL;

  run_mode = param[0].data.d_int32;

  INIT_I18N ();

  *nreturn_vals = 1;
  *return_vals  = values;
  values[0].type          = GIMP_PDB_STATUS;
  values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;

  if (strcmp (name, LOAD_PROC) == 0)
    {
       switch (run_mode)
        {
        case GIMP_RUN_INTERACTIVE:
          interactive = TRUE;
          break;

        case GIMP_RUN_NONINTERACTIVE:
          /*  Make sure all the arguments are there!  */
          if (nparams != 3)
            status = GIMP_PDB_CALLING_ERROR;
          break;

        default:
          break;
        }

       if (status == GIMP_PDB_SUCCESS)
         {
           image_ID = ReadBMP (param[1].data.d_string);

           if (image_ID != -1)
             {
               *nreturn_vals = 2;
               values[1].type         = GIMP_PDB_IMAGE;
               values[1].data.d_image = image_ID;
             }
           else
             {
               status = GIMP_PDB_EXECUTION_ERROR;
             }
         }
    }
  else if (strcmp (name, SAVE_PROC) == 0)
    {
      image_ID    = param[1].data.d_int32;
      drawable_ID = param[2].data.d_int32;

      /*  eventually export the image */
      switch (run_mode)
        {
        case GIMP_RUN_INTERACTIVE:
          interactive = TRUE;
          /* fallthrough */

        case GIMP_RUN_WITH_LAST_VALS:
          if (run_mode == GIMP_RUN_WITH_LAST_VALS) lastvals = TRUE;
          gimp_ui_init ("bmp", FALSE);
          export = gimp_export_image (&image_ID, &drawable_ID, "BMP",
                                      (GIMP_EXPORT_CAN_HANDLE_RGB |
                                       GIMP_EXPORT_CAN_HANDLE_ALPHA |
                                       GIMP_EXPORT_CAN_HANDLE_GRAY |
                                       GIMP_EXPORT_CAN_HANDLE_INDEXED));

          if (export == GIMP_EXPORT_CANCEL)
            {
              values[0].data.d_status = GIMP_PDB_CANCEL;
              return;
            }
          break;

        case GIMP_RUN_NONINTERACTIVE:
          /*  Make sure all the arguments are there!  */
          if (nparams != 5)
            status = GIMP_PDB_CALLING_ERROR;
          break;

        default:
          break;
        }
Пример #14
0
/*
 * Initialization function for an X Athena Widget module to Angband
 *
 * We should accept "-d<dpy>" requests in the "argv" array.  XXX XXX XXX
 */
errr init_xaw(int argc, char *argv[])
{
	int i;
	Widget topLevel;
	Display *dpy;

	cptr dpy_name = "";


#ifdef USE_GRAPHICS

	char filename[1024];

	int pict_wid = 0;
	int pict_hgt = 0;

#ifdef USE_TRANSPARENCY

	char *TmpData;
#endif /* USE_TRANSPARENCY */

#endif /* USE_GRAPHICS */

	/* Parse args */
	for (i = 1; i < argc; i++)
	{
		if (prefix(argv[i], "-d"))
		{
			dpy_name = &argv[i][2];
			continue;
		}

#ifdef USE_GRAPHICS
		if (prefix(argv[i], "-s"))
		{
			smoothRescaling = FALSE;
			continue;
		}
#endif /* USE_GRAPHICS */

		if (prefix(argv[i], "-n"))
		{
			num_term = atoi(&argv[i][2]);
			if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA;
			else if (num_term < 1) num_term = 1;
			continue;
		}

		plog_fmt("Ignoring option: %s", argv[i]);
	}


	/* Attempt to open the local display */
	dpy = XOpenDisplay(dpy_name);

	/* Failure -- assume no X11 available */
	if (!dpy) return (-1);

	/* Close the local display */
	XCloseDisplay(dpy);


#ifdef USE_XAW_LANG

	/* Support locale processing */
	XtSetLanguageProc(NULL, NULL, NULL);

#endif /* USE_XAW_LANG */


	/* Initialize the toolkit */
	topLevel = XtAppInitialize(&appcon, "Angband", NULL, 0, &argc, argv,
	                           fallback, NULL, 0);


	/* Initialize the windows */
	for (i = 0; i < num_term; i++)
	{
		term_data *td = &data[i];

		term_data_init(td, topLevel, 1024, termNames[i],
		               (i == 0) ? specialArgs : defaultArgs,
		               TERM_FALLBACKS, i);

		angband_term[i] = Term;
	}

	/* Activate the "Angband" window screen */
	Term_activate(&data[0].t);

	/* Raise the "Angband" window */
	term_raise(&data[0]);


#ifdef USE_GRAPHICS

	/* Try graphics */
	if (arg_graphics)
	{
		/* Try the "16x16.bmp" file */
		path_build(filename, 1024, ANGBAND_DIR_XTRA, "graf/16x16.bmp");

		/* Use the "16x16.bmp" file if it exists */
		if (0 == fd_close(fd_open(filename, O_RDONLY)))
		{
			/* Use graphics */
			use_graphics = TRUE;

			use_transparency = TRUE;

			pict_wid = pict_hgt = 16;

			ANGBAND_GRAF = "new";
		}
		else
		{
			/* Try the "8x8.bmp" file */
			path_build(filename, 1024, ANGBAND_DIR_XTRA, "graf/8x8.bmp");

			/* Use the "8x8.bmp" file if it exists */
			if (0 == fd_close(fd_open(filename, O_RDONLY)))
			{
				/* Use graphics */
				use_graphics = TRUE;

				pict_wid = pict_hgt = 8;

				ANGBAND_GRAF = "old";
			}
		}
	}

	/* Load graphics */
	if (use_graphics)
	{
		/* Hack -- Get the Display */
		term_data *td = &data[0];
		Widget widget = (Widget)(td->widget);
		Display *dpy = XtDisplay(widget);

		XImage *tiles_raw;

		/* Load the graphical tiles */
		tiles_raw = ReadBMP(dpy, filename);

		/* Initialize the windows */
		for (i = 0; i < num_term; i++)
		{
			term_data *td = &data[i];

			term *t = &td->t;

			t->pict_hook = Term_pict_xaw;

			t->higher_pict = TRUE;

			/* Resize tiles */
			td->widget->angband.tiles =
			ResizeImage(dpy, tiles_raw,
			            pict_wid, pict_hgt,
			            td->widget->angband.fontwidth,
			            td->widget->angband.fontheight);
		}

#ifdef USE_TRANSPARENCY
		/* Initialize the transparency temp storage*/
		for (i = 0; i < num_term; i++)
		{
			term_data *td = &data[i];
			int ii, jj;
			int depth = DefaultDepth(dpy, DefaultScreen(dpy));
			Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy));
			int total;


			/* Determine total bytes needed for image */
			ii = 1;
			jj = (depth - 1) >> 2;
			while (jj >>= 1) ii <<= 1;
			total = td->widget->angband.fontwidth *
				 td->widget->angband.fontheight * ii;


			TmpData = (char *)malloc(total);

			td->widget->angband.TmpImage = XCreateImage(dpy,
				visual,depth,
				ZPixmap, 0, TmpData,
				td->widget->angband.fontwidth,
			        td->widget->angband.fontheight, 8, 0);

		}
#endif /* USE_TRANSPARENCY */


		/* Free tiles_raw? XXX XXX */
	}

#endif /* USE_GRAPHICS */

	/* Success */
	return (0);
}
Пример #15
0
HBITMAP load_pict(short pict_num)
{
	HBITMAP got_bitmap;

	switch(pict_num) {
		case 700: got_bitmap = ReadBMP("Images/STATAREA.BMP"); break;
		case 701: got_bitmap = ReadBMP("Images/STATAREA.BMP"); break;
		case 702: got_bitmap = ReadBMP("Images/STATAREA.BMP"); break;
		case 703: got_bitmap = ReadBMP("Images/TEXTBAR.BMP"); break;
		case 704: got_bitmap = ReadBMP("Images/BUTTONS.BMP"); break;
		case 705: got_bitmap = ReadBMP("Images/TERSCRN.BMP"); break;
		case 800: got_bitmap = ReadBMP("Images/TER1.BMP"); break;
		case 801: got_bitmap = ReadBMP("Images/TER2.BMP"); break;
		case 802: got_bitmap = ReadBMP("Images/TER3.BMP"); break;
		case 803: got_bitmap = ReadBMP("Images/TER4.BMP"); break;
		case 804: got_bitmap = ReadBMP("Images/TER5.BMP"); break;
		case 805: got_bitmap = ReadBMP("Images/TER6.BMP"); break;
		case 820: got_bitmap = ReadBMP("Images/TERANIM.BMP"); break;
		case 821: got_bitmap = ReadBMP("Images/FIELDS.BMP"); break;
		case 830: got_bitmap = ReadBMP("Images/STARTUP.BMP"); break;
		case 850: got_bitmap = ReadBMP("Images/DLOGPICS.BMP"); break;
		case 851: got_bitmap = ReadBMP("Images/SCENPICS.BMP"); break;
		case 860: got_bitmap = ReadBMP("Images/TALKPORT.BMP"); break;
		case 880: got_bitmap = ReadBMP("Images/MISSILES.BMP"); break;
		case 900: got_bitmap = ReadBMP("Images/TINYOBJ.BMP"); break;
		case 901: got_bitmap = ReadBMP("Images/OBJECTS.BMP"); break;
		case 902: got_bitmap = ReadBMP("Images/PCS.BMP"); break;
		case 905: got_bitmap = ReadBMP("Images/PCS.BMP"); break;
		case 903: got_bitmap = ReadBMP("Images/MIXED.BMP"); break;
		case 904: got_bitmap = ReadBMP("Images/MIXED.BMP"); break;
		case 906: got_bitmap = ReadBMP("Images/EDBTNS.BMP"); break;
		case 910: got_bitmap = ReadBMP("Images/BIGSCEN.BMP"); break;
		case 911: got_bitmap = ReadBMP("Images/BIGSCEN.BMP"); break;
		case 912: got_bitmap = ReadBMP("Images/BIGSCEN.BMP"); break;
		case 1100: case 1200: got_bitmap = ReadBMP("Images/MONST1.BMP"); break;
		case 1101: case 1201: got_bitmap = ReadBMP("Images/MONST2.BMP"); break;
		case 1102: case 1202: got_bitmap = ReadBMP("Images/MONST3.BMP"); break;
		case 1103: case 1203: got_bitmap = ReadBMP("Images/MONST4.BMP"); break;
		case 1104: case 1204: got_bitmap = ReadBMP("Images/MONST5.BMP"); break;
		case 1105: case 1205: got_bitmap = ReadBMP("Images/MONST6.BMP"); break;
		case 1106: case 1206: got_bitmap = ReadBMP("Images/MONST7.BMP"); break;
		case 1107: case 1207: got_bitmap = ReadBMP("Images/MONST8.BMP"); break;
		case 1108: case 1208: got_bitmap = ReadBMP("Images/MONST9.BMP"); break;
		case 1109: case 1209: got_bitmap = ReadBMP("Images/MONST10.BMP"); break;
		case 1400: got_bitmap = ReadBMP("Images/STSCICON.BMP"); break;
		case 1401: got_bitmap = ReadBMP("Images/HELPPICS.BMP"); break;
		case 1402: got_bitmap = ReadBMP("Images/APPIC.BMP"); break;
		case 1500: case 1501: case 1502: case 1503: case 1504: case 1505: case 1506: case 1507:
			got_bitmap = ReadBMP("Images/BIGMAPS.BMP"); break;
		case 2000: got_bitmap = ReadBMP("Images/DLOGBTNS.BMP"); break;
		case 3000: got_bitmap = ReadBMP("Images/START.BMP"); break;
		case 3001: got_bitmap = ReadBMP("Images/SPIDLOGO.BMP"); break;
		case 3002: got_bitmap = ReadBMP("Images/EDSTART.BMP"); break;
		case 5000: got_bitmap = ReadBMP("Images/E3EDTITL.BMP"); break;

		default: got_bitmap = NULL;
		}
	return got_bitmap;
}
Пример #16
0
/*
 * Initialization function for an "X11" module to Angband
 */
errr init_x11(int argc, char **argv)
{
	int i;

	cptr dpy_name = "";

	int num_term = 1;

#ifdef USE_GRAPHICS

	cptr bitmap_file = "";
	char filename[1024];

	int pict_wid = 0;
	int pict_hgt = 0;

	char *TmpData;

#endif /* USE_GRAPHICS */


	/* Parse args */
	for (i = 1; i < argc; i++)
	{
		if (prefix(argv[i], "-d"))
		{
			dpy_name = &argv[i][2];
			continue;
		}

#ifdef USE_GRAPHICS
		if (prefix(argv[i], "-s"))
		{
			smoothRescaling = FALSE;
			continue;
		}

		if (prefix(argv[i], "-o"))
		{
			arg_graphics = GRAPHICS_ORIGINAL;
			continue;
		}

		if (prefix(argv[i], "-a"))
		{
			arg_graphics = GRAPHICS_ADAM_BOLT;
			continue;
		}

		if (prefix(argv[i], "-g"))
		{
			smoothRescaling = FALSE;
			arg_graphics = GRAPHICS_DAVID_GERVAIS;
			continue;
		}

		if (prefix(argv[i], "-b"))
		{
			use_bigtile = TRUE;
			continue;
		}

#endif /* USE_GRAPHICS */

		if (prefix(argv[i], "-n"))
		{
			num_term = atoi(&argv[i][2]);
			if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA;
			else if (num_term < 1) num_term = 1;
			continue;
		}

		plog_fmt("Ignoring option: %s", argv[i]);
	}


	/* Init the Metadpy if possible */
	if (Metadpy_init_name(dpy_name)) return (-1);


	/* Prepare cursor color */
	MAKE(xor, infoclr);
	Infoclr_set(xor);
	Infoclr_init_ppn(Metadpy->fg, Metadpy->bg, "xor", 0);


	/* Prepare normal colors */
	for (i = 0; i < 256; ++i)
	{
		Pixell pixel;

		MAKE(clr[i], infoclr);

		Infoclr_set(clr[i]);

		/* Acquire Angband colors */
		color_table[i][0] = angband_color_table[i][0];
		color_table[i][1] = angband_color_table[i][1];
		color_table[i][2] = angband_color_table[i][2];
		color_table[i][3] = angband_color_table[i][3];

		/* Default to monochrome */
		pixel = ((i == 0) ? Metadpy->bg : Metadpy->fg);

		/* Handle color */
		if (Metadpy->color)
		{
			/* Create pixel */
			pixel = create_pixel(Metadpy->dpy,
			                     color_table[i][1],
			                     color_table[i][2],
			                     color_table[i][3]);
		}

		/* Initialize the color */
		Infoclr_init_ppn(pixel, Metadpy->bg, "cpy", 0);
	}


	/* Initialize the windows */
	for (i = 0; i < num_term; i++)
	{
		term_data *td = &data[i];

		/* Initialize the term_data */
		term_data_init(td, i);

		/* Save global entry */
		angband_term[i] = Term;
	}

	/* Raise the "Angband" window */
	Infowin_set(data[0].win);
	Infowin_raise();

	/* Activate the "Angband" window screen */
	Term_activate(&data[0].t);


#ifdef USE_GRAPHICS

	/* Try graphics */
	switch (arg_graphics)
	{
	case GRAPHICS_ADAM_BOLT:
		/* Use tile graphics of Adam Bolt */
		bitmap_file = "16x16.bmp";

		/* Try the "16x16.bmp" file */
		path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file));

		/* Use the "16x16.bmp" file if it exists */
		if (0 == fd_close(fd_open(filename, O_RDONLY)))
		{
			/* Use graphics */
			use_graphics = TRUE;
			use_transparency = TRUE;

			pict_wid = pict_hgt = 16;

			ANGBAND_GRAF = "new";

			break;
		}
		/* Fall through */

	case GRAPHICS_ORIGINAL:
		/* Use original tile graphics */
		bitmap_file = "8x8.bmp";

		/* Try the "8x8.bmp" file */
		path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file));

		/* Use the "8x8.bmp" file if it exists */
		if (0 == fd_close(fd_open(filename, O_RDONLY)))
		{
			/* Use graphics */
			use_graphics = TRUE;

			pict_wid = pict_hgt = 8;

			ANGBAND_GRAF = "old";
			break;
		}
		break;

	case GRAPHICS_DAVID_GERVAIS:
		/* Use tile graphics of David Gervais */
		bitmap_file = "32x32.bmp";

		/* Use graphics */
		use_graphics = TRUE;
		use_transparency = TRUE;

		pict_wid = pict_hgt = 32;

		ANGBAND_GRAF = "david";
		break;
	}

	/* Load graphics */
	if (use_graphics)
	{
		Display *dpy = Metadpy->dpy;

		XImage *tiles_raw;

		/* Initialize */
		for (i = 0; i < num_term; i++)
		{
			term_data *td = &data[i];
			td->tiles = NULL;
		}

		path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file));

		/* Load the graphical tiles */
		tiles_raw = ReadBMP(dpy, filename);

		if (tiles_raw)
		{
			/* Initialize the windows */
			for (i = 0; i < num_term; i++)
			{
				int j;
				bool same = FALSE;

				term_data *td = &data[i];
				term_data *o_td = NULL;

				term *t = &td->t;

				/* Graphics hook */
				t->pict_hook = Term_pict_x11;

				/* Use graphics sometimes */
				t->higher_pict = TRUE;

				/* Look for another term with same font size */
				for (j = 0; j < i; j++)
				{
					o_td = &data[j];

					if ((td->fnt->twid == o_td->fnt->twid) && (td->fnt->hgt == o_td->fnt->hgt))
					{
						same = TRUE;
						break;
					}
				}

				if (!same)
				{
					/* Resize tiles */
					td->tiles = ResizeImage(dpy, tiles_raw,
					                        pict_wid, pict_hgt,
					                        td->fnt->twid, td->fnt->hgt);
				}
				else
				{
					/* Use same graphics */
					td->tiles = o_td->tiles;
				}
			}

			/* Free tiles_raw */
			FREE(tiles_raw);
		}
                        
		/* Initialize the transparency masks */
		for (i = 0; i < num_term; i++)
		{
			term_data *td = &data[i];
			int ii, jj;
			int depth = DefaultDepth(dpy, DefaultScreen(dpy));
			Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy));
			int total;


			/* Determine total bytes needed for image */
			ii = 1;
			jj = (depth - 1) >> 2;
			while (jj >>= 1) ii <<= 1;
			total = td->fnt->twid * td->fnt->hgt * ii;


			TmpData = (char *)malloc(total);

			td->TmpImage = XCreateImage(dpy,visual,depth,
				ZPixmap, 0, TmpData,
				td->fnt->twid, td->fnt->hgt, 32, 0);

		}
	}

#endif /* USE_GRAPHICS */


	/* Success */
	return (0);
}
Пример #17
0
/*
 * Initialization function for an X Athena Widget module to Angband
 *
 * We should accept "-d<dpy>" requests in the "argv" array.  XXX XXX XXX
 */
errr init_xaw(int argc, char **argv)
{
	int i;
	Widget topLevel;
	Display *dpy;

	cptr dpy_name = "";


#ifdef USE_GRAPHICS

	cptr bitmap_file = "";
	char filename[1024];

	int pict_wid = 0;
	int pict_hgt = 0;

	char *TmpData;

#endif /* USE_GRAPHICS */

	/* Parse args */
	for (i = 1; i < argc; i++)
	{
		if (prefix(argv[i], "-d"))
		{
			dpy_name = &argv[i][2];
			continue;
		}

#ifdef USE_GRAPHICS
		if (prefix(argv[i], "-s"))
		{
			smoothRescaling = FALSE;
			continue;
		}

		if (prefix(argv[i], "-o"))
		{
			arg_graphics = GRAPHICS_ORIGINAL;
			continue;
		}

		if (prefix(argv[i], "-a"))
		{
			arg_graphics = GRAPHICS_ADAM_BOLT;
			continue;
		}

		if (prefix(argv[i], "-g"))
		{
			smoothRescaling = FALSE;
			arg_graphics = GRAPHICS_DAVID_GERVAIS;
			continue;
		}

		if (prefix(argv[i], "-b"))
		{
			use_bigtile = TRUE;
			continue;
		}

#endif /* USE_GRAPHICS */

		if (prefix(argv[i], "-n"))
		{
			num_term = atoi(&argv[i][2]);
			if (num_term > MAX_TERM_DATA) num_term = MAX_TERM_DATA;
			else if (num_term < 1) num_term = 1;
			continue;
		}

		plog_fmt("Ignoring option: %s", argv[i]);
	}


	/* Attempt to open the local display */
	dpy = XOpenDisplay(dpy_name);

	/* Failure -- assume no X11 available */
	if (!dpy) return (-1);

	/* Close the local display */
	XCloseDisplay(dpy);


#ifdef USE_XAW_LANG

	/* Support locale processing */
	XtSetLanguageProc(NULL, NULL, NULL);

#endif /* USE_XAW_LANG */


	/* Initialize the toolkit */
	topLevel = XtAppInitialize(&appcon, "Angband", NULL, 0, &argc, argv,
	                           fallback, NULL, 0);


	/* Initialize the windows */
	for (i = 0; i < num_term; i++)
	{
		term_data *td = &data[i];

		term_data_init(td, topLevel, 1024, termNames[i],
		               (i == 0) ? specialArgs : defaultArgs,
		               TERM_FALLBACKS, i);

		angband_term[i] = Term;
	}

	/* Activate the "Angband" window screen */
	Term_activate(&data[0].t);

	/* Raise the "Angband" window */
	term_raise(&data[0]);


#ifdef USE_GRAPHICS

	/* Try graphics */
	switch (arg_graphics)
	{
	case GRAPHICS_ADAM_BOLT:
		/* Use tile graphics of Adam Bolt */
		bitmap_file = "16x16.bmp";

		/* Try the "16x16.bmp" file */
		path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file));

		/* Use the "16x16.bmp" file if it exists */
		if (0 == fd_close(fd_open(filename, O_RDONLY)))
		{
			/* Use graphics */
			use_graphics = GRAPHICS_ADAM_BOLT;
			use_transparency = TRUE;

			pict_wid = pict_hgt = 16;

			ANGBAND_GRAF = "new";

			break;
		}
		/* Fall through */

	case GRAPHICS_ORIGINAL:
		/* Use original tile graphics */
		bitmap_file = "8x8.bmp";

		/* Try the "8x8.bmp" file */
		path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file));

		/* Use the "8x8.bmp" file if it exists */
		if (0 == fd_close(fd_open(filename, O_RDONLY)))
		{
			/* Use graphics */
			use_graphics = GRAPHICS_ORIGINAL;

			pict_wid = pict_hgt = 8;

			ANGBAND_GRAF = "old";
			break;
		}
		break;

	case GRAPHICS_DAVID_GERVAIS:
		/* Use tile graphics of David Gervais */
		bitmap_file = "32x32.bmp";

		/* Use graphics */
		use_graphics = GRAPHICS_DAVID_GERVAIS;
		use_transparency = TRUE;

		pict_wid = pict_hgt = 32;

		ANGBAND_GRAF = "david";
		break;
	}

	/* Load graphics */
	if (use_graphics)
	{
		/* Hack -- Get the Display */
		term_data *td = &data[0];
		Widget widget = (Widget)(td->widget);
		Display *dpy = XtDisplay(widget);

		XImage *tiles_raw;

		for (i = 0; i < num_term; i++)
		{
			term_data *td = &data[i];
			td->widget->angband.tiles = NULL;
		}

		path_build(filename, sizeof(filename), ANGBAND_DIR_XTRA, format("graf/%s", bitmap_file));

		/* Load the graphical tiles */
		tiles_raw = ReadBMP(dpy, filename);

		if (tiles_raw)
		{
			/* Initialize the windows */
			for (i = 0; i < num_term; i++)
			{
				int j;
				bool same = FALSE;

				term_data *td = &data[i];
				term_data *o_td = NULL;

				term *t = &td->t;

				t->pict_hook = Term_pict_xaw;

				t->higher_pict = TRUE;

				/* Look for another term with same font size */
				for (j = 0; j < i; j++)
				{
					o_td = &data[j];

					if ((td->widget->angband.tilewidth == o_td->widget->angband.tilewidth) &&
					    (td->widget->angband.fontheight == o_td->widget->angband.fontheight))
					{
						same = TRUE;
						break;
					}
				}

				if (!same)
				{
					/* Resize tiles */
					td->widget->angband.tiles = ResizeImage(dpy, tiles_raw,
					                                        pict_wid, pict_hgt,
					                                        td->widget->angband.tilewidth,
					                                        td->widget->angband.fontheight);
				}
				else
				{
					/* Use same graphics */
					td->widget->angband.tiles = o_td->widget->angband.tiles;
				}
			}

			/* Free tiles_raw */
			FREE(tiles_raw);
		}

		/* Initialize the transparency temp storage */
		for (i = 0; i < num_term; i++)
		{
			term_data *td = &data[i];
			int ii, jj;
			int depth = DefaultDepth(dpy, DefaultScreen(dpy));
			Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy));
			int total;


			/* Determine total bytes needed for image */
			ii = 1;
			jj = (depth - 1) >> 2;
			while (jj >>= 1) ii <<= 1;
			total = td->widget->angband.tilewidth *
			        td->widget->angband.fontheight * ii;


			TmpData = (char *)malloc(total);

			td->widget->angband.TmpImage = XCreateImage(dpy,
				visual,depth,
				ZPixmap, 0, TmpData,
				td->widget->angband.tilewidth,
			        td->widget->angband.fontheight, 8, 0);
		}
	}

#endif /* USE_GRAPHICS */

	/* Success */
	return (0);
}