File tree Expand file tree Collapse file tree 4 files changed +47
-5
lines changed Expand file tree Collapse file tree 4 files changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,41 @@ vips__premultiplied_bgra2rgba( guint32 * restrict p, int n )
69
69
}
70
70
}
71
71
72
+ /* Unpremultiplied RGBA (vips convention) to cairo-style premul BGRA.
73
+ */
74
+ void
75
+ vips__rgba2bgra_premultiplied ( guint32 * restrict p , int n )
76
+ {
77
+ int x ;
78
+
79
+ for ( x = 0 ; x < n ; x ++ ) {
80
+ guint32 rgba = GUINT32_FROM_BE ( p [x ] );
81
+ guint8 a = rgba & 0xff ;
82
+
83
+ guint32 bgra ;
84
+
85
+ if ( a == 0 )
86
+ bgra = 0 ;
87
+ else if ( a == 255 )
88
+ bgra = (rgba & 0x00ff00ff ) |
89
+ (rgba & 0x0000ff00 ) << 16 |
90
+ (rgba & 0xff000000 ) >> 16 ;
91
+ else {
92
+ int r = (rgba >> 24 ) & 0xff ;
93
+ int g = (rgba >> 16 ) & 0xff ;
94
+ int b = (rgba >> 8 ) & 0xff ;
95
+
96
+ r = ((r * a ) + 128 ) >> 8 ;
97
+ g = ((g * a ) + 128 ) >> 8 ;
98
+ b = ((b * a ) + 128 ) >> 8 ;
99
+
100
+ bgra = (b << 24 ) | (g << 16 ) | (r << 8 ) | a ;
101
+ }
102
+
103
+ p [x ] = GUINT32_TO_BE ( bgra );
104
+ }
105
+ }
106
+
72
107
/* Convert from PDFium-style BGRA to RGBA.
73
108
*/
74
109
void
Original file line number Diff line number Diff line change @@ -524,6 +524,10 @@ vips_foreign_load_pdf_header( VipsForeignLoad *load )
524
524
VIPS_AREA ( pdf -> background )-> n )) )
525
525
return ( -1 );
526
526
527
+ /* Swap B and R.
528
+ */
529
+ vips__bgra2rgba ( (guint32 * ) pdf -> ink , 1 );
530
+
527
531
return ( 0 );
528
532
}
529
533
@@ -572,10 +576,10 @@ vips_foreign_load_pdf_generate( VipsRegion *or,
572
576
if ( vips_foreign_load_pdf_get_page ( pdf , pdf -> page_no + i ) )
573
577
return ( -1 );
574
578
575
- /* 4 means RGBA.
576
- */
577
579
g_mutex_lock ( vips_pdfium_mutex );
578
580
581
+ /* 4 means RGBA.
582
+ */
579
583
bitmap = FPDFBitmap_CreateEx ( rect .width , rect .height , 4 ,
580
584
VIPS_REGION_ADDR ( or , rect .left , rect .top ),
581
585
VIPS_REGION_LSKIP ( or ) );
Original file line number Diff line number Diff line change @@ -380,16 +380,17 @@ vips_foreign_load_pdf_header( VipsForeignLoad *load )
380
380
vips_foreign_load_pdf_set_image ( pdf , load -> out );
381
381
382
382
/* Convert the background to the image format.
383
- *
384
- * FIXME ... we probably should convert this to pre-multiplied BGRA
385
- * to match the Cairo convention. See vips__premultiplied_bgra2rgba().
386
383
*/
387
384
if ( !(pdf -> ink = vips__vector_to_ink ( class -> nickname ,
388
385
load -> out ,
389
386
VIPS_AREA ( pdf -> background )-> data , NULL ,
390
387
VIPS_AREA ( pdf -> background )-> n )) )
391
388
return ( -1 );
392
389
390
+ /* Swap to cairo-style premultiplied bgra.
391
+ */
392
+ vips__rgba2bgra_premultiplied ( (guint32 * ) pdf -> ink , 1 );
393
+
393
394
vips_source_minimise ( pdf -> source );
394
395
395
396
return ( 0 );
Original file line number Diff line number Diff line change @@ -325,6 +325,8 @@ char *vips__xml_properties( VipsImage *image );
325
325
*/
326
326
VIPS_API
327
327
void vips__premultiplied_bgra2rgba ( guint32 * restrict p , int n );
328
+ VIPS_API
329
+ void vips__rgba2bgra_premultiplied ( guint32 * restrict p , int n );
328
330
void vips__bgra2rgba ( guint32 * restrict p , int n );
329
331
void vips__Lab2LabQ_vec ( VipsPel * out , float * in , int width );
330
332
void vips__LabQ2Lab_vec ( float * out , VipsPel * in , int width );
You can’t perform that action at this time.
0 commit comments