gxmclip.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Copyright (C) 1998, 1999 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: gxmclip.c,v 1.2 2000/09/19 19:00:39 lpd Exp $ */
  16. /* Mask clipping support */
  17. #include "gx.h"
  18. #include "gxdevice.h"
  19. #include "gxdevmem.h"
  20. #include "gxmclip.h"
  21. /* Structure descriptor */
  22. public_st_device_mask_clip();
  23. /* GC procedures */
  24. private ENUM_PTRS_WITH(device_mask_clip_enum_ptrs, gx_device_mask_clip *mcdev)
  25. {
  26. if (index < st_gx_strip_bitmap_max_ptrs) {
  27. return ENUM_USING(st_gx_strip_bitmap, &mcdev->tiles,
  28. sizeof(mcdev->tiles), index);
  29. }
  30. index -= st_gx_strip_bitmap_max_ptrs;
  31. if (index < st_device_memory_max_ptrs) {
  32. return ENUM_USING(st_device_memory, &mcdev->mdev,
  33. sizeof(mcdev->mdev), index);
  34. }
  35. ENUM_PREFIX(st_device_forward, st_device_memory_max_ptrs);
  36. }
  37. ENUM_PTRS_END
  38. private RELOC_PTRS_WITH(device_mask_clip_reloc_ptrs, gx_device_mask_clip *mcdev)
  39. {
  40. RELOC_PREFIX(st_device_forward);
  41. RELOC_USING(st_gx_strip_bitmap, &mcdev->tiles, sizeof(mcdev->tiles));
  42. RELOC_USING(st_device_memory, &mcdev->mdev, sizeof(mcdev->mdev));
  43. if (mcdev->mdev.base != 0) {
  44. /*
  45. * Update the line pointers specially, since they point into the
  46. * buffer that is part of the mask clipping device itself.
  47. */
  48. long diff = (char *)RELOC_OBJ(mcdev) - (char *)mcdev;
  49. int i;
  50. for (i = 0; i < mcdev->mdev.height; ++i)
  51. mcdev->mdev.line_ptrs[i] += diff;
  52. mcdev->mdev.base = mcdev->mdev.line_ptrs[0];
  53. mcdev->mdev.line_ptrs =
  54. (void *)((char *)(mcdev->mdev.line_ptrs) + diff);
  55. }
  56. }
  57. RELOC_PTRS_END
  58. /* Initialize a mask clipping device. */
  59. int
  60. gx_mask_clip_initialize(gx_device_mask_clip * cdev,
  61. const gx_device_mask_clip * proto,
  62. const gx_bitmap * bits, gx_device * tdev,
  63. int tx, int ty, gs_memory_t *mem)
  64. {
  65. int buffer_width = bits->size.x;
  66. int buffer_height =
  67. tile_clip_buffer_size / (bits->raster + sizeof(byte *));
  68. gx_device_init((gx_device *)cdev, (const gx_device *)proto,
  69. mem, true);
  70. cdev->width = tdev->width;
  71. cdev->height = tdev->height;
  72. cdev->color_info = tdev->color_info;
  73. gx_device_set_target((gx_device_forward *)cdev, tdev);
  74. cdev->phase.x = -tx;
  75. cdev->phase.y = -ty;
  76. if (buffer_height > bits->size.y)
  77. buffer_height = bits->size.y;
  78. gs_make_mem_mono_device(&cdev->mdev, 0, 0);
  79. for (;;) {
  80. if (buffer_height <= 0) {
  81. /*
  82. * The tile is too wide to buffer even one scan line.
  83. * We could do copy_mono in chunks, but for now, we punt.
  84. */
  85. cdev->mdev.base = 0;
  86. return 0;
  87. }
  88. cdev->mdev.width = buffer_width;
  89. cdev->mdev.height = buffer_height;
  90. if (gdev_mem_bitmap_size(&cdev->mdev) <= tile_clip_buffer_size)
  91. break;
  92. buffer_height--;
  93. }
  94. cdev->mdev.base = cdev->buffer.bytes;
  95. return (*dev_proc(&cdev->mdev, open_device))((gx_device *)&cdev->mdev);
  96. }