Advertisement
Guest User

dynamic pixmap

a guest
Mar 26th, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1.  
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <conio.h>
  5. #include <iostream>
  6.  
  7.  
  8. class pixmap
  9. {
  10. private:
  11.     char _cols;
  12.     int _width, _height;
  13.     char **pix_m;
  14. public:
  15.     pixmap(int , int);
  16.     uint8_t getpixel(int, int);
  17.     void printl(int);
  18.  
  19. };
  20.  
  21. pixmap::pixmap(int width, int height)
  22. {
  23.     _width = width;
  24.     _height = height;
  25.     _cols = width/8+1;
  26.  
  27.     pix_m = (char**) (calloc(height,_cols));
  28.     for (int x =0 ; x < _cols; x++)
  29.     {
  30.            pix_m[x] = (char*)calloc(_cols,sizeof(char*));
  31.     }
  32.  
  33.     printf("%d\r\n",_cols);
  34. }
  35.  
  36. void pixmap::printl(int y)
  37. {
  38.     int pix;
  39.     for (int i = 0; i < _cols-1; i++)
  40.     {
  41.         for (int x= 0; x<8; x++)
  42.         {
  43.             pix = pix_m[y][i]&(0x01<<(7-x));
  44.             printf("%d",pix!=0);
  45.         }
  46.     }
  47.     int q = _width - (_cols-1)*8;
  48.     for (int x= 0; x<q; x++)
  49.     {
  50.         pix = pix_m[y][_cols-1]&(0x01<<(7-x));
  51.         printf("%d",pix!=0);
  52.     }
  53. }
  54. /*
  55. uint8_t imaq::getpixel(int x , int y)
  56. {
  57.     uint8_t q = (x)/8;
  58.     uint8_t mask = 0x80 >> x%8;
  59.     return((pix_x[q]& mask)!=0);
  60. }*/
  61.  
  62.  
  63.  
  64. int main()
  65. {
  66.     pixmap img(50,100);
  67.     img.printl(1);
  68.  
  69.     printf("\r\n");
  70.     /*for (int i=0 ; i <50; i++)
  71.     {
  72.         printf("%d",img.getpixel(i,0));
  73.     }*/
  74.  
  75.     getch();
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement