This blog is under construction

Saturday 14 September 2013

getpalette example in c

Header file:
    graphics.h

Synopsis:
      void getpalette(struct palettetype *palette);
     struct palettetype {
          unsigned char size; /* no of colors in the palette */
          signed char color[MAXCOLOR + 1] /* color nos for each entry in the palette */
     };
     
Description:
     getpalette() gets current palette information.


getpalette function in c graphics



  #include <graphics.h>
  #include <stdlib.h>
  #include <stdio.h>
  #include <conio.h>

  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;
        int err, i, x, y;
        struct palettetype palette;
        char size[32], colors[32];


        /* initialize graphics and local variables */
        initgraph(&graphicDriver, &graphicMode,
                                "C:/TURBOC3/BGI");

        /* read result of initialization */
        err = graphresult();

        if (err != grOk) {
                /* an error occurred */
                printf("Graphic Error: %s\n",
                                grapherrormsg(err));
                getch();
                return 0;
        }

        x = getmaxx() / 2;
        y = 50;

        /* get the current palette information */
        getpalette(&palette);

        /* store palette size in a string */
        sprintf(size, "Palette size: %d", palette.size);

        /* display the information */
        outtextxy(0, y, size);

        for (i=0; i<palette.size && palette.size; i++) {
                y = y + 10;

                /* store the palette color information in a string */
                sprintf(colors, "palette[%02d]: 0x%02X",
                                        i, palette.colors[i]);

                /* display the information */
                outtextxy(0, y, colors);
        }

        /* clean up */
        getch();
        closegraph();
        return 0;

  }





Output: (getpalette built-in function in c graphics.h)


No comments:

Post a Comment