<commit_before>/* GDK - The GIMP Drawing Kit
 * Copyright (C) 1995-1997 <NAME>, <NAME> and <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
 * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

#include "config.h"

#include "gdkvisual.h"
#include "gdkprivate-win32.h"

static void gdk_visual_decompose_mask(gulong mask,
                                      gint * shift, gint * prec);

static GdkVisualPrivate *system_visual;

static gint available_depths[1];

static GdkVisualType available_types[1];

#ifdef G_ENABLE_DEBUG

static const gchar *visual_names[] = {
   "static gray",
   "grayscale",
   "static color",
   "pseudo color",
   "true color",
   "direct color",
};

#endif                          /* G_ENABLE_DEBUG */

void gdk_visual_init(void)
{
   struct {
      BITMAPINFOHEADER bi;
      union {
         RGBQUAD colors[256];
         DWORD fields[256];
      } u;
   } bmi;
   HBITMAP hbm;

   int rastercaps, numcolors, sizepalette, bitspixel;

   system_visual = g_new(GdkVisualPrivate, 1);

   bitspixel = GetDeviceCaps(gdk_DC, BITSPIXEL);
   rastercaps = GetDeviceCaps(gdk_DC, RASTERCAPS);
   system_visual->xvisual = g_new(Visual, 1);
   system_visual->xvisual->visualid = 0;
   system_visual->xvisual->bitspixel = bitspixel;

   if (rastercaps & RC_PALETTE) {
      g_error
          ("Palettized display (%d-colour) mode not supported on Windows.",
           GetDeviceCaps(gdk_DC, SIZEPALETTE));
      system_visual->visual.type = GDK_VISUAL_PSEUDO_COLOR;
      numcolors = GetDeviceCaps(gdk_DC, NUMCOLORS);
      sizepalette = GetDeviceCaps(gdk_DC, SIZEPALETTE);
      system_visual->xvisual->map_entries = sizepalette;
   } else if (bitspixel == 1) {
      system_visual->visual.type = GDK_VISUAL_STATIC_GRAY;
      system_visual->xvisual->map_entries = 2;
   } else if (bitspixel == 4) {
      system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
      system_visual->xvisual->map_entries = 16;
   } else if (bitspixel == 8) {
      system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
      system_visual->xvisual->map_entries = 256;
   } else if (bitspixel == 16) {
      system_visual->visual.type = GDK_VISUAL_TRUE_COLOR;
#if 1
      /* This code by <NAME>,
       * see http://www.users.cts.com/sd/m/menright/display.html
       */
      memset(&bmi, 0, sizeof(bmi));
      bmi.bi.biSize = sizeof(bmi.bi);

      hbm = CreateCompatibleBitmap(gdk_DC, 1, 1);
      GetDIBits(gdk_DC, hbm, 0, 1, NULL,
                (BITMAPINFO *) & bmi, DIB_RGB_COLORS);<commit_msg>From Bertrand: Quick and dirty (temporary) fix solving axis labels having a square background different from pad background in 16 bit color mode on Windows.<commit_after>/* GDK - The GIMP Drawing Kit
 * Copyright (C) 1995-1997 <NAME>, <NAME> and <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
 * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

#include "config.h"

#include "gdkvisual.h"
#include "gdkprivate-win32.h"

static void gdk_visual_decompose_mask(gulong mask,
                                      gint * shift, gint * prec);

static GdkVisualPrivate *system_visual;

static gint available_depths[1];

static GdkVisualType available_types[1];

#ifdef G_ENABLE_DEBUG

static const gchar *visual_names[] = {
   "static gray",
   "grayscale",
   "static color",
   "pseudo color",
   "true color",
   "direct color",
};

#endif                          /* G_ENABLE_DEBUG */

void gdk_visual_init(void)
{
   struct {
      BITMAPINFOHEADER bi;
      union {
         RGBQUAD colors[256];
         DWORD fields[256];
      } u;
   } bmi;
   HBITMAP hbm;

   int rastercaps, numcolors, sizepalette, bitspixel;

   system_visual = g_new(GdkVisualPrivate, 1);

   bitspixel = GetDeviceCaps(gdk_DC, BITSPIXEL);
   rastercaps = GetDeviceCaps(gdk_DC, RASTERCAPS);
   system_visual->xvisual = g_new(Visual, 1);
   system_visual->xvisual->visualid = 0;
   system_visual->xvisual->bitspixel = bitspixel;

   // temporary solves a strange bug in root in 16 bit mode:
   // axis labels background is not the same color than the 
   // pad background...
   if (bitspixel == 16) bitspixel = 24; 

   if (rastercaps & RC_PALETTE) {
      g_error
          ("Palettized display (%d-colour) mode not supported on Windows.",
           GetDeviceCaps(gdk_DC, SIZEPALETTE));
      system_visual->visual.type = GDK_VISUAL_PSEUDO_COLOR;
      numcolors = GetDeviceCaps(gdk_DC, NUMCOLORS);
      sizepalette = GetDeviceCaps(gdk_DC, SIZEPALETTE);
      system_visual->xvisual->map_entries = sizepalette;
   } else if (bitspixel == 1) {
      system_visual->visual.type = GDK_VISUAL_STATIC_GRAY;
      system_visual->xvisual->map_entries = 2;
   } else if (bitspixel == 4) {
      system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
      system_visual->xvisual->map_entries = 16;
   } else if (bitspixel == 8) {
      system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
      system_visual->xvisual->map_entries = 256;
   } else if (bitspixel == 16) {
      system_visual->visual.type = GDK_VISUAL_TRUE_COLOR;
#if 1
      /* This code by <NAME>,
       * see http://www.users.cts.com/sd/m/menright/display.html
       */
      memset(&bmi, 0, sizeof(bmi));
      bmi.bi.biSize = sizeof(bmi.bi);

      hbm = CreateCompatibleBitmap(gdk_DC, 1, 1);
      GetDIBits(gdk_DC, hbm, 0, 1, NULL,
                (BITMAPINFO *) & bmi, DIB_RGB_COLORS);
{'fraction_non_alphanumeric': 0.10063069376313945, 'fraction_numerical': 0.018220042046250877, 'mean_word_length': 3.108232584916523, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5098287', 'n_tokens_mistral': 2527, 'n_tokens_neox': 2287, 'n_words': 697}