bildramer

Untitled

Dec 24th, 2011
718
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <math.h>
  3. #include <time.h>
  4. #include <iostream>
  5. #include <fstream>
  6. #define XSIZE 2048 //make sure it's a multiple of 4
  7. #define YSIZE 2048
  8.  
  9. using namespace std;
  10.  
  11. char* bmpdata;
  12.  
  13. inline void setPixel(int x, int y, int c) {
  14.     bmpdata[(x+XSIZE*(YSIZE-1-y))*3+54] = c&0xFF;
  15.     bmpdata[(x+XSIZE*(YSIZE-1-y))*3+55] = (c>>8)&0xFF;
  16.     bmpdata[(x+XSIZE*(YSIZE-1-y))*3+56] = (c>>16)&0xFF;
  17. }
  18.  
  19. struct MTwist{
  20.     int MT[624];
  21.     int index;
  22.     MTwist(){index=0;seed(2);seed(get());}
  23.     void seed(int seed){
  24.         MT[0]=seed;for(int i=1;i<624;i++)MT[i]=(-1)&(1812433253*(MT[i-1]^((MT[i-1])>>30))+i);//0x6C078965
  25.     }
  26.     int get(){
  27.         if(!index)genN();int y=MT[index];y^=y>>11;
  28.         y^=(y<<7)&2636928640;//0x9D2C5680
  29.         y^=(y<<15)&4022730752;//0xEFC60000
  30.         y^=y>>18;index=(++index)%624;return y;
  31.     }
  32.     void genN(){
  33.         for(int i=0;i<624;i++){int y=((MT[i]>>31)&1)+(0x7FFFFFFF&(MT[(i+1)%624]));
  34.             MT[i]=MT[(i+397)%624]^(y>>1);if(y&1)MT[i]^=2567483615;//0x9908B0DF
  35.         }
  36.     }
  37. };
  38.  
  39. MTwist rnd;
  40.  
  41. int main() {
  42.     rnd.seed(time(0));
  43.     int fsize = SIZE*SIZE*3+54; //54 bytes header
  44.     bmpdata = (char*)malloc(fsize);
  45.     for(int i=0;i<54;i++)bmpdata[i]=0;
  46.     bmpdata[0] = 'B'; //magic
  47.     bmpdata[1] = 'M';
  48.     bmpdata[2] = fsize&0xFF; //file size
  49.     bmpdata[3] = (fsize>>8)&0xFF;
  50.     bmpdata[4] = (fsize>>16)&0xFF;
  51.     bmpdata[5] = (fsize>>24)&0xFF;
  52.     bmpdata[10] = 54; //bitmap data offset
  53.     bmpdata[14] = 40; //header size after this
  54.     bmpdata[18] = XSIZE&0xFF; //x
  55.     bmpdata[19] = (XSIZE&0xFF00)>>8;
  56.     bmpdata[22] = YSIZE&0xFF; //y
  57.     bmpdata[23] = (YSIZE&0xFF00)>>8;
  58.     bmpdata[26] = 1; //planes
  59.     bmpdata[28] = 24; //bpp
  60.     fsize -= 54;
  61.     bmpdata[34] = fsize&0xFF; //bitmap data size
  62.     bmpdata[35] = (fsize>>8)&0xFF;
  63.     bmpdata[36] = (fsize>>16)&0xFF;
  64.     bmpdata[37] = (fsize>>24)&0xFF;
  65.     fsize += 54;
  66.     bmpdata[38] = 0x13; //x dpi|ppm
  67.     bmpdata[39] = 0x0B;
  68.     bmpdata[42] = 0x13; //y dpi|ppm
  69.     bmpdata[43] = 0x0B;
  70.     //do stuff here
  71.     ofstream output;
  72.     char* fname = (char*)malloc(128);
  73.     sprintf(fname, &quot;test%.4u.bmp&quot;, 0);
  74.     output.open(fname, fstream::binary|fstream::out|fstream::trunc);
  75.     output.write(bmpdata, fsize);
  76.     output.flush();
  77.     output.close();
  78.     return 0;
  79. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×