Re: [Gnome-print] gnome_print_rgbaimage bug



Lauris Kaplinski wrote:

> 
> What version of gnome-print are you using?

I'm working directly from the CVS sources. I've also tested against 
gnome-print-0.25-0_helix_1

> 
> Can you send me a code example?

The following is the C++ code I'm using. This code renders alpha channel 
bitmaps correctly to
the preview window and to PDF. Note that the Bitmap class used actually 
stores the color
components BGRA instead of RGBA, thus the fix_bitmap method:


// Move BGR[A] layout to RGB[A]. Return is allocated on heap, caller 
must delete
static char* fix_bytes(char* old_bitmap, int length, bool has_alpha)
{
   int increment = has_alpha ? 4 : 3;
   char* new_bitmap = new char[length];
  
   for (int i = 0; i < length; i += increment)
   {
       new_bitmap[i] = old_bitmap[i+2];
       new_bitmap[i+1] = old_bitmap[i+1];
       new_bitmap[i+2] = old_bitmap[i];
       if (has_alpha)
           new_bitmap[i+3] = old_bitmap[i+3];
   }
   return new_bitmap;
}
//
// Only currently valid bitmaps types are B_RGB32_LITTLE and B_RGBA32_LITTLE
//
void TPrinterContext::DrawBitmap(const BBitmap* bits, BRect dest)
{
   BRect bounds = bits->Bounds();
   double matrix[6];
  
   matrix[0] = dest.Width();
   matrix[1] = 0;
   matrix[2] = 0;
   matrix[3] = -dest.Height();
   matrix[4] = dest.left;
   matrix[5] = dest.top + dest.Height();

   gnome_print_gsave(mPC);
   gnome_print_concat(mPC,matrix);
   gnome_print_moveto(mPC,0,0);

   color_space cs = bits->ColorSpace();
   ASSERT((cs == B_RGB32_LITTLE) || (cs = B_RGBA32_LITTLE),"Unhandled 
colorspace in TPrinterContext::DrawBitmap");
  

   if (cs == B_RGB32_LITTLE)    // Standard pixmap w/o alpha
   {
       // convert BGR byte layout to RGB
       char* new_bitmap = 
fix_bytes(static_cast<char*>(bits->Bits()),bits->BitsLength(),false);

       gnome_print_rgbimage(mPC,new_bitmap,
                            static_cast<int>(bounds.Width()),
                            static_cast<int>(bounds.Height()),
                            bits->BytesPerRow());
       delete new_bitmap;
   }
   else if (cs == B_RGBA32_LITTLE) // pixmap w/ alpha channel
   {
       // convert BGRA byte layout to RGBA
       char* new_bitmap = 
fix_bytes(static_cast<char*>(bits->Bits()),bits->BitsLength(),true);

       gnome_print_rgbaimage(mPC,new_bitmap,
                             static_cast<int>(bounds.Width()),
                             static_cast<int>(bounds.Height()),
                             bits->BytesPerRow());
       delete new_bitmap;
   }
   gnome_print_grestore(mPC);
}


Thanks,
Tomy





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]