Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 6th, 2020 143 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6. void main()
  7. {
  8.     string sFileName;
  9.     BITMAPFILEHEADER bmpFileHeader;
  10.     BITMAPINFOHEADER bmpInfoHeader;
  11.     int Width, Height;
  12.     RGBQUAD Palette[256];
  13.     RGBTRIPLE* inBuf;
  14.     BYTE* outBuf;
  15.     HANDLE hInputFile, hOutFile;
  16.     DWORD RW;
  17.     hInputFile = CreateFile(L"\\\\mac\\home\\Documents\\Untitled.bmp", GENERIC_READ, FILE_SHARE_READ, NULL,
  18.         OPEN_EXISTING, 0, NULL);
  19.     if (hInputFile == INVALID_HANDLE_VALUE)
  20.         return;
  21.     hOutFile = CreateFile(L"\\\\mac\\home\\Documents\\Result.bmp", GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
  22.     if (hOutFile == INVALID_HANDLE_VALUE)
  23.     {
  24.  
  25.         CloseHandle(hInputFile);
  26.         return;
  27.     }
  28.     // Считываем инфу
  29.     ReadFile(hInputFile, &bmpFileHeader, sizeof(bmpFileHeader), &RW, NULL);
  30.     ReadFile(hInputFile, &bmpInfoHeader, sizeof(bmpInfoHeader), &RW, NULL);
  31.  
  32.     // Установим указатель на начало растра
  33.     SetFilePointer(hInputFile, bmpFileHeader.bfOffBits, NULL, FILE_BEGIN);
  34.     Width = bmpInfoHeader.biWidth;
  35.     Height = bmpInfoHeader.biHeight;
  36.     // Выделим память
  37.     inBuf = new RGBTRIPLE[Width];
  38.     outBuf = new BYTE[Width];
  39.     // Заполним заголовки
  40.     bmpFileHeader.bfOffBits = sizeof(bmpFileHeader) + sizeof(bmpInfoHeader) + 1024;
  41.     bmpInfoHeader.biBitCount = 8;
  42.     bmpFileHeader.bfSize = bmpFileHeader.bfOffBits + Width * Height + Height * (Width % 4);
  43.     // Запишем заголовки
  44.     WriteFile(hOutFile, &bmpFileHeader, sizeof(bmpFileHeader), &RW, NULL);
  45.     WriteFile(hOutFile, &bmpInfoHeader, sizeof(bmpInfoHeader), &RW, NULL);
  46.     // Палитра черно-белая
  47.     for (int i = 0; i < 8; i++)
  48.     {
  49.         for (int j = 0; j < 8; j++)
  50.         {
  51.             for (int k = 0; k < 4; k++)
  52.             {
  53.                 Palette[i * 32 + j * 4 + k].rgbRed = i * 32;
  54.                 Palette[i * 32 + j * 4 + k].rgbGreen = j * 32;
  55.                 Palette[i * 32 + j * 4 + k].rgbBlue = k * 64;
  56.             }
  57.         }
  58.     }
  59.     WriteFile(hOutFile, Palette, 256 * sizeof(RGBQUAD), &RW, NULL);
  60.     // Начнем преобразовывать
  61.     for (int i = 0; i < Height; i++)
  62.     {
  63.         ReadFile(hInputFile, inBuf, sizeof(RGBTRIPLE) * Width, &RW, NULL);
  64.         for (int j = 0; j < Width; j++)
  65.             outBuf[j] = 32 * (inBuf[j].rgbtRed / 32) + 4 * (inBuf[j].rgbtGreen / 32) + inBuf[j].rgbtBlue / 64;
  66.         WriteFile(hOutFile, outBuf, sizeof(BYTE) * Width, &RW, NULL);
  67.         // Пишем мусор для выравнивания
  68.         WriteFile(hOutFile, Palette, (Width) % 4, &RW, NULL);
  69.         SetFilePointer(hInputFile, (Width * sizeof(RGBTRIPLE)) % 4, NULL, FILE_CURRENT);
  70.     }
  71.     delete[] inBuf;
  72.     delete[] outBuf;
  73.     CloseHandle(hInputFile);
  74.     CloseHandle(hOutFile);
  75.     cout << "Updating has come to the end successfully!";
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top