logo
down
shadow

How to add color palette to BITMAPINFO


How to add color palette to BITMAPINFO

By : aswderf sdfwerf
Date : November 21 2020, 01:01 AM
Does that help I modified the function and didn't use BITMAPINFO at all. I used RGBQUAD to write the color palette instead. Here's the solution:
code :
bool SaveBMP(BYTE* Buffer, int width, int height, long paddedsize, LPCTSTR bmpfile)
{
    const int NUMBER_OF_COLORS = 256;
    const int COLOR_PALETTE_SIZE = NUMBER_OF_COLORS * sizeof(RGBQUAD);
    const int HEADER_OFFSET = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + COLOR_PALETTE_SIZE;
    const int TOTAL_FILE_SIZE = HEADER_OFFSET + paddedsize;

    BITMAPFILEHEADER bmfh;
    BITMAPINFOHEADER info;
    RGBQUAD quad[NUMBER_OF_COLORS];
    memset(&bmfh, 0, sizeof(BITMAPFILEHEADER));
    memset(&info, 0, sizeof(BITMAPINFOHEADER));

    // create the color palette
    for (int i = 0; i < NUMBER_OF_COLORS; i++)
    {
        quad[i].rgbBlue = i;
        quad[i].rgbGreen = i;
        quad[i].rgbRed = i;
        quad[i].rgbReserved = 0;
    }

    // fill the fileheader
    bmfh.bfType = 0x4d42;           // 0x4d42 = 'BM'
    bmfh.bfSize = TOTAL_FILE_SIZE;  // Total file size
    bmfh.bfReserved1 = 0;           // UNUSED
    bmfh.bfReserved2 = 0;           // UNUSED
    bmfh.bfOffBits = HEADER_OFFSET; // Offset to start of pixel data

    // fill the infoheader
    info.biSize = sizeof(BITMAPINFOHEADER); // Header size (Must be at least 40)
    info.biWidth = width;                   // Image width
    info.biHeight = -height;                // Image height
    info.biPlanes = 1;                      // MUST BE 1
    info.biBitCount = 8;                    // Bits per pixel (1, 4, 8, 16, 24 or 32)
    info.biCompression = 0;                 // Compression type (BI_RGB = 0, BI_RLE8 = 1, BI_RLE4 = 2 or BI_BITFIELDS = 3)
    info.biSizeImage = height * width;      // Image size (May be 0 if not compressed)
    info.biXPelsPerMeter = 0;               // Preferred resolution in pixels per meter
    info.biYPelsPerMeter = 0;               // Preferred resolution in pixels per meter
    info.biClrUsed = NUMBER_OF_COLORS;      // Number of entries in the color map that are actually used
    info.biClrImportant = 0;                // Number of significant colors (All colors = 0)

    // open the file to write to 
    HANDLE file = CreateFile(bmpfile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

    if (file == NULL)
    {
        CloseHandle(file);
        return false;
    }

    // write file header
    unsigned long bwritten;
    if (WriteFile(file, &bmfh, sizeof(BITMAPFILEHEADER), &bwritten, NULL) == false)
    {
        CloseHandle(file);
        return false;
    }

    // write info header
    if (WriteFile(file, &info, sizeof(BITMAPINFOHEADER), &bwritten, NULL) == false)
    {
        CloseHandle(file);
        return false;
    }

    // write palette
    if (WriteFile(file, quad, COLOR_PALETTE_SIZE, &bwritten, NULL) == false)
    {
        CloseHandle(file);
        return false;
    }

    // write image data
    if (WriteFile(file, Buffer, paddedsize, &bwritten, NULL) == false)
    {
        CloseHandle(file);
        return false;
    }

    // close file
    CloseHandle(file);
    return true;
}


Share : facebook icon twitter icon
Convert 8 bit ( 16 Color Palette ) PNG to proper 4 bit ( 16 color Palette ) with Java or Python?

Convert 8 bit ( 16 Color Palette ) PNG to proper 4 bit ( 16 color Palette ) with Java or Python?


By : user3569055
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , In PNG the palette is always stored in RGB8 (3 bytes for each index=color), with an arbitrary (up to 256) number of entries. If you currently have a 8 bit image with a 16-colors palette (16 total entries), you dont need to alter the pallete, only to repack the pixel bytes (two indexes per byte). If so, I think you could do it with PNGJ with this code (untested):
code :
public static void reencode(String orig, String dest) {
    PngReader png1 = FileHelper.createPngReader(new File(orig));
    ImageInfo pnginfo1 = png1.imgInfo;
    ImageInfo pnginfo2 = new ImageInfo(pnginfo1.cols, pnginfo1.rows, 4, false,false,true);  
    PngWriter png2 = FileHelper.createPngWriter(new File(dest), pnginfo2, false);
    png2.copyChunksFirst(png1, ChunksToWrite.COPY_ALL);
    ImageLine l2 = new ImageLine(pnginfo2);
    for (int row = 0; row < pnginfo1.rows; row++) {
        ImageLine l1 = png1.readRow(row);
        l2.tf_pack(l1.scanline, false);
        l2.setRown(row);
        png2.writeRow(l2);
    }
    png1.end();
    png2.copyChunksLast(png1, ChunksToWrite.COPY_ALL);
    png2.end();
    System.out.println("Done");
}
Is it possible to import a color palette and have stroke, fill, and gradient color stop colors refer to the palette?

Is it possible to import a color palette and have stroke, fill, and gradient color stop colors refer to the palette?


By : mayank pandey
Date : March 29 2020, 07:55 AM
it helps some times I am experimenting with the idea of creating an SVG icon set. What I would like to do is define a color palette and have stroke, fill, and gradient color stop colors refer to colors in the palette, which would be imported somehow by each of the SVG files. This way, if I wanted to create a grayscale version of the icon set, or adapt the colors for a particular kind of colorblindness, then I could just change the palette. , Like any XML file, SVG supports CSS.
mystyle.css
code :
rect {
  fill: red;
  stroke: blue;
  stroke-width: 3
}
<?xml version="1.0" standalone="no"?>
<?xml-stylesheet href="mystyle.css" type="text/css"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
     width="10cm" height="5cm" viewBox="0 0 1000 500">
  <rect x="200" y="100" width="600" height="300"/>
</svg>
Gnuplot - show palette palette and set print - do not print the message "Color palette with x discrete colors saved

Gnuplot - show palette palette and set print - do not print the message "Color palette with x discrete colors saved


By : Antônio Flávio
Date : March 29 2020, 07:55 AM
help you fix your problem I am generating gnuplot scripts with Python. Some of the Gnuplot scripts create graphs (with only a few points on them) with a color variation. I have to reuse the same colors for other graphs. I have discovered that it is possible to use the command , On a Unix system you can start gnuplot with
code :
gnuplot 2>/dev/null
How to write color data in BITMAPINFO by use CreateDIBSection?

How to write color data in BITMAPINFO by use CreateDIBSection?


By : DAYU
Date : March 29 2020, 07:55 AM
will be helpful for those in need first I write some UINT as color in UINT** framebuffer,then create a BITMAPINFO by CreateDIBSection, but after run the program the window are black instead of some color I set,what's wrong? , you need code like this
code :
PVOID pv;
if (s_hBitmap = CreateDIBSection(nullptr, (PBITMAPINFO)&bmphdr, DIB_RGB_COLORS, &pv, 0, 0))
{
    RtlFillMemoryUlong((PULONG)pv, bmphdr.biSizeImage, 0x3fbcefff);
}
BITMAPINFOHEADER bmphdr = { 0 };
BITMAPINFOHEADER bmphdr = {  };
Palette Library: How to add transparency to Palette Swatch Color?

Palette Library: How to add transparency to Palette Swatch Color?


By : Kelly Goerbig
Date : March 29 2020, 07:55 AM
may help you . How can I add transparency value to a palette's swatch? Like I am adding the color(swatch.getRGB()) to a linear layout, It shows solid color. And I don't want to use alpha as it will make other items in layout transparent too. , Use android support utility class:
Related Posts Related Posts :
  • What is the purpose of name mangling in C++?
  • C++ Why the void function is not working eventhough I called it?
  • How the pointer and the pointer's adress can share the same memory adress?
  • error C2220: warning treated as error - no 'object' file generated
  • exception of strcpy function in c++ console program
  • How to access USB barcode scanner data directly from USB port using C/C++ without driver
  • Under which circumstances will std::vector.clear() call a destructor?
  • Template partial specialisation and dependent names
  • best way to share data between c codes
  • C++ ignores if statement conditions
  • How to set the argv[ ] to be case-insensitive in a Win32 Console Application?
  • How to fix error "clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)"?
  • C++ How do I print a .txt file verbatim?
  • Creating two dimensional array of class
  • How do I correctly use COMMTIMEOUTS with OVERLAPPED IO mode reading from a Serial port
  • An assert macro which expands to static_assert when possible?
  • How to write a copyconstructor for a class which has HANDLE as a member in win32 c++ application?
  • C++ saving info such as tree in a file
  • Transforming an expression template tree
  • How to overload an operator with multiple parameters like a + b + c?
  • C++ 11 with Raspberry Pi performances
  • Make a C++ class look like a numpy array using swig
  • Postfix incrementer overloading for nested enumerated types
  • Is there a tidy way of associating metadata with functions in C++
  • QObject::installEventFilter(): Cannot filter events for objects in a different thread
  • LNK2005 error with Zxing C++
  • C++ Doubly Linked List with Pointers: Object of class isn't constructed properly
  • Using a random string generator in c++ constructor
  • What should I use instead of void as one of the alternative types in an variant?
  • C++ return value from multithreads using reference
  • How to connect multiple TCP IP clients to same server port using c++
  • Defaul compiler generates the reference operator (In C++)?
  • Unable to change directory time stamp after using FILE_FLAG_BACKUP_SEMANTICS
  • vector handling displaying output
  • WSAGetLastError returns WSAENOTSOCK - Cause?
  • C++: How to overload pow for user type?
  • C++ using arrays as multidimensional despite initalising it as 1D with pointer
  • How negate std::is_integral for use in tag dispatch?
  • Retrieve serial number from USB memory (Windows environment c++)
  • g++ error: invalid preprocessing directive #INCLUDE
  • C++ What is the std::for_each() function parameter type?
  • C++: Read individual lines from text file, sort words alphabetically
  • Saving 'this' address into a variable
  • c++ command line arguments in ubuntu terminal
  • Convert "Cartesian coordinates" to "polar coordinates with respect to user specified origin"
  • In what order are local scoped objects destructed?
  • How to use SDL_MapRGB with SDL 2.0
  • how compiler and interpreter work in case of array declaration
  • GSL integration behaves strange
  • Cropping an image with OpenCV and C
  • Find the last line in text file and select the first 10 char and print to a new file?
  • Created many CCSprits but when triggering ccTouchBegan gives the last one allways
  • seekp and seekg don't work with fstream
  • Taking input in Sublime Text 3
  • ld: -bind_at_load and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together
  • C++ storing #define as std::string would give size as zero compile time
  • How to use static linking with OpenSSL in C/C++
  • What is the difference between a trap, an error, a failure and program abortion?
  • Dynamic members allocation in qt
  • How to reduce object file size when compiling for VxWorks 5.5.1?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org