Y_Less

bmp.pwn

Feb 19th, 2012
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.35 KB | None | 0 0
  1. // This is a comment
  2. // uncomment the line below if you want to write a filterscript
  3. //#define FILTERSCRIPT
  4.  
  5. #pragma dynamic 16680064
  6.  
  7. #include <a_samp>
  8. #include <YSI\y_colours>
  9.  
  10. new
  11.     gAlphabet[10][26 + 1 + 10 + 1] =
  12.     {
  13.         // A     B     C     D     E     F     G     H     I     J     K     L     M     N     O     P     Q     R     S     T     U     V     W     X     Y     Z           0     1     2     3     4     5     6     7     8     9     ~
  14.         {0x30, 0xFC, 0x3C, 0xF8, 0xFE, 0xFE, 0x3C, 0xCC, 0x78, 0x1E, 0xE6, 0xF0, 0xC6, 0xC6, 0x38, 0xFC, 0x38, 0xFC, 0x78, 0xFC, 0xCC, 0xCC, 0xC6, 0xCC, 0xCC, 0xFE, 0x00, 0x7C, 0x10, 0x78, 0x78, 0x0C, 0xFC, 0x38, 0xFE, 0x78, 0x78, 0x73},
  15.         {0x78, 0x66, 0x66, 0x6C, 0x62, 0x66, 0x66, 0xCC, 0x30, 0x0C, 0x66, 0x60, 0xEE, 0xC6, 0x6C, 0x66, 0x6C, 0x66, 0xCC, 0xB4, 0xCC, 0xCC, 0xC6, 0xCC, 0xCC, 0xCE, 0x00, 0xC6, 0x30, 0xCC, 0xCC, 0x1C, 0xC0, 0x60, 0xC6, 0xCC, 0xCC, 0xDA},
  16.         {0xCC, 0x66, 0xC6, 0x66, 0x60, 0x62, 0xC6, 0xCC, 0x30, 0x0C, 0x6C, 0x60, 0xFE, 0xE6, 0xC6, 0x66, 0xC6, 0x66, 0xCC, 0x30, 0xCC, 0xCC, 0xC6, 0xCC, 0xCC, 0x98, 0x00, 0xCE, 0xF0, 0xCC, 0x0C, 0x3C, 0xC0, 0xC0, 0xC6, 0xCC, 0xCC, 0xCE},
  17.         {0xCC, 0x66, 0xC0, 0x66, 0x64, 0x64, 0xC0, 0xCC, 0x30, 0x0C, 0x6C, 0x60, 0xFE, 0xF6, 0xC6, 0x66, 0xC6, 0x66, 0xC0, 0x30, 0xCC, 0xCC, 0xC6, 0x78, 0xCC, 0x18, 0x00, 0xDE, 0x30, 0x0C, 0x0C, 0x6C, 0xC0, 0xC0, 0x06, 0xCC, 0xCC, 0x00},
  18.         {0xCC, 0x7C, 0xC0, 0x66, 0x7C, 0x7C, 0xC0, 0xFC, 0x30, 0x0C, 0x78, 0x60, 0xD6, 0xFE, 0xC6, 0x7C, 0xC6, 0x7C, 0x70, 0x30, 0xCC, 0xCC, 0xD6, 0x30, 0x78, 0x30, 0x00, 0xD6, 0x30, 0x18, 0x38, 0xCC, 0xF8, 0xF8, 0x0C, 0x78, 0x7C, 0x00},
  19.         {0xFC, 0x66, 0xC0, 0x66, 0x64, 0x64, 0xCE, 0xCC, 0x30, 0xCC, 0x6C, 0x62, 0xC6, 0xDE, 0xC6, 0x60, 0xCE, 0x6C, 0x18, 0x30, 0xCC, 0xCC, 0xD6, 0x78, 0x30, 0x60, 0x00, 0xF6, 0x30, 0x30, 0x0C, 0xFE, 0x0C, 0xCC, 0x18, 0xCC, 0x18, 0x00},
  20.         {0xCC, 0x66, 0xC6, 0x66, 0x60, 0x60, 0xC6, 0xCC, 0x30, 0xCC, 0x6C, 0x66, 0xC6, 0xCE, 0xC6, 0x60, 0xDE, 0x66, 0xCC, 0x30, 0xCC, 0xCC, 0x6C, 0xCC, 0x30, 0x62, 0x00, 0xE6, 0x30, 0x60, 0x0C, 0x0C, 0x0C, 0xCC, 0x30, 0xCC, 0x18, 0x00},
  21.         {0xCC, 0x66, 0x66, 0x6C, 0x62, 0x60, 0x66, 0xCC, 0x30, 0xCC, 0x66, 0x66, 0xC6, 0xC6, 0x6C, 0x60, 0x7C, 0x66, 0xCC, 0x30, 0xCC, 0x78, 0x6C, 0xCC, 0x30, 0xC6, 0x00, 0xC6, 0x30, 0xCC, 0xCC, 0x0C, 0xCC, 0xCC, 0x30, 0xCC, 0x30, 0x00},
  22.         {0xCC, 0xFC, 0x3C, 0xF8, 0xFE, 0xF0, 0x3E, 0xCC, 0x78, 0x78, 0xE6, 0xFE, 0xC6, 0xC6, 0x38, 0xF0, 0x0C, 0xE6, 0x78, 0x78, 0x78, 0x30, 0x6C, 0xCC, 0x78, 0xFE, 0x00, 0x7C, 0xFC, 0xFC, 0x78, 0x1E, 0x78, 0x78, 0x30, 0x78, 0x70, 0x00},
  23.         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
  24.     };
  25.  
  26. AddLetter(colour, letter, data[][], &x, &y)
  27. {
  28.     if ('a' <= letter <= 'z') letter -= 'a';
  29.     else if ('A' <= letter <= 'Z') letter -= 'A';
  30.     else if ('0' <= letter <= '9') letter = letter - '0' + 27;
  31.     else if (letter == '~') letter = 26 + 1 + 10;
  32.     else letter = 26;
  33.     for (new j = 0; j != 10; ++j)
  34.     {
  35.         for (new i = 0, k = 0x80; i != 8; ++i, k >>= 1)
  36.         {
  37.             if (gAlphabet[j][letter] & k) data[y + j][x + i] = colour;
  38.         }
  39.     }
  40.     x += 8;
  41. }
  42.  
  43. AddBlock(colour, data[][], &x, &y, width)
  44. {
  45.     for (new j = 0; j != 50; ++j)
  46.     {
  47.         for (new i = 0; i != 200; ++i)
  48.         {
  49.             data[y + j][x + i] = colour;
  50.         }
  51.     }
  52.     x += 202;
  53.     if (x == width)
  54.     {
  55.         x = 2;
  56.         y += 52;
  57.     }
  58. }
  59.  
  60. AddString(colour, str[], data[][], &x, &y)
  61. {
  62.     for (new i = 0, ch; (ch = str[i]); ++i)
  63.     {
  64.         AddLetter(colour, ch, data, x, y);
  65.     }
  66. }
  67.  
  68. AddColour(colour, name[], data[][], &x, &y)
  69. {
  70.     new
  71.         ox = x + 10,
  72.         oy = y + 20;
  73.     colour >>>= 8;
  74.     printf("%08x", colour);
  75.     AddBlock(colour, data, x, y, 202 * 5 + 2);
  76.     if (colour >> 16 & 0xFF < 32 && colour >> 8 & 0xFF < 32 && colour & 0xFF < 32)
  77.     {
  78.         // White (on dark).
  79.         AddString(0xFFFFFF, name, data, ox, oy);
  80.     }
  81.     else
  82.     {
  83.         // Black (on most).
  84.         AddString(0x000000, name, data, ox, oy);
  85.     }
  86. }
  87.  
  88. #define DO_X11(X11_%0) AddColour(X11_%0, #%0, gGridData, x, y)
  89.  
  90. #define DO_GT(%0,%1) AddColour(SAMP_GAME_TEXT%0, #%1, gGridData, x, y)
  91.  
  92. main()
  93. {
  94.     print("\n----------------------------------");
  95.     print(" Blank Gamemode by your name here");
  96.     print("----------------------------------\n");
  97.     new
  98.         gGridData[1400 / 5 * 52 + 2][202 * 5 + 2]; // = {0xFF0000, ...};
  99.     new
  100.         x = 2,
  101.         y = 2;
  102. //  AddString(-1, "Hello There", gGridData, x, y);
  103. #include "x11.pwn"
  104.     WriteBMP(gGridData, sizeof (gGridData), sizeof (gGridData[]));
  105. }
  106.  
  107. MKLE32(dest[], num)
  108. {
  109.     dest[0] = num & 0xFF;
  110.     dest[1] = num >>> 8 & 0xFF;
  111.     dest[2] = num >>> 16 & 0xFF;
  112.     dest[3] = num >>> 24 & 0xFF;
  113. }
  114.  
  115. /*Inv(dest[], idx)
  116. {
  117.     dest[idx] = (dest[idx] >>> 24) | (dest[idx] & 0xFF0000 >> 8) | (dest[idx] & 0xFF00 << 8) | (dest[idx] & 0xFF << 24);
  118. }
  119.  
  120. MK24(dest[], num, &idx)
  121. {
  122.     dest{idx++} = num >>> 16 & 0xFF;
  123.     if (idx & 0x07 == 0x04) Inv(dest, idx >> 2);
  124.     dest{idx++} = num >>> 8 & 0xFF;
  125.     if (idx & 0x07 == 0x04) Inv(dest, idx >> 2);
  126.     dest{idx++} = num & 0xFF;
  127.     if (idx & 0x07 == 0x04) Inv(dest, idx >> 2);
  128. }
  129.  
  130. Pad(dest[], &idx)
  131. {
  132.     while (idx & 0x03)
  133.     {
  134.         dest{idx++} = 0;
  135.     }
  136.     if (idx & 0x07 == 0x04) Inv(dest, idx >> 2);
  137. }*/
  138.  
  139. MK24(dest[], num, &idx)
  140. {
  141.     dest[idx++] = num & 0xFF;
  142.     dest[idx++] = num >>> 8 & 0xFF;
  143.     dest[idx++] = num >>> 16 & 0xFF;
  144. }
  145.  
  146. Pad(dest[], &idx)
  147. {
  148.     while (idx & 0x03)
  149.     {
  150.         dest[idx++] = 0;
  151.     }
  152. }
  153.  
  154. WriteBMP(data[][], y, x)
  155. {
  156.     new
  157.         File:bmp = fopen("x11_colours.bmp", io_write);
  158.     if (!bmp)
  159.     {
  160.         printf("File Error");
  161.         return;
  162.     }
  163.     printf("header");
  164.     // Sizes are little endian.
  165.     static
  166.         sFileHeader[] =
  167.         {
  168.             'B', 'M', // bfType
  169.             1, 1, 1, 1, // bfSize
  170.             0, 0, // bfReserved1
  171.             0, 0, // bfReserved2
  172.             2, 2, 2, 2 // bfOffBits
  173.         },
  174.         sInfoHeader[] =
  175.         {
  176.             40, 0, 0, 0, // biSize
  177.             4, 4, 4, 4, // biWidth
  178.             5, 5, 5, 5, // biHeight
  179.             0, 0, // biPlanes
  180.             24, 0, // biBitCount
  181.             0, 0, 0, 0, // biCompression
  182.             0, 0, 0, 0, // biSizeImage
  183.             0, 0, 0, 0, // biXPelsPerMeter
  184.             0, 0, 0, 0, // biYPelsPerMeter
  185.             0, 0, 0, 0, // biClrUsed
  186.             0, 0, 0, 0 // biClrImportant
  187.         };
  188.     MKLE32(sInfoHeader[4], x);
  189.     MKLE32(sInfoHeader[8], y);
  190.     MKLE32(sFileHeader[2], x * y * 3 + sizeof (sFileHeader) + sizeof (sInfoHeader));
  191.     MKLE32(sFileHeader[10], sizeof (sFileHeader) + sizeof (sInfoHeader));
  192.     printf("write");
  193.     for (new j = 0; j != sizeof (sFileHeader); ++j)
  194.     {
  195.         fputchar(bmp, sFileHeader[j], false);
  196.     }
  197.     for (new j = 0; j != sizeof (sInfoHeader); ++j)
  198.     {
  199.         fputchar(bmp, sInfoHeader[j], false);
  200.     }
  201.     //fblockwrite(bmp, sFileHeader, sizeof (sFileHeader));
  202.     //fblockwrite(bmp, sInfoHeader, sizeof (sInfoHeader));
  203.     printf("body");
  204.     static
  205.         sRow[(202 * 5 + 2) * 3];
  206.     for (new i = y; i-- > 0; )
  207.     {
  208.         //printf("row %d", i);
  209.         // Go through the array backwards (bottom to top).
  210.         new
  211.             idx;
  212.         for (new j = 0; j != x; ++j)
  213.         {
  214.             MK24(sRow, data[i][j], idx);
  215.         }
  216.         Pad(sRow, idx);
  217.         //printf("%04x%04x %04x%04x %04x%04x", sRow[0] >>> 16, sRow[0] & 0xFFFF, sRow[1] >>> 16, sRow[1] & 0xFFFF, sRow[2] >>> 16, sRow[2] & 0xFFFF);
  218.         //strpack(sRow, sRow, idx);
  219.         //fblockwrite(bmp, sRow, idx >> 2);
  220.         for (new j = 0; j != idx; ++j) //j += 4)
  221.         {
  222.             /*sChar{0} = sRow[j + 0];
  223.             sChar{1} = sRow[j + 1];
  224.             sChar{2} = sRow[j + 2];
  225.             sChar{3} = sRow[j + 3];
  226.             fblockwrite(bmp, sChar, 1);*/
  227.             fputchar(bmp, sRow[j], false);
  228.             //fseek(bmp, -3, seek_current);
  229.         }
  230.     }
  231.     printf("done");
  232.     fclose(bmp);
  233. }
Advertisement
Add Comment
Please, Sign In to add comment