ilinvert.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: ilinvert.c /main/5 1996/06/19 12:21:28 ageorge $ */
  24. /**---------------------------------------------------------------------
  25. ***
  26. *** (c)Copyright 1991 Hewlett-Packard Co.
  27. ***
  28. *** RESTRICTED RIGHTS LEGEND
  29. *** Use, duplication, or disclosure by the U.S. Government is subject to
  30. *** restrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights in
  31. *** Technical Data and Computer Software clause in DFARS 252.227-7013.
  32. *** Hewlett-Packard Company
  33. *** 3000 Hanover Street
  34. *** Palo Alto, CA 94304 U.S.A.
  35. *** Rights for non-DOD U.S. Government Departments and Agencies are as set
  36. *** forth in FAR 52.227-19(c)(1,2).
  37. ***
  38. ***-------------------------------------------------------------------*/
  39. /* =============================================================================
  40. /ilc/ilinvert.c : Image Library conversion routines for bitonal polarity.
  41. =============================================================================== */
  42. #include "ilint.h"
  43. #include "ilpipelem.h"
  44. #include "ilconvert.h"
  45. #include "ilerrors.h"
  46. typedef struct {
  47. ilBool bitonal; /* bitonal flag */
  48. long nPixels; /* width - 1 of src/dst images */
  49. long srcRowBytes; /* bytes/row of src image */
  50. ilPtr pSrcPixels; /* ptr to start of src pixels */
  51. long dstRowBytes; /* bytes/row of dst image */
  52. ilPtr pDstPixels; /* ptr to start of dst pixels */
  53. } ilinvertRec, *ilinvertPtr;
  54. /* =============================================================================================================================
  55. ilInitInvert - Init() function.
  56. ============================================================================================================================= */
  57. static ilError ilInitInvert (
  58. ilinvertPtr pPriv,
  59. ilImageInfo *pSrcImage,
  60. ilImageInfo *pDstImage
  61. )
  62. {
  63. pPriv->srcRowBytes = pSrcImage->plane[0].nBytesPerRow;
  64. pPriv->pSrcPixels = pSrcImage->plane[0].pPixels;
  65. pPriv->dstRowBytes = pDstImage->plane[0].nBytesPerRow;
  66. pPriv->pDstPixels = pDstImage->plane[0].pPixels;
  67. pPriv->nPixels = (pPriv->srcRowBytes < pPriv->dstRowBytes) ? pPriv->srcRowBytes : pPriv->dstRowBytes;
  68. return IL_OK;
  69. }
  70. /* =============================================================================================================================
  71. ilExecuteinvert - Execute() function for bitonal & grayscale polarity conversion.
  72. ============================================================================================================================= */
  73. static ilError ilExecuteinvert (
  74. ilExecuteData *pData,
  75. long dstLine,
  76. long *pNLines /* ignored on input */
  77. )
  78. {
  79. ilinvertPtr pPriv;
  80. long srcnbytes, dstnbytes;
  81. ilPtr psrcline, pdstline;
  82. ilPtr psrc, pdst;
  83. long nLines, nPixels;
  84. pPriv = (ilinvertPtr )pData->pPrivate;
  85. srcnbytes = pPriv->srcRowBytes;
  86. psrcline = pPriv->pSrcPixels + pData->srcLine * srcnbytes;
  87. dstnbytes = pPriv->dstRowBytes;
  88. pdstline = pPriv->pDstPixels + dstLine * dstnbytes;
  89. if (pPriv->nPixels < 0) return 0;
  90. nLines = *pNLines;
  91. if (nLines <= 0) return 0;
  92. while ( nLines-- > 0 ) {
  93. psrc = psrcline;
  94. pdst = pdstline;
  95. nPixels = pPriv->nPixels;
  96. while ( nPixels-- > 0 ) *pdst++ = ~*psrc++;
  97. psrcline += srcnbytes;
  98. pdstline += dstnbytes;
  99. }
  100. return IL_OK;
  101. }
  102. /* =============================================================================================================================
  103. ilAddInvertFilter - function to add invert filter to the pipe - called by ilconvert.
  104. ============================================================================================================================= */
  105. IL_PRIVATE ilBool _ilAddInvertFilter (
  106. ilPipe pipe,
  107. ilImageDes *pPipedes,
  108. ilPipeInfo *pInfo
  109. )
  110. {
  111. ilDstElementData dstData;
  112. ilinvertPtr pPriv;
  113. unsigned int state;
  114. ilPipeInfo info;
  115. ilImageDes imdes;
  116. ilImageFormat imformat;
  117. state = ilGetPipeInfo(pipe, TRUE, &info, &imdes, &imformat);
  118. if(state != IL_PIPE_FORMING) {
  119. if (!pipe->context->error)
  120. ilDeclarePipeInvalid(pipe, IL_ERROR_PIPE_STATE);
  121. return FALSE;
  122. }
  123. dstData.producerObject = (ilObject)NULL;
  124. dstData.pDes = pPipedes;
  125. dstData.pFormat = (ilImageFormat *)NULL;
  126. dstData.width = pInfo->width;
  127. dstData.height = pInfo->height;
  128. dstData.stripHeight = 0;
  129. dstData.constantStrip = FALSE;
  130. dstData.pPalette = (unsigned short *)NULL;
  131. pPriv = (ilinvertPtr ) ilAddPipeElement (pipe, IL_FILTER, sizeof (ilinvertRec), 0, (ilSrcElementData *)NULL,
  132. &dstData, ilInitInvert, IL_NPF, IL_NPF, ilExecuteinvert, NULL, 0);
  133. if (!pPriv) return FALSE;
  134. if ( imdes.type == IL_BITONAL ) pPriv->bitonal = TRUE;
  135. else pPriv->bitonal = FALSE;
  136. return TRUE;
  137. }