Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
- #include <iostream>
- #include <fstream>
- #define XSIZE 2048 //make sure it's a multiple of 4
- #define YSIZE 2048
- using namespace std;
- char* bmpdata;
- inline void setPixel(int x, int y, int c) {
- bmpdata[(x+XSIZE*(YSIZE-1-y))*3+54] = c&0xFF;
- bmpdata[(x+XSIZE*(YSIZE-1-y))*3+55] = (c>>8)&0xFF;
- bmpdata[(x+XSIZE*(YSIZE-1-y))*3+56] = (c>>16)&0xFF;
- }
- struct MTwist{
- int MT[624];
- int index;
- MTwist(){index=0;seed(2);seed(get());}
- void seed(int seed){
- MT[0]=seed;for(int i=1;i<624;i++)MT[i]=(-1)&(1812433253*(MT[i-1]^((MT[i-1])>>30))+i);//0x6C078965
- }
- int get(){
- if(!index)genN();int y=MT[index];y^=y>>11;
- y^=(y<<7)&2636928640;//0x9D2C5680
- y^=(y<<15)&4022730752;//0xEFC60000
- y^=y>>18;index=(++index)%624;return y;
- }
- void genN(){
- for(int i=0;i<624;i++){int y=((MT[i]>>31)&1)+(0x7FFFFFFF&(MT[(i+1)%624]));
- MT[i]=MT[(i+397)%624]^(y>>1);if(y&1)MT[i]^=2567483615;//0x9908B0DF
- }
- }
- };
- MTwist rnd;
- int main() {
- rnd.seed(time(0));
- int fsize = SIZE*SIZE*3+54; //54 bytes header
- bmpdata = (char*)malloc(fsize);
- for(int i=0;i<54;i++)bmpdata[i]=0;
- bmpdata[0] = 'B'; //magic
- bmpdata[1] = 'M';
- bmpdata[2] = fsize&0xFF; //file size
- bmpdata[3] = (fsize>>8)&0xFF;
- bmpdata[4] = (fsize>>16)&0xFF;
- bmpdata[5] = (fsize>>24)&0xFF;
- bmpdata[10] = 54; //bitmap data offset
- bmpdata[14] = 40; //header size after this
- bmpdata[18] = XSIZE&0xFF; //x
- bmpdata[19] = (XSIZE&0xFF00)>>8;
- bmpdata[22] = YSIZE&0xFF; //y
- bmpdata[23] = (YSIZE&0xFF00)>>8;
- bmpdata[26] = 1; //planes
- bmpdata[28] = 24; //bpp
- fsize -= 54;
- bmpdata[34] = fsize&0xFF; //bitmap data size
- bmpdata[35] = (fsize>>8)&0xFF;
- bmpdata[36] = (fsize>>16)&0xFF;
- bmpdata[37] = (fsize>>24)&0xFF;
- fsize += 54;
- bmpdata[38] = 0x13; //x dpi|ppm
- bmpdata[39] = 0x0B;
- bmpdata[42] = 0x13; //y dpi|ppm
- bmpdata[43] = 0x0B;
- //do stuff here
- ofstream output;
- char* fname = (char*)malloc(128);
- sprintf(fname, "test%.4u.bmp", 0);
- output.open(fname, fstream::binary|fstream::out|fstream::trunc);
- output.write(bmpdata, fsize);
- output.flush();
- output.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement