The R Project SVN R

Rev

Rev 44594 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 44594 Rev 44641
Line 467... Line 467...
467
*/
467
*/
468
 
468
 
469
#define BMPERROR {R_ShowMessage("Problems writing to 'bmp' file");return 0;}
469
#define BMPERROR {R_ShowMessage("Problems writing to 'bmp' file");return 0;}
470
#define BMPW(a) {wrd=a;if(fwrite(&wrd,sizeof(unsigned short),1,fp)!=1) BMPERROR}
470
#define BMPW(a) {wrd=a;if(fwrite(&wrd,sizeof(unsigned short),1,fp)!=1) BMPERROR}
471
#define BMPDW(a) {dwrd=a;if(fwrite(&dwrd,sizeof(unsigned int),1,fp)!=1) BMPERROR}
471
#define BMPDW(a) {dwrd=a;if(fwrite(&dwrd,sizeof(unsigned int),1,fp)!=1) BMPERROR}
472
#define BMPLONG(a) {lng=a;if(fwrite(&lng,sizeof(long),1,fp)!=1) BMPERROR}
-
 
473
#define BMPPUTC(a) if(fputc(a,fp)==EOF) BMPERROR;
472
#define BMPPUTC(a) if(fputc(a,fp)==EOF) BMPERROR;
474
#define HEADERSIZE 54
473
#define HEADERSIZE 54
475
 
474
 
476
__declspec(dllexport)
475
__declspec(dllexport)
477
int R_SaveAsBmp(void  *d, int width, int height,
476
int R_SaveAsBmp(void  *d, int width, int height,
Line 481... Line 480...
481
    unsigned int  col, palette[256];
480
    unsigned int  col, palette[256];
482
    int i, j, r, ncols, mid, high, low, withpalette;
481
    int i, j, r, ncols, mid, high, low, withpalette;
483
    int bfOffBits, bfSize, biBitCount, biClrUsed , pad;
482
    int bfOffBits, bfSize, biBitCount, biClrUsed , pad;
484
    unsigned short wrd;
483
    unsigned short wrd;
485
    unsigned int dwrd;
484
    unsigned int dwrd;
486
    long lng, lres;
485
    int lres;
487
    DECLARESHIFTS;
486
    DECLARESHIFTS;
488
 
487
 
489
    /* Have we less than 256 different colors? */
488
    /* Have we less than 256 different colors? */
490
    ncols = mid = 0;
489
    ncols = mid = 0;
491
    withpalette = 1;
490
    withpalette = 1;
Line 527... Line 526...
527
	biBitCount = 24;
526
	biBitCount = 24;
528
	biClrUsed = 0;
527
	biClrUsed = 0;
529
    }
528
    }
530
 
529
 
531
    /* write the header */
530
    /* write the header */
-
 
531
    
532
    BMPW(0x4D42); /* bfType must be "BM" */
532
    BMPPUTC('B');BMPPUTC('M');
533
    BMPDW(bfSize); /*bfSize*/
533
    BMPDW(bfSize); /*bfSize*/
534
    BMPW(0);BMPW(0); /* bfReserved1 and bfReserved2 must be 0*/
534
    BMPW(0);BMPW(0); /* bfReserved1 and bfReserved2 must be 0*/
535
    BMPDW(bfOffBits); /* bfOffBits */
535
    BMPDW(bfOffBits); /* bfOffBits */
536
    BMPDW(40);	/* biSize */
536
    BMPDW(40);	/* Windows V3. size 40 bytes */
537
    BMPLONG(width); /* biWidth */
537
    BMPDW(width); /* biWidth */
538
    BMPLONG(height); /* biHeight */
538
    BMPDW(height); /* biHeight */
539
    BMPW(1);	/* biPlanes - must be 1 */
539
    BMPW(1);	/* biPlanes - must be 1 */
540
    BMPW(biBitCount); /* biBitCount */
540
    BMPW(biBitCount); /* biBitCount */
541
    BMPDW(0); /* biCompression=BI_RGB */
541
    BMPDW(0); /* biCompression=BI_RGB */
542
    BMPDW(0); /* biSizeImage (with BI_RGB not needed)*/
542
    BMPDW(0); /* biSizeImage (with BI_RGB not needed)*/
543
    lres = (long)(0.5 + res/0.0254);
543
    lres = (int)(0.5 + res/0.0254);
544
    BMPLONG(lres); /* XPels/M <- used only by Windows?*/
544
    BMPDW(lres); /* XPels/M */
545
    BMPLONG(lres); /* XPels/M */
545
    BMPDW(lres); /* XPels/M */
546
    BMPDW(biClrUsed); /* biClrUsed */
546
    BMPDW(biClrUsed); /* biClrUsed */
547
    BMPDW(0) ; /* biClrImportant All colours are important */
547
    BMPDW(0) ; /* biClrImportant All colours are important */
548
 
548
 
549
    /* and now the image */
549
    /* and now the image */
550
    if (withpalette) {
550
    if (withpalette) {