Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Sharpen filter of bmp image

Sharpen filter of bmp image

Scheduled Pinned Locked Moved Managed C++/CLI
iosgraphicsdata-structureshelpquestion
2 Posts 2 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jakub Bartczak
    wrote on last edited by
    #1

    need some help with my code, I tried in many ways to make simple filtering image with array 3x3, but cant make it. any ideas how shall I start it?

    #include
    #include
    #include
    #include
    #include

    using namespace std;

    //BMP header
    typedef struct tagBITMAPFILEHEADER {
    unsigned short bfType;
    unsigned int bfSize;
    short bfReserved1;
    short bfReserved2;
    unsigned int bfOffBits;
    } BITMAPFILEHEADER;
    //BMP header
    typedef struct tagBITMAPINFOHEADER {
    unsigned int biSize;
    int biWidth;
    int biHeight;
    unsigned short biPlanes;
    unsigned short biBitCount;
    unsigned int biCompression;
    unsigned int biSizeImage;
    int biXpelsPerMeter;
    int biYpelsPerMeter;
    unsigned int biClrUses;
    unsigned int biClrImportant;
    } BITMAPINFOHEADER;

    int odczytajBFH(ifstream &ifs, BITMAPFILEHEADER &bfh);
    int odczytajBIH(ifstream &ifs, BITMAPINFOHEADER &bih, int kursor);
    void zapiszBFH(ofstream &ofs, BITMAPFILEHEADER &bfh);
    void zapiszBIH(ofstream &ofs, BITMAPINFOHEADER &bih);

    unsigned char* odczytajDaneObrazu(ifstream &ifs, unsigned int rozmiar, int kursor);
    void odczytajRGB(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
    unsigned char * polaczRGB(int **niebieski, int **zielony, int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
    void zwolnij_pamiec(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, int wysokosc);
    void zapiszDaneObrazu(ofstream &ofs, unsigned char *obraz, unsigned int rozmiar);

    int main()
    {
    BITMAPFILEHEADER bfh;
    BITMAPINFOHEADER bih;
    string str = "bitmap.bmp";
    const char * nazwa_pliku = str.c_str();
    ifstream ifs(nazwa_pliku, ios::binary) ;
    if( !ifs.is_open() )
    {
    cout << "\nBlad otwarcia pliku";
    return 0;
    }
    ofstream ofs("out.bmp", ios::binary);

    int kursor = odczytajBFH(ifs, bfh);
    kursor = odczytajBIH(ifs, bih, kursor);
    zapiszBFH(ofs, bfh);
    zapiszBIH(ofs, bih);
    unsigned int rozmiar = bfh.bfSize - bfh.bfOffBits;
    int szerokosc = bih.biWidth;
    int wysokosc = bih.biHeight;

    u

    J 1 Reply Last reply
    0
    • J Jakub Bartczak

      need some help with my code, I tried in many ways to make simple filtering image with array 3x3, but cant make it. any ideas how shall I start it?

      #include
      #include
      #include
      #include
      #include

      using namespace std;

      //BMP header
      typedef struct tagBITMAPFILEHEADER {
      unsigned short bfType;
      unsigned int bfSize;
      short bfReserved1;
      short bfReserved2;
      unsigned int bfOffBits;
      } BITMAPFILEHEADER;
      //BMP header
      typedef struct tagBITMAPINFOHEADER {
      unsigned int biSize;
      int biWidth;
      int biHeight;
      unsigned short biPlanes;
      unsigned short biBitCount;
      unsigned int biCompression;
      unsigned int biSizeImage;
      int biXpelsPerMeter;
      int biYpelsPerMeter;
      unsigned int biClrUses;
      unsigned int biClrImportant;
      } BITMAPINFOHEADER;

      int odczytajBFH(ifstream &ifs, BITMAPFILEHEADER &bfh);
      int odczytajBIH(ifstream &ifs, BITMAPINFOHEADER &bih, int kursor);
      void zapiszBFH(ofstream &ofs, BITMAPFILEHEADER &bfh);
      void zapiszBIH(ofstream &ofs, BITMAPINFOHEADER &bih);

      unsigned char* odczytajDaneObrazu(ifstream &ifs, unsigned int rozmiar, int kursor);
      void odczytajRGB(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
      unsigned char * polaczRGB(int **niebieski, int **zielony, int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
      void zwolnij_pamiec(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, int wysokosc);
      void zapiszDaneObrazu(ofstream &ofs, unsigned char *obraz, unsigned int rozmiar);

      int main()
      {
      BITMAPFILEHEADER bfh;
      BITMAPINFOHEADER bih;
      string str = "bitmap.bmp";
      const char * nazwa_pliku = str.c_str();
      ifstream ifs(nazwa_pliku, ios::binary) ;
      if( !ifs.is_open() )
      {
      cout << "\nBlad otwarcia pliku";
      return 0;
      }
      ofstream ofs("out.bmp", ios::binary);

      int kursor = odczytajBFH(ifs, bfh);
      kursor = odczytajBIH(ifs, bih, kursor);
      zapiszBFH(ofs, bfh);
      zapiszBIH(ofs, bih);
      unsigned int rozmiar = bfh.bfSize - bfh.bfOffBits;
      int szerokosc = bih.biWidth;
      int wysokosc = bih.biHeight;

      u

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      I don't know Polish so that it is really hard to retrace the code. But you missed some points:

      • There are two versions of info headers with different sizes which can be identified using the biSize member: BITMAPINFOHEADER and BITMAPV5HEADER
      • When biCompression is BI_BITFIELDS, these bitfields are stored after the info header.
      • Your code supports only 24-bit RGB bitmaps. So you should check if the file is in that format (biBitCount == 24).

      You can read the pixel data from file offset bfOffBits with size biSizeImage which includes the padding bytes. But your code starts reading after the info header which is the location of the bitfields table or still within a BITMAPV5HEADER.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups