Exemplo n.º 1
0
    //static
    //------------------------------------------------------------------------
    BITMAPINFO* pixel_map::create_bitmap_info(unsigned width, 
                                              unsigned height, 
                                              unsigned bits_per_pixel)
    {
        unsigned line_len = calc_row_len(width, bits_per_pixel);
        unsigned img_size = line_len * height;
        unsigned rgb_size = calc_palette_size(0, bits_per_pixel) * sizeof(RGBQUAD);
        unsigned full_size = sizeof(BITMAPINFOHEADER) + rgb_size + img_size;

        BITMAPINFO *bmp = (BITMAPINFO *) new unsigned char[full_size];

        bmp->bmiHeader.biSize   = sizeof(BITMAPINFOHEADER);
        bmp->bmiHeader.biWidth  = width;
        bmp->bmiHeader.biHeight = height;
        bmp->bmiHeader.biPlanes = 1;
        bmp->bmiHeader.biBitCount = (unsigned short)bits_per_pixel;
        bmp->bmiHeader.biCompression = 0;
        bmp->bmiHeader.biSizeImage = img_size;
        bmp->bmiHeader.biXPelsPerMeter = 0;
        bmp->bmiHeader.biYPelsPerMeter = 0;
        bmp->bmiHeader.biClrUsed = 0;
        bmp->bmiHeader.biClrImportant = 0;

        return bmp;
    }
Exemplo n.º 2
0
    //static
    //------------------------------------------------------------------------
    unsigned pixel_map::calc_full_size(BITMAPINFO *bmp)
    {
        if(bmp == 0) return 0;

        return sizeof(BITMAPINFOHEADER) +
               sizeof(RGBQUAD) * calc_palette_size(bmp) +
               bmp->bmiHeader.biSizeImage;
    }
Exemplo n.º 3
0
unsigned dib_display::calc_palette_size(BITMAPINFO *bmp)
{
    if (bmp == 0)
    {
        return 0;
    } else {
        return calc_palette_size(bmp->bmiHeader.biClrUsed, bmp->bmiHeader.biBitCount);
    }
}
Exemplo n.º 4
0
unsigned dib_display::calc_header_size(BITMAPINFO *bmp)
{
    if (bmp == NULL)
    {
        return 0;
    } else {
        return sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * calc_palette_size(bmp);
    }
}
Exemplo n.º 5
0
    BImage* dib_display::create_image(const rendering_buffer* rbuf,
                                    unsigned bits_per_pixel)

    {
        DEBUG_MTH("dib_display::create_image");
        unsigned width = rbuf->width(); 
        unsigned height = rbuf->height();
        unsigned line_len = platform_specific::calc_row_len(width, bits_per_pixel);
        unsigned img_size = line_len * height;
        unsigned rgb_size = calc_palette_size(0, bits_per_pixel) * sizeof(RGBQUAD);
        unsigned full_size = sizeof(BITMAPINFOHEADER) + rgb_size;// + img_size;

        BITMAPINFO *bmp = (BITMAPINFO *) new unsigned char[full_size];

        bmp->bmiHeader.biSize   = sizeof(BITMAPINFOHEADER);
        bmp->bmiHeader.biWidth  = width;
        bmp->bmiHeader.biHeight = -height;
        bmp->bmiHeader.biPlanes = 1;
        bmp->bmiHeader.biBitCount = (unsigned short)bits_per_pixel;
        bmp->bmiHeader.biCompression = 0;
        bmp->bmiHeader.biSizeImage = img_size;
        bmp->bmiHeader.biXPelsPerMeter = 0;
        bmp->bmiHeader.biYPelsPerMeter = 0;
        bmp->bmiHeader.biClrUsed = 0;
        bmp->bmiHeader.biClrImportant = 0;

        RGBQUAD *rgb = (RGBQUAD*)(((unsigned char*)bmp) + sizeof(BITMAPINFOHEADER));
        unsigned brightness;
        unsigned i;
        for(i = 0; i < rgb_size; i++)
        {
            brightness = (255 * i) / (rgb_size - 1);
            rgb->rgbBlue =
            rgb->rgbGreen =  
            rgb->rgbRed = (unsigned char)brightness; 
            rgb->rgbReserved = 0;
            rgb++;
        }

        BImage* image = new BImage;
        image->bmp = bmp;
        image->data = (unsigned char*)rbuf->buf();

        return image;

    }
Exemplo n.º 6
0
    //static
    //------------------------------------------------------------------------
    void pixel_map::create_gray_scale_palette(BITMAPINFO *bmp)
    {
        if(bmp == 0) return;

        unsigned rgb_size = calc_palette_size(bmp);
        RGBQUAD *rgb = (RGBQUAD*)(((unsigned char*)bmp) + sizeof(BITMAPINFOHEADER));
        unsigned brightness;
        unsigned i;

        for(i = 0; i < rgb_size; i++)
        {
            brightness = (255 * i) / (rgb_size - 1);
            rgb->rgbBlue =
            rgb->rgbGreen =  
            rgb->rgbRed = (unsigned char)brightness; 
            rgb->rgbReserved = 0;
            rgb++;
        }
    }
