~muktupavels/metacity/lp1403583

« back to all changes in this revision

Viewing changes to src/ui/gradient.c

  • Committer: Package Import Robot
  • Author(s): Dmitry Shachnev
  • Date: 2014-11-18 18:13:01 UTC
  • mfrom: (2.3.7 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118181301-omfi79vghwycfal2
Tags: 1:3.14.2-0ubuntu1
* Merge with Debian unstable, remaining changes:
  - 05_raise_on_click_for_click_mode.patch:
    Force raise on click option.
  - 22_fix_above_tab_switching.patch:
    For Above_Tab, don't compare keysym (fixes group switching).
  - debian/metacity-common.links:
    Show keybindings in Unity control center.
  - Use Ubuntu Desktop team Vcs fields.
* Drop all other patches, they were needed only for Unity 2D.
* New upstream bugfix release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
/* Metacity gradient rendering */
4
4
 
5
 
/* 
 
5
/*
6
6
 * Copyright (C) 2001 Havoc Pennington, 99% copied from wrlib in
7
7
 * WindowMaker, Copyright (C) 1997-2000 Dan Pascu and Alfredo Kojima
8
8
 * Copyright (C) 2005 Elijah Newren
9
 
 * 
 
9
 *
10
10
 * This program is free software; you can redistribute it and/or
11
11
 * modify it under the terms of the GNU General Public License as
12
12
 * published by the Free Software Foundation; either version 2 of the
16
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of
17
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
18
 * General Public License for more details.
19
 
 * 
 
19
 *
20
20
 * You should have received a copy of the GNU General Public License
21
21
 * along with this program; if not, see <http://www.gnu.org/licenses/>.  */
22
22
 
72
72
  if (no_padding)
73
73
    rowstride = width * 3;
74
74
  else
75
 
    /* Always align rows to 32-bit boundaries */  
 
75
    /* Always align rows to 32-bit boundaries */
76
76
    rowstride = 4 * ((3 * width + 3) / 4);
77
77
 
78
78
  buf = g_try_malloc (height * rowstride);
161
161
                                 const GdkRGBA  colors2[2],
162
162
                                 int            thickness2)
