i_openpl.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* This file is part of the GNU plotutils package. Copyright (C) 1995,
  2. 1996, 1997, 1998, 1999, 2000, 2005, 2008, Free Software Foundation, Inc.
  3. The GNU plotutils package is free software. You may redistribute it
  4. and/or modify it under the terms of the GNU General Public License as
  5. published by the Free Software foundation; either version 2, or (at your
  6. option) any later version.
  7. The GNU plotutils package is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with the GNU plotutils package; see the file COPYING. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  14. Boston, MA 02110-1301, USA. */
  15. #include "sys-defines.h"
  16. #include "extern.h"
  17. #include "xmi.h"
  18. bool
  19. _pl_i_begin_page (S___(Plotter *_plotter))
  20. {
  21. /* With each call to openpl(), we reset the dynamic GIF-specific data
  22. members of the GIFPlotter. The data members, and the values that are
  23. set, are the same as are used in initializing the GIFPlotter (see
  24. i_defplot.c). */
  25. _plotter->i_painted_set = (void *)NULL;
  26. _plotter->i_canvas = (void *)NULL;
  27. _plotter->i_num_color_indices = 0;
  28. _plotter->i_bit_depth = 0;
  29. _plotter->i_frame_nonempty = false;
  30. _plotter->i_pixels_scanned = 0;
  31. _plotter->i_pass = 0;
  32. _plotter->i_hot.x = 0;
  33. _plotter->i_hot.y = 0;
  34. _plotter->i_header_written = false;
  35. /* Create new image, consisting of bitmap and colormap; initialized to
  36. background color. First entries in color table will be (1)
  37. transparent color [if there is one, and we're animating] and (2)
  38. background color. May be the same. */
  39. _pl_i_new_image (S___(_plotter));
  40. /* frame starts empty */
  41. _plotter->i_frame_nonempty = false;
  42. /* GIF file header not yet written */
  43. _plotter->i_header_written = false;
  44. return true;
  45. }
  46. /* Internal function: Create new image, consisting of bitmap and colormap;
  47. initialized to background color. First entries in color table will be
  48. (1) transparent color [if there is one, and we're animating] and (2)
  49. background color. Maybe the same. */
  50. void
  51. _pl_i_new_image (S___(Plotter *_plotter))
  52. {
  53. int i;
  54. miPixel pixel;
  55. /* colormap starts empty (unused entries initted to `black'; we may later
  56. need to output some of the unused entries because GIF colormap lengths
  57. are always powers of 2) */
  58. _plotter->i_num_color_indices = 0;
  59. for (i = 0; i < 256; i++)
  60. {
  61. _plotter->i_colormap[i].red = 0;
  62. _plotter->i_colormap[i].green = 0;
  63. _plotter->i_colormap[i].blue = 0;
  64. }
  65. /* flag any color indices stored in current drawing state as bogus */
  66. _plotter->drawstate->i_pen_color_status = false;
  67. _plotter->drawstate->i_fill_color_status = false;
  68. _plotter->drawstate->i_bg_color_status = false;
  69. /* Transparency feature of GIF89a files requires that the index of the
  70. transparent color be the same for all images in the file. So if we're
  71. animating, i.e. writing a multi-image file, we allocate the
  72. transparent color as the first color index (#0) in all images. */
  73. if (_plotter->i_transparent && _plotter->i_animation)
  74. /* allocate color cell in colormap; see i_color.c */
  75. _pl_i_new_color_index (R___(_plotter)
  76. _plotter->i_transparent_color.red,
  77. _plotter->i_transparent_color.green,
  78. _plotter->i_transparent_color.blue);
  79. /* allocate bg color as next color index in colormap (it could well be
  80. the same as the transparent index); also construct a miPixel for it */
  81. _pl_i_set_bg_color (S___(_plotter));
  82. pixel.type = MI_PIXEL_INDEX_TYPE;
  83. pixel.u.index = _plotter->drawstate->i_bg_color_index;
  84. /* create libxmi miPaintedSet and miCanvas structs */
  85. _plotter->i_painted_set = (void *)miNewPaintedSet ();
  86. _plotter->i_canvas = (void *)miNewCanvas ((unsigned int)_plotter->i_xn, (unsigned int)_plotter->i_yn, pixel);
  87. }