Ticket #69291: patch-gdk-quartz.diff

File patch-gdk-quartz.diff, 3.2 KB (added by DanielO (Daniel O'Connor), 8 months ago)
  • gdk/quartz/gdkimage-quartz.c

    old new  
    3737                                 gint         height)
    3838{
    3939  GdkScreen *screen;
     40  int depth;
    4041 
    4142  g_return_val_if_fail (GDK_IS_DRAWABLE_IMPL_QUARTZ (drawable), NULL);
    4243  g_return_val_if_fail (image != NULL || (dest_x == 0 && dest_y == 0), NULL);
    4344
    4445  screen = gdk_drawable_get_screen (drawable);
     46  depth = gdk_drawable_get_depth (drawable);
    4547  if (!image)
    4648    image = _gdk_image_new_for_depth (screen, GDK_IMAGE_FASTEST, NULL,
    47                                       width, height,
    48                                       gdk_drawable_get_depth (drawable));
     49                                      width, height, depth);
    4950 
    5051  if (GDK_IS_PIXMAP_IMPL_QUARTZ (drawable))
    5152    {
     
    6364          return image;
    6465        }
    6566
    66       switch (gdk_drawable_get_depth (drawable))
     67      switch (depth)
    6768        {
    6869        case 24:
    6970          bytes_per_row = pix_impl->width * 4;
     
    123124          break;
    124125
    125126        default:
    126           g_warning ("Unsupported bit depth %d\n", gdk_drawable_get_depth (drawable));
     127          g_warning ("Unsupported bit depth %d\n", depth);
    127128          return image;
    128129        }
    129130    }
     
    322323  if (visual)
    323324    depth = visual->depth;
    324325
    325   g_assert (depth == 24 || depth == 32);
     326  g_assert (depth == 1 || depth == 24 || depth == 32);
    326327
    327328  image = g_object_new (gdk_image_get_type (), NULL);
    328329  image->type = type;
     
    333334
    334335  image->byte_order = (G_BYTE_ORDER == G_LITTLE_ENDIAN) ? GDK_LSB_FIRST : GDK_MSB_FIRST;
    335336
    336   /* We only support images with bpp 4 */
    337   image->bpp = 4;
    338   image->bpl = image->width * image->bpp;
    339   image->bits_per_pixel = image->bpp * 8;
    340  
     337  if (depth == 1) {
     338    image->bpp = 1;
     339    image->bpl = (image->width >> 3) + 1;
     340    image->bits_per_pixel = 1;
     341  } else {
     342    image->bpp = 4;
     343    image->bpl = image->width * image->bpp;
     344    image->bits_per_pixel = image->bpp * 8;
     345  }
     346 
    341347  image->mem = g_malloc (image->bpl * image->height);
    342348  memset (image->mem, 0x00, image->bpl * image->height);
    343349
     
    355361  g_return_val_if_fail (x >= 0 && x < image->width, 0);
    356362  g_return_val_if_fail (y >= 0 && y < image->height, 0);
    357363
    358   ptr = image->mem + y * image->bpl + x * image->bpp;
     364  ptr = image->mem + y * image->bpl;
     365  if (image->depth == 1) {
     366    guchar data = (image->byte_order == GDK_MSB_FIRST ? (0x80 >> (x & 7)) : (1 << (x & 7)));
     367    return (ptr[x >> 3] & data) ? 0x1 : 0x0;
     368  } else {
     369    ptr += x * image->bpp;
     370    return *(guint32 *)ptr;
     371  }
    359372
    360373  return *(guint32 *)ptr;
    361374}
     
    366379                     gint y,
    367380                     guint32 pixel)
    368381{
    369   guchar *ptr;
     382  guchar *ptr = image->mem + y * image->bpl;
     383  if (image->depth == 1) {
     384    guchar data = (image->byte_order == GDK_MSB_FIRST ? (0x80 >> (x & 7)) : (1 << (x & 7)));
     385    if (pixel) {
     386        ptr[x >> 3] |= data;
     387    } else {
     388        ptr[x >> 3] &= ~data;
     389    }
     390  } else {
     391    ptr += x * image->bpp;
     392    *(guint32 *)ptr = pixel;
     393  }
    370394
    371   ptr = image->mem + y * image->bpl + x * image->bpp;
    372 
    373395  *(guint32 *)ptr = pixel;
    374396}
    375397
     
    377399_gdk_windowing_get_bits_for_depth (GdkDisplay *display,
    378400                                   gint        depth)
    379401{
    380   if (depth == 24 || depth == 32)
     402  if (depth == 1)
     403    return 1;
     404  else if (depth == 24 || depth == 32)
    381405    return 32;
    382406  else
    383407    g_assert_not_reached ();