Guest User

Untitled

a guest
May 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. // testBMP.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include <iostream>
  5. #include <fstream> //подключили библиотеку для работы с map
  6. #include "conio.h"
  7.  
  8. //using namespace std;
  9. void write(char *img, char *msg);
  10. void read();
  11.  
  12. void main()
  13. {
  14. read();
  15. write(/*KUKUSIKI*/, "Hello!");
  16. system("pause");
  17. }
  18. void write(char *img, char *msg) {
  19.  
  20. std::ofstream os("temp.bmp", std::ios::binary);
  21.  
  22. unsigned char signature[2] = { 'B', 'M' };
  23. unsigned int fileSize = 14 + 40 + 1000 * 1000 * 4;
  24. unsigned int reserved = 0;
  25. unsigned int offset = 14 + 40;
  26.  
  27. unsigned int headerSize = 40;
  28. unsigned int dimensions[2] = { 1000, 1000 };
  29. unsigned short colorPlanes = 1;
  30. unsigned short bpp = 32;
  31. unsigned int compression = 0;
  32. unsigned int imgSize = 1000 * 1000 * 4;
  33. unsigned int resolution[2] = { 2795, 2795 };
  34. unsigned int pltColors = 0;
  35. unsigned int impColors = 0;
  36.  
  37. os.write(reinterpret_cast<char*>(signature), sizeof(signature));
  38. os.write(reinterpret_cast<char*>(&fileSize), sizeof(fileSize));
  39. os.write(reinterpret_cast<char*>(&reserved), sizeof(reserved));
  40. os.write(reinterpret_cast<char*>(&offset), sizeof(offset));
  41.  
  42. os.write(reinterpret_cast<char*>(&headerSize), sizeof(headerSize));
  43. os.write(reinterpret_cast<char*>(dimensions), sizeof(dimensions));
  44. os.write(reinterpret_cast<char*>(&colorPlanes), sizeof(colorPlanes));
  45. os.write(reinterpret_cast<char*>(&bpp), sizeof(bpp));
  46. os.write(reinterpret_cast<char*>(&compression), sizeof(compression));
  47. os.write(reinterpret_cast<char*>(&imgSize), sizeof(imgSize));
  48. os.write(reinterpret_cast<char*>(resolution), sizeof(resolution));
  49. os.write(reinterpret_cast<char*>(&pltColors), sizeof(pltColors));
  50. os.write(reinterpret_cast<char*>(&impColors), sizeof(impColors));
  51.  
  52. unsigned char x, r, g, b;
  53. unsigned msg_size = strlen(msg);
  54. unsigned msg_pos = 0;
  55. for (int i = 0; i < dimensions[1] * dimensions[0] * 4; ++i)
  56. {
  57. b = img[i++];
  58. g = img[i++];
  59. r = img[i++];
  60. x = img[i++];
  61. /*x = 0;
  62. b = 0;
  63. g = 0;
  64. r = rand() % 256;
  65. g = rand() % 256;
  66. b = rand() % 256;
  67.  
  68. if (i > 100 && i < 900)//квадратик
  69. if(j > 100 && j < 900)
  70. r = 255;*/
  71. if (msg_pos <= msg_size) {
  72. char ch = msg[msg_pos];
  73. char ar = (ch & 0b11100000) >> 5;
  74. char ag = (ch & 0b00011100) >> 2;
  75. char ab = (ch & 0b00000011);
  76.  
  77. r ^= ar;
  78. g ^= ag;
  79. b ^= ab;
  80.  
  81. msg_pos++;
  82. }
  83.  
  84. os.write(reinterpret_cast<char*>(&b), sizeof(b));
  85. os.write(reinterpret_cast<char*>(&g), sizeof(g));
  86. os.write(reinterpret_cast<char*>(&r), sizeof(r));
  87. os.write(reinterpret_cast<char*>(&x), sizeof(x));
  88.  
  89. }
  90.  
  91. os.close();
  92. }
  93.  
  94. void read()
  95.  
  96. {
  97. std::ifstream os("temp.bmp", std::ios::binary);
  98.  
  99. unsigned char signature[2] = { 'B', 'M' };
  100. unsigned int fileSize = 14 + 40 + 1000 * 1000 * 4;
  101. unsigned int reserved = 0;
  102. unsigned int offset = 14 + 40;
  103.  
  104. unsigned int headerSize = 40;
  105. unsigned int dimensions[2] = { 1000, 1000 };
  106. unsigned short colorPlanes = 1;
  107. unsigned short bpp = 32;
  108. unsigned int compression = 0;
  109. unsigned int imgSize = 1000 * 1000 * 4;
  110. unsigned int resolution[2] = { 2795, 2795 };
  111. unsigned int pltColors = 0;
  112. unsigned int impColors = 0;
  113.  
  114. os.read(reinterpret_cast<char*>(signature), sizeof(signature)); cout << "signature=" << signature << endl;
  115. os.read(reinterpret_cast<char*>(&fileSize), sizeof(fileSize)); cout << "fileSize=" << fileSize << endl;
  116. os.read(reinterpret_cast<char*>(&reserved), sizeof(reserved)); cout << "reserved=" << reserved << endl;
  117. os.read(reinterpret_cast<char*>(&offset), sizeof(offset));
  118.  
  119. os.read(reinterpret_cast<char*>(&headerSize), sizeof(headerSize)); cout << "headerSize=" << headerSize << endl;
  120. os.read(reinterpret_cast<char*>(dimensions), sizeof(dimensions)); cout << "dimensions=" << dimensions[0] << " " << dimensions[1] << endl;
  121. os.read(reinterpret_cast<char*>(&colorPlanes), sizeof(colorPlanes)); cout << "colorPlanes=" << colorPlanes << endl;
  122. os.read(reinterpret_cast<char*>(&bpp), sizeof(bpp)); cout << "bpp=" << bpp << endl;
  123. os.read(reinterpret_cast<char*>(&compression), sizeof(compression)); cout << "compression=" << compression << endl;
  124. os.read(reinterpret_cast<char*>(&imgSize), sizeof(imgSize)); cout << "imgSize=" << imgSize << endl;
  125. os.read(reinterpret_cast<char*>(resolution), sizeof(resolution)); cout << "resolution=" << resolution[0] << " " << resolution[1] << endl;
  126. os.read(reinterpret_cast<char*>(&pltColors), sizeof(pltColors)); cout << "pltColors=" << pltColors << endl;
  127. os.read(reinterpret_cast<char*>(&impColors), sizeof(impColors)); cout << "impColors=" << impColors << endl;
  128.  
  129. char *img;
  130. unsigned char x, r, g, b;
  131.  
  132. for (int i = 0; i < dimensions[1]; ++i)
  133. {
  134. for (int j = 0; j < dimensions[0]; ++j)
  135. {
  136.  
  137. os >> b;
  138. os >> g;
  139. os >> r;
  140. os >> x;
  141.  
  142. img[i*dimensions[1] + j] = b;
  143. img[i*dimensions[1] + j + 1] = g;
  144. img[i*dimensions[1] + j + 2] = r;
  145. img[i*dimensions[1] + j+ 3 ] = x;
  146. }
  147. }
  148. //getch();
  149. }
  150.  
  151. void Change() {
  152.  
  153. }
Add Comment
Please, Sign In to add comment