Exemplo n.º 7
0
 //private
 //------------------------------------------------------------------------
 HBITMAP pixel_map::create_dib_section_from_args(HDC h_dc,
                                                 unsigned width, 
                                                 unsigned height, 
                                                 unsigned bits_per_pixel)
 {
     unsigned line_len  = calc_row_len(width, bits_per_pixel);
     unsigned img_size  = line_len * height;
     unsigned rgb_size  = calc_palette_size(0, bits_per_pixel) * sizeof(RGBQUAD);
     unsigned full_size = sizeof(BITMAPINFOHEADER) + rgb_size;
     
     BITMAPINFO *bmp = (BITMAPINFO *) new unsigned char[full_size];
     
     bmp->bmiHeader.biSize   = sizeof(BITMAPINFOHEADER);
     bmp->bmiHeader.biWidth  = width;
     bmp->bmiHeader.biHeight = height;
     bmp->bmiHeader.biPlanes = 1;
     bmp->bmiHeader.biBitCount = (unsigned short)bits_per_pixel;
     bmp->bmiHeader.biCompression = 0;
     bmp->bmiHeader.biSizeImage = img_size;
     bmp->bmiHeader.biXPelsPerMeter = 0;
     bmp->bmiHeader.biYPelsPerMeter = 0;
     bmp->bmiHeader.biClrUsed = 0;
     bmp->bmiHeader.biClrImportant = 0;
     
     void*   img_ptr  = 0;
     HBITMAP h_bitmap = ::CreateDIBSection(h_dc, bmp, DIB_RGB_COLORS, &img_ptr, NULL, 0);
     
     if(img_ptr)
     {
         m_img_size  = calc_row_len(width, bits_per_pixel) * height;
         m_full_size = 0;
         m_bmp       = bmp;
         m_buf       = (unsigned char *) img_ptr;
     }
     
     return h_bitmap;
 }
Exemplo n.º 8
0
 //static
 //------------------------------------------------------------------------
 unsigned pixel_map::calc_palette_size(BITMAPINFO *bmp)
 {
     if(bmp == 0) return 0;
     return calc_palette_size(bmp->bmiHeader.biClrUsed, bmp->bmiHeader.biBitCount);
 }
Exemplo n.º 9
0
 //static
 //------------------------------------------------------------------------
 unsigned pixel_map::calc_header_size(BITMAPINFO *bmp)
 {
     if(bmp == 0) return 0;
     return sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * calc_palette_size(bmp);
 }
Exemplo n.º 10
0
void Win32Window::drawImageGray(unsigned char *buffer, int width, int height, int x, int y)
{
    //TODO

    //create buffer
    unsigned char *tmpBuf = malloc(width * height);
    for (int i  = 0; i < ; ++i)
    {



    }

    //create paired BITMAP

    {
        unsigned line_len = calc_row_len(width, bits_per_pixel);
        unsigned img_size = line_len * height;
        unsigned rgb_size = calc_palette_size(0, bits_per_pixel) * sizeof(RGBQUAD);
        unsigned full_size = sizeof(BITMAPINFOHEADER) + rgb_size + img_size;

        BITMAPINFO *bmp = (BITMAPINFO *) new unsigned char[full_size];

        bmp->bmiHeader.biSize   = sizeof(BITMAPINFOHEADER);
        bmp->bmiHeader.biWidth  = width;
        bmp->bmiHeader.biHeight = height;
        bmp->bmiHeader.biPlanes = 1;
        bmp->bmiHeader.biBitCount = (unsigned short)bits_per_pixel;
        bmp->bmiHeader.biCompression = 0;
        bmp->bmiHeader.biSizeImage = img_size;
        bmp->bmiHeader.biXPelsPerMeter = 0;
        bmp->bmiHeader.biYPelsPerMeter = 0;
        bmp->bmiHeader.biClrUsed = 0;
        bmp->bmiHeader.biClrImportant = 0;
    }

    {
            m_img_size  = calc_row_len(bmp->bmiHeader.biWidth, 
                                       bmp->bmiHeader.biBitCount) * 
                          bmp->bmiHeader.biHeight;

            m_full_size = calc_full_size(bmp);
            m_bmp       = bmp;
            m_buf       = calc_img_ptr(bmp);
    }

    ::SetDIBitsToDevice(
    hDc,            // handle to device context
    dvc_x,           // x-coordinate of upper-left corner of 
    dvc_y,           // y-coordinate of upper-left corner of 
    dvc_width,       // source rectangle width
    dvc_height,      // source rectangle height
    bmp_x,           // x-coordinate of lower-left corner of 
    bmp_y,           // y-coordinate of lower-left corner of 
    0,               // first scan line in array
    bmp_height,      // number of scan lines
    m_buf,           // address of array with DIB bits
    m_bmp,           // address of structure BITMAPINFO
    DIB_RGB_COLORS   // RGB or palette indexes
    );


    free tmpBuf;
}