163
163
{
164
 
  
 
164
 
165
165
  int i, j, k, l, ll;
166
166
  long r1, g1, b1, dr1, dg1, db1;
167
167
  long r2, g2, b2, dr2, dg2, db2;
169
169
  unsigned char *ptr;
170
170
  unsigned char *pixels;
171
171
  int rowstride;
172
 
  
 
172
 
173
173
  pixbuf = blank_pixbuf (width, height, FALSE);
174
174
  if (pixbuf == NULL)
175
175
    return NULL;
176
 
    
 
176
 
177
177
  pixels = gdk_pixbuf_get_pixels (pixbuf);
178
178
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
179
 
  
 
179
 
180
180
  r1 = (long)(colors1[0].red*0xffffff);
181
181
  g1 = (long)(colors1[0].green*0xffffff);
182
182
  b1 = (long)(colors1[0].blue*0xffffff);
196
196
  for (i=0,k=0,l=0,ll=thickness1; i<height; i++)
197
197
    {
198
198
      ptr = pixels + i * rowstride;
199
 
      
 
199
 
200
200
      if (k == 0)
201
201
        {
202
202
          ptr[0] = (unsigned char) (r1>>16);
231
231
      r1+=dr1;
232
232
      g1+=dg1;
233
233
      b1+=db1;
234
 
        
 
234
 
235
235
      r2+=dr2;
236
236
      g2+=dg2;
237
237
      b2+=db2;
244
244
 *----------------------------------------------------------------------
245
245
 * meta_gradient_create_horizontal--
246
246
 *      Renders a horizontal linear gradient of the specified size in the
247
 
 * GdkPixbuf format with a border of the specified type. 
248
 
 * 
 
247
 * GdkPixbuf format with a border of the specified type.
 
248
 *
249
249
 * Returns:
250
250
 *      A 24bit GdkPixbuf with the gradient (no alpha channel).
251
 
 * 
 
251
 *
252
252
 * Side effects:
253
253
 *      None
254
 
 *---------------------------------------------------------------------- 
 
254
 *----------------------------------------------------------------------
255
255
 */
256
256
static GdkPixbuf*
257
257
meta_gradient_create_horizontal (int width, int height,
258
258
                                 const GdkRGBA  *from,
259
259
                                 const GdkRGBA  *to)
260
 
{    
 
260
{
261
261
  int i;
262
262
  long r, g, b, dr, dg, db;
263
263
  GdkPixbuf *pixbuf;
270
270
  pixbuf = blank_pixbuf (width, height, FALSE);
271
271
  if (pixbuf == NULL)
272
272
    return NULL;
273
 
    
 
273
 
274
274
  pixels = gdk_pixbuf_get_pixels (pixbuf);
275
275
  ptr = pixels;
276
276
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
277
 
  
 
277
 
278
278
  r0 = (guchar) (from->red * 0xff);
279
279
  g0 = (guchar) (from->green * 0xff);
280
280
  b0 = (guchar) (from->blue * 0xff);
281
281
  rf = (guchar) (to->red * 0xff);
282
282
  gf = (guchar) (to->green * 0xff);
283
 
  bf = (guchar) (to->blue * 0xff);  
284
 
  
 
283
  bf = (guchar) (to->blue * 0xff);
 
284
 
285
285
  r = r0 << 16;
286
286
  g = g0 << 16;
287
287
  b = b0 << 16;
288
 
    
 
288
 
289
289
  dr = ((rf-r0)<<16)/(int)width;
290
290
  dg = ((gf-g0)<<16)/(int)width;
291
291
  db = ((bf-b0)<<16)/(int)width;
334
334
  int rf, gf, bf;
335
335
  int rowstride;
336
336
  unsigned char *pixels;
337
 
  
 
337
 
338
338
  pixbuf = blank_pixbuf (width, height, FALSE);
339
339
  if (pixbuf == NULL)
340
340
    return NULL;
341
 
    
 
341
 
342
342
  pixels = gdk_pixbuf_get_pixels (pixbuf);
343
343
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
344
 
  
 
344
 
345
345
  r0 = (guchar) (from->red * 0xff);
346
346
  g0 = (guchar) (from->green * 0xff);
347
347
  b0 = (guchar) (from->blue * 0xff);
348
348
  rf = (guchar) (to->red * 0xff);
349
349
  gf = (guchar) (to->green * 0xff);
350
350
  bf = (guchar) (to->blue * 0xff);
351
 
  
 
351
 
352
352
  r = r0<<16;
353
353
  g = g0<<16;
354
354
  b = b0<<16;
360
360
  for (i=0; i<height; i++)
361
361
    {
362
362
      ptr = pixels + i * rowstride;
363
 
      
 
363
 
364
364
      ptr[0] = (unsigned char)(r>>16);
365
365
      ptr[1] = (unsigned char)(g>>16);
366
366
      ptr[2] = (unsigned char)(b>>16);
403
403
  unsigned char *ptr;
404
404
  unsigned char *pixels;
405
405
  int rowstride;
406
 
  
 
406
 
407
407
  if (width == 1)
408
408
    return meta_gradient_create_vertical (width, height, from, to);
409
409
  else if (height == 1)
412
412
  pixbuf = blank_pixbuf (width, height, FALSE);
413
413
  if (pixbuf == NULL)
414
414
    return NULL;
415
 
    
 
415
 
416
416
  pixels = gdk_pixbuf_get_pixels (pixbuf);
417
417
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
418
418
 
450
450
  GdkPixbuf *pixbuf;
451
451
  unsigned char *ptr;
452
452
  unsigned char *pixels;
453
 
  int width2;  
 
453
  int width2;
454
454
  int rowstride;
455
 
  
 
455
 
456
456
  g_return_val_if_fail (count > 2, NULL);
457
457
 
458
458
  pixbuf = blank_pixbuf (width, height, FALSE);
459
459
  if (pixbuf == NULL)
460
460
    return NULL;
461
 
    
 
461
 
462
462
  pixels = gdk_pixbuf_get_pixels (pixbuf);
463
463
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
464
464
  ptr = pixels;
465
 
    
 
465
 
466
466
  if (count > width)
467
467
    count = width;
468
 
    
 
468
 
469
469
  if (count > 1)
470
470
    width2 = width/(count-1);
471
471
  else
472
472
    width2 = width;
473
 
    
 
473
 
474
474
  k = 0;
475
475
 
476
476
  r = (long)(colors[0].red * 0xffffff);
503
503
      *ptr++ = (unsigned char)(g>>16);
504
504
      *ptr++ = (unsigned char)(b>>16);
505
505
    }
506
 
    
 
506
 
507
507
  /* copy the first line to the other lines */
508
508
  for (i=1; i<height; i++)
509
509
    {
524
524
  int height2;
525
525
  int x;
526
526
  int rowstride;
527
 
  
 
527
 
528
528
  g_return_val_if_fail (count > 2, NULL);
529
529
 
530
530
  pixbuf = blank_pixbuf (width, height, FALSE);
531
531
  if (pixbuf == NULL)
532
532
    return NULL;
533
 
    
 
533
 
534
534
  pixels = gdk_pixbuf_get_pixels (pixbuf);
535
535
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
536
536
  ptr = pixels;
537
 
    
 
537
 
538
538
  if (count > height)
539
539
    count = height;
540
 
    
 
540
 
541
541
  if (count > 1)
542
542
    height2 = height/(count-1);
543
543
  else
544
544
    height2 = height;
545
 
    
 
545
 
546
546
  k = 0;
547
547
 
548
548
  r = (long)(colors[0].red * 0xffffff);
566
566
          memcpy (&(ptr[x*3]), ptr, (width - x)*3);
567
567
 
568
568
          ptr += rowstride;
569
 
          
 
569
 
570
570
          r += dr;
571
571
          g += dg;
572
572
          b += db;
590
590
      memcpy (&(ptr[x*3]), ptr, (width - x)*3);
591
591
 
592
592
      ptr += rowstride;
593
 
      
 
593
 
594
594
      for (j=k+1; j<height; j++)
595
595
        {
596
596
          memcpy (ptr, tmp, rowstride);
597
597
          ptr += rowstride;
598
598
        }
599
599
    }
600
 
    
 
600
 
601
601
  return pixbuf;
602
602
}
603
603
 
613
613
  unsigned char *ptr;
614
614
  unsigned char *pixels;
615
615
  int rowstride;
616
 
  
 
616
 
617
617
  g_return_val_if_fail (count > 2, NULL);
618
618
 
619
619
  if (width == 1)
625
625
                           width, height);
626
626
  if (pixbuf == NULL)
627
627
    return NULL;
628
 
    
 
628
 
629
629
  pixels = gdk_pixbuf_get_pixels (pixbuf);
630
630
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
631
 
  
 
631
 
632
632
  if (count > width)
633
633
    count = width;
634
634
  if (count > height)
675
675
  int row;
676
676
 
677
677
  g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
678
 
  
 
678
 
679
679
  if (alpha == 255)
680
680
    return;
681
 
  
 
681
 
682
682
  g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
683
 
  
 
683
 
684
684
  pixels = gdk_pixbuf_get_pixels (pixbuf);
685
685
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
686
686
  height = gdk_pixbuf_get_height (pixbuf);
705
705
           */
706
706
          /* ((*p / 255.0) * (alpha / 255.0)) * 255; */
707
707
          *p = (guchar) (((int) *p * (int) alpha) / (int) 255);
708
 
          
 
708
 
709
709
          ++p; /* skip A */
710
710
        }
711
711
 
722
722
  long a, da;
723
723
  unsigned char *p;
724
724
  unsigned char *pixels;
725
 
  int width2;  
 
725
  int width2;
726
726
  int rowstride;
727
727
  int width, height;
728
728
  unsigned char *gradient;
729
729
  unsigned char *gradient_p;
730
730
  unsigned char *gradient_end;
731
 
  
 
731
 
732
732
  g_return_if_fail (n_alphas > 0);
733
733
 
734
734
  if (n_alphas == 1)
737
737
      simple_multiply_alpha (pixbuf, alphas[0]);
738
738
      return;
739
739
    }
740
 
  
 
740
 
741
741
  width = gdk_pixbuf_get_width (pixbuf);
742
742
  height = gdk_pixbuf_get_height (pixbuf);
743
743
 
744
744
  gradient = g_new (unsigned char, width);
745
745
  gradient_end = gradient + width;
746
 
  
 
746
 
747
747
  if (n_alphas > width)
748
748
    n_alphas = width;
749
 
    
 
749
 
750
750
  if (n_alphas > 1)
751
751
    width2 = width / (n_alphas - 1);
752
752
  else
753
753
    width2 = width;
754
 
    
 
754
 
755
755
  a = alphas[0] << 8;
756
756
  gradient_p = gradient;
757
 
  
 
757
 
758
758
  /* render the gradient into an array */
759
759
  for (i = 1; i < n_alphas; i++)
760
760
    {
763
763
      for (j = 0; j < width2; j++)
764
764
        {
765
765
          *gradient_p++ = (a >> 8);
766
 
          
 
766
 
767
767
          a += da;
768
768
        }
769
769
 
775
775
    {
776
776
      *gradient_p++ = a >> 8;
777
777
    }
778
 
    
 
778
 
779
779
  /* Now for each line of the pixbuf, fill in with the gradient */
780
780
  pixels = gdk_pixbuf_get_pixels (pixbuf);
781
781
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
782
 
  
 
782
 
783
783
  p = pixels;
784
784
  i = 0;
785
785
  while (i < height)
805
805
      p = row_end;
806
806
      ++i;
807
807
    }
808
 
  
 
808
 
809
809
  g_free (gradient);
810
810
}
811
811
 
818
818
  g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
819
819
  g_return_if_fail (gdk_pixbuf_get_has_alpha (pixbuf));
820
820
  g_return_if_fail (n_alphas > 0);
821
 
  
 
821
 
822
822
  switch (type)
823
823
    {
824
824
    case META_GRADIENT_HORIZONTAL:
825
825
      meta_gradient_add_alpha_horizontal (pixbuf, alphas, n_alphas);
826
826
      break;
827
 
      
 
827
 
828
828
    case META_GRADIENT_VERTICAL:
829
829
      g_printerr ("metacity: vertical alpha channel gradient not implemented yet\n");
830
830
      break;
831
 
      
 
831
 
832
832
    case META_GRADIENT_DIAGONAL:
833
833
      g_printerr ("metacity: diagonal alpha channel gradient not implemented yet\n");
834
834
      break;
835
 
      
 
835
 
836
836
    case META_GRADIENT_LAST:
837
837
      g_assert_not_reached ();
838
838
      break;