Exemplo n.º 1
0
template<class C> raster<C>
as_raster (picture pic) {
  if (pic->get_type () != picture_kind_helper<C>::kind) {
    picture rew= raster_picture (pic->get_width (), pic->get_height (),
                                 pic->get_origin_x (), pic->get_origin_y ());
    pic->copy_to (rew);
    pic= rew;
  }
  raster_picture_rep<C>* rep= (raster_picture_rep<C>*) pic->get_handle ();
  return rep->r;
}
Exemplo n.º 2
0
string
picture_as_eps (picture pic, int dpi) {
    (void) dpi;
    if (DEBUG_CONVERT) debug_convert<< "in picture_as_eps " <<LF;
    static const char* d= "0123456789ABCDEF";
    int w_pt= pic->get_width (), h_pt= pic->get_height ();
    int ox= pic->get_origin_x (), oy= pic->get_origin_y ();
    string r;

    string sw= as_string (w_pt);
    string sh= as_string (h_pt);
    r << "%!PS-Adobe-3.0 EPSF-3.0\n%%Creator: TeXmacs\n%%BoundingBox: 0 0 "
      << sw << " " << sh
      << "\n\n% Created by picture_as_eps ()\n\n%%BeginProlog\nsave\n"
      << "countdictstack\nmark\nnewpath\n/showpage {} def\n/setpagedevice "
      << "{pop} def\n%%EndProlog\n%%Page 1 1\n"
      << "/max { 2 copy lt { exch } if pop } bind def\n"
      << "/ImageWidth " << sw
      << " def\n/ImageHeight " << sh << " def\nImageWidth ImageHeight max "
      << "ImageWidth ImageHeight max scale\n\n/ImageDatas\n\tcurrentfile\n\t"
      << "<< /Filter /ASCIIHexDecode >>\n\t/ReusableStreamDecode\n\tfilter\n";

    int v, i= 0, j= 0, k= 0, l= 0;
    bool alpha= false;
    for (j=0; j < h_pt; j++)
        for (i=0; i < w_pt; i++) {
            color col= pic->get_pixel (i - ox, h_pt - 1 - j - oy);
            int rr, gg, bb, aa;
            get_rgb_color (col, rr, gg, bb, aa);
            if (aa != 255) alpha= true;
        }

    string mask;
    for (j= 0; j < h_pt; j++) {
        for (i=0; i < w_pt; i++) {
            l++;
            color col= pic->get_pixel (i - ox, h_pt - 1 - j - oy);
            int rr, gg, bb, aa;
            get_rgb_color (col, rr, gg, bb, aa);
            rr= (rr * aa + 255 * (255 - aa)) / 255;
            gg= (gg * aa + 255 * (255 - aa)) / 255;
            bb= (bb * aa + 255 * (255 - aa)) / 255;
            r << as_hexadecimal (rr, 2);
            r << as_hexadecimal (gg, 2);
            r << as_hexadecimal (bb, 2);
            if (l > 12) {
                r << "\n";
                l= 0;
            }
        }
        if (alpha) {
            v = 0;
            for (i=0; i < w_pt; i++) {
                color col= pic->get_pixel (i - ox, h_pt - 1 - j - oy);
                int rr, gg, bb, aa;
                get_rgb_color (col, rr, gg, bb, aa);
                v += (aa <= 32) << (3 - i % 4);
                if (i % 4 == 3 || i + 1 == w_pt) {
                    mask << d[v];
                    v= 0;
                    k++;
                    // Padding of the image data mask
                    if (i + 1 == w_pt && k % 2 == 1) {
                        mask << d[0];
                        k++;
                    }
                    // Code layout
                    if (k >= 78) {
                        mask << "\n";
                        k= 0;
                    }
                }
            }
        }
    }
    r << ">\ndef\n\n";

    if (alpha) {
        r << "/MaskDatas\n\tcurrentfile\n\t<< /Filter /ASCIIHexDecode >>\n"
          << "\t/ReusableStreamDecode\n\tfilter\n"
          << mask
          << ">\ndef\n\n"
          << "/TheMask\n<<\n\t/ImageType\t1\n\t/Width\t\tImageWidth\n\t/Height\t"
          << "\tImageHeight\n\t/BitsPerComponent 1\n\t/Decode [ 0 1 ]\n\t"
          << "/ImageMatrix [ ImageWidth 0 0 ImageWidth neg 0 ImageHeight ]\n\t"
          << "/DataSource MaskDatas\n>> def\n\n";
    }
    r << "/TheImage\n<<\n\t/ImageType\t1\n\t/Width\t\tImageWidth\n\t/Height\t"
      << "\tImageHeight\n\t/BitsPerComponent 8\n\t/Decode [ 0 1 0 1 0 1 ]\n\t"
      << "/ImageMatrix [ ImageWidth 0 0 ImageWidth neg 0 ImageHeight ]\n\t"
      << "/DataSource ImageDatas\n>> def\n\n"
      << "/DeviceRGB setcolorspace\n";
    if (alpha) {
        r << "<<\n\t/ImageType 3\n\t/InterleaveType 3\n\t/DataDict TheImage\n"
          << "\t/MaskDict TheMask\n>>";
    }
    else {
        r << "\tTheImage";
    }
    r << "\nimage\nshowpage\n%%Trailer\ncleartomark\ncountdictstack\n"
      << "exch sub { end } repeat\nrestore\n%%EOF\n";

    return r;
}
Exemplo n.º 3
0
 inline void copy_from (picture s) {
   internal_copy_from (0, 0, s, 0, 0, s->get_width (), s->get_height ()); }