gxmclip.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Copyright (C) 1998, 1999 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gxmclip.c,v 1.4 2002/02/21 22:24:53 giles Exp $ */
  14. /* Mask clipping support */
  15. #include "gx.h"
  16. #include "gxdevice.h"
  17. #include "gxdevmem.h"
  18. #include "gxmclip.h"
  19. /* Structure descriptor */
  20. public_st_device_mask_clip();
  21. /* GC procedures */
  22. private ENUM_PTRS_WITH(device_mask_clip_enum_ptrs, gx_device_mask_clip *mcdev)
  23. {
  24. if (index < st_gx_strip_bitmap_max_ptrs) {
  25. return ENUM_USING(st_gx_strip_bitmap, &mcdev->tiles,
  26. sizeof(mcdev->tiles), index);
  27. }
  28. index -= st_gx_strip_bitmap_max_ptrs;
  29. if (index < st_device_memory_max_ptrs) {
  30. return ENUM_USING(st_device_memory, &mcdev->mdev,
  31. sizeof(mcdev->mdev), index);
  32. }
  33. ENUM_PREFIX(st_device_forward, st_device_memory_max_ptrs);
  34. }
  35. ENUM_PTRS_END
  36. private RELOC_PTRS_WITH(device_mask_clip_reloc_ptrs, gx_device_mask_clip *mcdev)
  37. {
  38. RELOC_PREFIX(st_device_forward);
  39. RELOC_USING(st_gx_strip_bitmap, &mcdev->tiles, sizeof(mcdev->tiles));
  40. RELOC_USING(st_device_memory, &mcdev->mdev, sizeof(mcdev->mdev));
  41. if (mcdev->mdev.base != 0) {
  42. /*
  43. * Update the line pointers specially, since they point into the
  44. * buffer that is part of the mask clipping device itself.
  45. */
  46. long diff = (char *)RELOC_OBJ(mcdev) - (char *)mcdev;
  47. int i;
  48. for (i = 0; i < mcdev->mdev.height; ++i)
  49. mcdev->mdev.line_ptrs[i] += diff;
  50. mcdev->mdev.base = mcdev->mdev.line_ptrs[0];
  51. mcdev->mdev.line_ptrs =
  52. (void *)((char *)(mcdev->mdev.line_ptrs) + diff);
  53. }
  54. }
  55. RELOC_PTRS_END
  56. /* Initialize a mask clipping device. */
  57. int
  58. gx_mask_clip_initialize(gx_device_mask_clip * cdev,
  59. const gx_device_mask_clip * proto,
  60. const gx_bitmap * bits, gx_device * tdev,
  61. int tx, int ty, gs_memory_t *mem)
  62. {
  63. int buffer_width = bits->size.x;
  64. int buffer_height =
  65. tile_clip_buffer_size / (bits->raster + sizeof(byte *));
  66. gx_device_init((gx_device *)cdev, (const gx_device *)proto,
  67. mem, true);
  68. cdev->width = tdev->width;
  69. cdev->height = tdev->height;
  70. cdev->color_info = tdev->color_info;
  71. gx_device_set_target((gx_device_forward *)cdev, tdev);
  72. cdev->phase.x = -tx;
  73. cdev->phase.y = -ty;
  74. if (buffer_height > bits->size.y)
  75. buffer_height = bits->size.y;
  76. gs_make_mem_mono_device(&cdev->mdev, 0, 0);
  77. for (;;) {
  78. if (buffer_height <= 0) {
  79. /*
  80. * The tile is too wide to buffer even one scan line.
  81. * We could do copy_mono in chunks, but for now, we punt.
  82. */
  83. cdev->mdev.base = 0;
  84. return 0;
  85. }
  86. cdev->mdev.width = buffer_width;
  87. cdev->mdev.height = buffer_height;
  88. if (gdev_mem_bitmap_size(&cdev->mdev) <= tile_clip_buffer_size)
  89. break;
  90. buffer_height--;
  91. }
  92. cdev->mdev.base = cdev->buffer.bytes;
  93. return (*dev_proc(&cdev->mdev, open_device))((gx_device *)&cdev->mdev);
  94. }