123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* $XConsortium: ilrotate.c /main/4 1996/01/08 12:16:56 lehors $ */
- /* =============================================================================================================================
- /ilc/ilrotate.c : Images Library rotation routines.
- Date Mail-ID Description
- -------- ----------- -------------------------------------------------------------------
- 07/2/91 larsson Initial Coding.
- 11/4/91 voegelin moved ilBitReverseTable to ildata.c
- ============================================================================================================================= */
- #include "ilint.h"
- #include "ilpipelem.h"
- #include "ilerrors.h"
- #define LONGSZ 4
- #define WORDPOS 32
- #define BYTESIZE 8
- #define LEFT_BIT_ON 0x80000000
- #define ROT90 1
- #define ROT180 2
- #define ROT270 3
- typedef struct {
- int illinecount; /* running line count as pipe strips are executed */
- int ilXCenter; /* center of image width */
- int ilYCenter; /* center of image height */
- int ilRotateDstheight; /* destination height value saved to avoid strip sizes */
- int ilRotateSrcheight; /* src height value saved to avoid strip sizes */
- unsigned long dstMask; /* destination bit mask for 90 degree rotations (bitonal) */
- int rtype; /* rotation type used for setting dstMask */
- ilBool Lastbit; /* Flag indicating leftmost bit of current word is written */
- } ilRotatePriv, *ilRotatePrivptr;
- /* =============================================================================================================================
- ============================================================================================================================= */
- static ilError ilRotateInit(
- ilRotatePrivptr pPrivate,
- ilImageInfo *pSrcImage,
- ilImageInfo *pDstImage
- )
- {
- unsigned char *pdstline;
- ilImagePlaneInfo *pplane;
- int bitoff;
- /* Initialize counters */
- pPrivate->illinecount = 1;
- pPrivate->ilXCenter = pSrcImage->width/2;
- pPrivate->ilYCenter = pPrivate->ilRotateSrcheight/2;
-
- /* Zero out destination memory for bitonal format handling */
- pplane = &pDstImage->plane[0];
- pdstline = (unsigned char *) (pplane->pPixels);
- bitoff = (pplane->nBytesPerRow * 8) - pDstImage->width;
- if ( pPrivate->rtype == ROT90) pPrivate->dstMask = 1 << bitoff;
- else pPrivate->dstMask = LEFT_BIT_ON;
- if ( (long) pPrivate->dstMask < 0 ) pPrivate->Lastbit = TRUE;
- else pPrivate->Lastbit = FALSE;
- bzero((char *)pdstline,
- (pplane->nBytesPerRow * pPrivate->ilRotateDstheight));
- return IL_OK;
- }
- /* =============================================================================================================================
- ilRotate90BitonalExecute - 90 degree cw Rotation for images with bit per pixel format .
- ============================================================================================================================= */
- static ilError ilRotate90BitonalExecute (
- ilExecuteData *pData,
- unsigned long dstLine,
- unsigned long *pNLines
- )
- {
-
- unsigned long *psrc, *pdst, *psrcline, *pdstline;
- unsigned long srcnwords, dstnwords;
- ilImagePlaneInfo *pplane;
- int x, y, xoffset, lastcount;
- ilRotatePrivptr pPriv;
- unsigned long srcMask;
- unsigned long srcLong;
- ilBool shortwidth;
- if (*pNLines <= 0) return IL_OK;
- pplane = &pData->pSrcImage->plane[0];
- srcnwords = (pplane->nBytesPerRow + LONGSZ - 1)/LONGSZ;
- psrcline = (unsigned long *) (pplane->pPixels) + pData->srcLine * srcnwords;
- pplane = &pData->pDstImage->plane[0];
- dstnwords = (pplane->nBytesPerRow + LONGSZ - 1)/LONGSZ;
- pdstline = (unsigned long *) (pplane->pPixels) + dstLine * dstnwords;
- pPriv = (ilRotatePrivptr) pData->pPrivate;
- /* Rotate cw 90 degrees map (x,y) to (-y,x) about its center [ width-y, x ] */
- psrc = psrcline;
-
- srcLong = *psrc++;
- srcMask = LEFT_BIT_ON;
- shortwidth = (((srcnwords * WORDPOS) - pData->pSrcImage->width) > 0) ? TRUE : FALSE;
- lastcount = pPriv->illinecount - 1;
- for (y = pPriv->illinecount; y <= (lastcount + *pNLines); y++, pPriv->illinecount++ ) {
- xoffset = (pData->pDstImage->width - y)/WORDPOS;
- for ( x = 0; x < pData->pSrcImage->width; x++) {
- if ( srcLong & srcMask ) { /* Copy bit */
- pdst = pdstline + (dstnwords * x) + xoffset;
- *pdst = *pdst | pPriv->dstMask;
- }
- srcMask >>= 1; /* Shift to next pixel */
- if ( !srcMask ) {
- srcLong = *psrc++;
- srcMask = LEFT_BIT_ON;
- }
- }
- if ( !pPriv->Lastbit ) pPriv->dstMask <<= 1;
- else {
- pPriv->dstMask = 1;
- pPriv->Lastbit = FALSE;
- }
- if ( (long) pPriv->dstMask < 0 ) pPriv->Lastbit = TRUE;
- if(shortwidth) {
- srcLong = *psrc++;
- srcMask = LEFT_BIT_ON;
- }
- }
- /* No. of lines written is the destination height */
- if ( pPriv->illinecount <= pPriv->ilRotateSrcheight ) *pNLines = 0;
- else *pNLines = pPriv->ilRotateDstheight;
-
- return IL_OK;
- }
- /* =============================================================================================================================
- ilRotate180BitonalExecute - 180 degree Rotation for images with bit per pixel format .
- ============================================================================================================================= */
- static ilError ilRotate180BitonalExecute (
- ilExecuteData *pData,
- unsigned long dstLine,
- unsigned long *pNLines
- )
- {
-
- unsigned char *psrc, *pdst, *psrcline, *psrcbefore, *pdstline;
- unsigned char srcbyte;
- ilImagePlaneInfo *pplane;
- int x, y, lastcount, loffset, roffset;
- int srcnbytes, dstnbytes, widthbytes;
- ilRotatePrivptr pPriv;
- if (*pNLines <= 0) return IL_OK;
- pplane = &pData->pSrcImage->plane[0];
- srcnbytes = pplane->nBytesPerRow;
- psrcline = (unsigned char *) (pplane->pPixels) + pData->srcLine * srcnbytes;
- pplane = &pData->pDstImage->plane[0];
- dstnbytes = pplane->nBytesPerRow;
- pdstline = (unsigned char *) (pplane->pPixels) + dstLine * dstnbytes;
- pPriv = (ilRotatePrivptr) pData->pPrivate;
- loffset = pData->pSrcImage->width % BYTESIZE;
- roffset = BYTESIZE - loffset;
- widthbytes = pData->pSrcImage->width / BYTESIZE;
- if ( loffset > 0 ) widthbytes++;
- /* Rotate 180 degrees map (x,y) to (-x,-y) about its center [ width-x, height-y ] */
- lastcount = pPriv->illinecount - 1;
- for (y = pPriv->illinecount; y <= (lastcount + *pNLines); y++, pPriv->illinecount++ ) {
- psrc = psrcline + widthbytes - 1;
- psrcbefore = psrc - 1;
- pdst = pdstline + (dstnbytes * (pPriv->ilRotateSrcheight - y));
- if ( loffset == 0 )
- for ( x = 0; x < widthbytes; x++) *pdst++ = ilBitReverseTable[ *psrc-- ];
- else {
- for ( x = 0; x < widthbytes; x++) {
- if ( psrcbefore < psrcline ) srcbyte = (*psrc >> roffset);
- else srcbyte = (*psrcbefore << loffset) | (*psrc >> roffset);
- *pdst++ = ilBitReverseTable[srcbyte];
- psrc--;
- psrcbefore--;
- }
- }
- psrcline += srcnbytes;
- }
- /* No. of lines written is the destination height */
- if ( pPriv->illinecount <= pPriv->ilRotateSrcheight ) *pNLines = 0;
- else *pNLines = pPriv->ilRotateDstheight;
-
- return IL_OK;
- }
- /* =============================================================================================================================
- ilRotate270BitonalExecute - 270 degree cw Rotation for images with bit per pixel format .
- ============================================================================================================================= */
- static ilError ilRotate270BitonalExecute (
- ilExecuteData *pData,
- unsigned long dstLine,
- unsigned long *pNLines
- )
- {
- unsigned long *psrc, *pdst, *psrcline, *pdstline;
- unsigned long srcnwords, dstnwords;
- ilImagePlaneInfo *pplane;
- int x, y, xoffset, lastcount;
- ilRotatePrivptr pPriv;
- unsigned long srcMask, dstMask;
- unsigned long srcLong, dstLong;
- ilBool shortwidth;
- if (*pNLines <= 0) return IL_OK;
- pplane = &pData->pSrcImage->plane[0];
- srcnwords = (pplane->nBytesPerRow + LONGSZ - 1)/LONGSZ;
- psrcline = (unsigned long *) (pplane->pPixels) + pData->srcLine * srcnwords;
- pplane = &pData->pDstImage->plane[0];
- dstnwords = (pplane->nBytesPerRow + LONGSZ - 1)/LONGSZ;
- pdstline = (unsigned long *) (pplane->pPixels) + dstLine * dstnwords;
- pPriv = (ilRotatePrivptr) pData->pPrivate;
- /* Rotate cw 270 degrees map (x,y) to (y,-x) about its center [ y, height-x ] */
- psrc = psrcline;
-
- srcLong = *psrc++;
- srcMask = LEFT_BIT_ON;
- shortwidth = (((srcnwords * WORDPOS) - pData->pSrcImage->width) > 0) ? TRUE : FALSE;
- lastcount = pPriv->illinecount - 1;
- for (y = pPriv->illinecount; y <= (lastcount + *pNLines); y++, pPriv->illinecount++ ) {
- xoffset = (y - 1)/WORDPOS;
- for ( x = 1; x <= pData->pSrcImage->width; x++) {
- if ( srcLong & srcMask ) { /* perform copy */
- pdst = pdstline + (dstnwords * (pPriv->ilRotateDstheight - x)) + xoffset;
- *pdst = *pdst | pPriv->dstMask;
- }
- /* shift to next pixel */
- srcMask >>= 1;
- if ( !srcMask ) {
- srcLong = *psrc++;
- srcMask = LEFT_BIT_ON;
- }
- }
- pPriv->dstMask >>= 1;
- if( !pPriv->dstMask ) pPriv->dstMask = LEFT_BIT_ON;
- if(shortwidth) {
- srcLong = *psrc++;
- srcMask = LEFT_BIT_ON;
- }
- }
- /* No. of lines written is the destination height */
- if ( pPriv->illinecount <= pPriv->ilRotateSrcheight ) *pNLines = 0;
- else *pNLines = pPriv->ilRotateDstheight;
-
- return IL_OK;
- }
- /* =============================================================================================================================
- ilRotate903ByteExecute - 90 degree cw Rotation for images with 24 bits per pixel format .
- ============================================================================================================================= */
- static ilError ilRotate903ByteExecute (
- ilExecuteData *pData,
- unsigned long dstLine,
- unsigned long *pNLines
- )
- {
- unsigned char *psrc, *pdst, *psrcline, *pdstline;
- unsigned long srcnbytes, dstnbytes;
- ilImagePlaneInfo *pplane;
- int x, y, xoffset, lastcount;
- ilRotatePrivptr pPriv;
- if (*pNLines <= 0) return IL_OK;
- pplane = &pData->pSrcImage->plane[0];
- srcnbytes = pplane->nBytesPerRow;
- psrcline = (unsigned char *) (pplane->pPixels) + pData->srcLine * srcnbytes;
- pplane = &pData->pDstImage->plane[0];
- dstnbytes = pplane->nBytesPerRow;
- pdstline = (unsigned char *) (pplane->pPixels) + dstLine * dstnbytes;
- pPriv = (ilRotatePrivptr) pData->pPrivate;
- /* Rotate cw 90 degrees map (x,y) to (-y,x) about its center [ width-y, x ] */
- lastcount = pPriv->illinecount - 1;
- for (y = pPriv->illinecount; y <= (lastcount + *pNLines); y++, pPriv->illinecount++ ) {
- psrc = psrcline;
- xoffset = (pData->pDstImage->width - y) * 3;
- for ( x = 0; x < pData->pSrcImage->width; x++) {
- pdst = pdstline + (dstnbytes * x) + xoffset;
- *pdst++ = *psrc++;
- *pdst++ = *psrc++;
- *pdst = *psrc++;
- }
- psrcline += srcnbytes;
- }
- /* No. of lines written is the destination height */
- if ( pPriv->illinecount <= pPriv->ilRotateSrcheight ) *pNLines = 0;
- else *pNLines = pPriv->ilRotateDstheight;
-
- return IL_OK;
- }
- /* =============================================================================================================================
- ilRotate1803ByteExecute - 180 degree Rotation for images with 24 bits per pixel format .
- ============================================================================================================================= */
- static ilError ilRotate1803ByteExecute (
- ilExecuteData *pData,
- unsigned long dstLine,
- unsigned long *pNLines
- )
- {
- unsigned char *psrc, *pdst, *psrcline, *pdstline;
- unsigned long srcnbytes, dstnbytes;
- ilImagePlaneInfo *pplane;
- int x, y, xoffset, lastcount;
- ilRotatePrivptr pPriv;
- if (*pNLines <= 0) return IL_OK;
- pplane = &pData->pSrcImage->plane[0];
- srcnbytes = pplane->nBytesPerRow;
- psrcline = (unsigned char *) (pplane->pPixels) + pData->srcLine * srcnbytes;
- pplane = &pData->pDstImage->plane[0];
- dstnbytes = pplane->nBytesPerRow;
- pdstline = (unsigned char *) (pplane->pPixels) + dstLine * dstnbytes;
- pPriv = (ilRotatePrivptr) pData->pPrivate;
- /* Rotate 180 degrees map (x,y) to (-x,-y) about its center [ width-x, height-y ] */
-
- xoffset = pData->pSrcImage->width * 3;
- lastcount = pPriv->illinecount - 1;
- for (y = pPriv->illinecount; y <= (lastcount + *pNLines); y++, pPriv->illinecount++ ) {
- psrc = psrcline + 2;
- pdst = pdstline + (dstnbytes * (pPriv->ilRotateSrcheight - y)) + xoffset - 1;
- for ( x = 0; x < pData->pSrcImage->width; x++, psrc += 5) {
- *pdst-- = *psrc--;
- *pdst-- = *psrc--;
- *pdst-- = *psrc;
- }
- psrcline += srcnbytes;
- }
- /* No. of lines written is the destination height */
- if ( pPriv->illinecount <= pPriv->ilRotateSrcheight ) *pNLines = 0;
- else *pNLines = pPriv->ilRotateDstheight;
-
- return IL_OK;
- }
- /* =============================================================================================================================
- ilRotate2703ByteExecute - 270 degree cw Rotation for images with 24 bits per pixel format .
- ============================================================================================================================= */
- static ilError ilRotate2703ByteExecute (
- ilExecuteData *pData,
- unsigned long dstLine,
- unsigned long *pNLines
- )
- {
- unsigned char *psrc, *pdst, *psrcline, *pdstline;
- unsigned long srcnbytes, dstnbytes;
- ilImagePlaneInfo *pplane;
- int x, y, lastcount, xoffset;
- ilRotatePrivptr pPriv;
- if (*pNLines <= 0) return IL_OK;
- pplane = &pData->pSrcImage->plane[0];
- srcnbytes = pplane->nBytesPerRow;
- psrcline = (unsigned char *) (pplane->pPixels) + pData->srcLine * srcnbytes;
- pplane = &pData->pDstImage->plane[0];
- dstnbytes = pplane->nBytesPerRow;
- pdstline = (unsigned char *) (pplane->pPixels) + dstLine * dstnbytes;
- pPriv = (ilRotatePrivptr) pData->pPrivate;
- /* Rotate cw 270 degrees map (x,y) to (y,-x) about its center [ y, height-x ] */
- lastcount = pPriv->illinecount - 1;
- for (y = pPriv->illinecount; y <= (lastcount + *pNLines); y++, pPriv->illinecount++ ) {
- psrc = psrcline;
- xoffset = 3 * (y-1);
- for ( x = 1; x <= pData->pSrcImage->width; x++) {
- pdst = pdstline + (dstnbytes * (pPriv->ilRotateDstheight - x)) + xoffset;
- *pdst++ = *psrc++;
- *pdst++ = *psrc++;
- *pdst = *psrc++;
- }
- psrcline += srcnbytes;
- }
- /* No. of lines written is the destination height */
- if ( pPriv->illinecount <= pPriv->ilRotateSrcheight ) *pNLines = 0;
- else *pNLines = pPriv->ilRotateDstheight;
-
- return IL_OK;
- }
- /* =============================================================================================================================
- ilRotate90ByteExecute - 90 degree cw Rotation for images with byte per pixel format .
- ============================================================================================================================= */
- static ilError ilRotate90ByteExecute (
- ilExecuteData *pData,
- unsigned long dstLine,
- unsigned long *pNLines
- )
- {
- unsigned char *psrc, *pdst, *psrcline, *pdstline;
- unsigned long srcnbytes, dstnbytes;
- ilImagePlaneInfo *pplane;
- int x, y, xoffset, lastcount;
- unsigned int dstrowpixels;
- ilRotatePrivptr pPriv;
- if (*pNLines <= 0) return IL_OK;
- pplane = &pData->pSrcImage->plane[0];
- srcnbytes = pplane->nBytesPerRow;
- psrcline = (unsigned char *) (pplane->pPixels) + pData->srcLine * srcnbytes;
- pplane = &pData->pDstImage->plane[0];
- dstnbytes = pplane->nBytesPerRow;
- pdstline = (unsigned char *) (pplane->pPixels) + dstLine * dstnbytes;
- pPriv = (ilRotatePrivptr) pData->pPrivate;
- /* Rotate cw 90 degrees map (x,y) to (-y,x) about its center [ width-y, x ] */
- lastcount = pPriv->illinecount - 1;
- for (y = pPriv->illinecount; y <= (lastcount + *pNLines); y++, pPriv->illinecount++ ) {
- psrc = psrcline;
- xoffset = pData->pDstImage->width - y;
- for ( x = 0; x < pData->pSrcImage->width; x++) {
- pdst = pdstline + (dstnbytes * x) + xoffset;
- *pdst = *psrc++;
- }
- psrcline += srcnbytes;
- }
- /* No. of lines written is the destination height */
- if ( pPriv->illinecount <= pPriv->ilRotateSrcheight ) *pNLines = 0;
- else *pNLines = pPriv->ilRotateDstheight;
-
- return IL_OK;
- }
- /* =============================================================================================================================
- ilRotate180ByteExecute - 180 degree Rotation for images with byte per pixel format .
- ============================================================================================================================= */
- static ilError ilRotate180ByteExecute (
- ilExecuteData *pData,
- unsigned long dstLine,
- unsigned long *pNLines
- )
- {
- unsigned char *psrc, *pdst, *psrcline, *pdstline;
- unsigned long srcnbytes, dstnbytes;
- ilImagePlaneInfo *pplane;
- int x, y, lastcount;
- ilRotatePrivptr pPriv;
- if (*pNLines <= 0) return IL_OK;
- pplane = &pData->pSrcImage->plane[0];
- srcnbytes = pplane->nBytesPerRow;
- psrcline = (unsigned char *) (pplane->pPixels) + pData->srcLine * srcnbytes;
- pplane = &pData->pDstImage->plane[0];
- dstnbytes = pplane->nBytesPerRow;
- pdstline = (unsigned char *) (pplane->pPixels) + dstLine * dstnbytes;
- pPriv = (ilRotatePrivptr) pData->pPrivate;
- /* Rotate 180 degrees map (x,y) to (-x,-y) about its center [ width-x, height-y ] */
- lastcount = pPriv->illinecount - 1;
- for (y = pPriv->illinecount; y <= (lastcount + *pNLines); y++, pPriv->illinecount++ ) {
- psrc = psrcline;
- pdst = pdstline + (dstnbytes * (pPriv->ilRotateSrcheight - y)) + srcnbytes - 1;
- for ( x = 0; x < pData->pSrcImage->width; x++) *pdst-- = *psrc++;
- psrcline += srcnbytes;
- }
- /* No. of lines written is the destination height */
- if ( pPriv->illinecount <= pPriv->ilRotateSrcheight ) *pNLines = 0;
- else *pNLines = pPriv->ilRotateDstheight;
-
- return IL_OK;
- }
- /* =============================================================================================================================
- ilRotate270ByteExecute - 270 degree cw Rotation for images with byte per pixel format .
- ============================================================================================================================= */
- static ilError ilRotate270ByteExecute (
- ilExecuteData *pData,
- unsigned long dstLine,
- unsigned long *pNLines
- )
- {
- unsigned char *psrc, *pdst, *psrcline, *pdstline;
- unsigned long srcnbytes, dstnbytes;
- ilImagePlaneInfo *pplane;
- int x, y, lastcount, xoffset;
- ilRotatePrivptr pPriv;
- if (*pNLines <= 0) return IL_OK;
- pplane = &pData->pSrcImage->plane[0];
- srcnbytes = pplane->nBytesPerRow;
- psrcline = (unsigned char *) (pplane->pPixels) + pData->srcLine * srcnbytes;
- pplane = &pData->pDstImage->plane[0];
- dstnbytes = pplane->nBytesPerRow;
- pdstline = (unsigned char *) (pplane->pPixels) + dstLine * dstnbytes;
- pPriv = (ilRotatePrivptr) pData->pPrivate;
- /* Rotate cw 270 degrees map (x,y) to (y,-x) about its center [ y, height-x ] */
-
- lastcount = pPriv->illinecount - 1;
- for (y = pPriv->illinecount; y <= (lastcount + *pNLines); y++, pPriv->illinecount++ ) {
- psrc = psrcline;
- for ( x = 1; x <= pData->pSrcImage->width; x++) {
- pdst = pdstline + (dstnbytes * (pPriv->ilRotateDstheight - x)) + (y-1);
- *pdst = *psrc++;
- }
- psrcline += srcnbytes;
- }
- /* No. of lines written is the destination height */
- if ( pPriv->illinecount <= pPriv->ilRotateSrcheight ) *pNLines = 0;
- else *pNLines = pPriv->ilRotateDstheight;
-
- return IL_OK;
- }
- /* =============================================================================================================================
- ilRotate90 - Add a rotate filter to an existing pipe for 90 degree rotations - checking
- for format types and doing an explicit conversion if necessary. Positive factors
- cause clockwise rotations - negative counter clockwise.
- ============================================================================================================================= */
- ilBool ilRotate90 (
- ilPipe pipe,
- int factor
- )
- {
- unsigned int state;
- ilPipeInfo info;
- ilRotatePrivptr pPriv;
- ilDstElementData dstdata;
- ilImageDes imdes;
- ilImageFormat imformat;
- ilBool convert;
- ilBool bitonal;
- ilBool cw;
- unsigned int rtype;
- #define PIPE_FLAGS
- /* Get ptr to pipe info and check state */
- state = ilGetPipeInfo(pipe, TRUE, &info, &imdes, &imformat);
- if(state != IL_PIPE_FORMING) {
- if (!pipe->context->error)
- ilDeclarePipeInvalid(pipe, IL_ERROR_PIPE_STATE);
- return FALSE;
- }
- bitonal = FALSE;
- /* Check for valid Formats */
- convert = FALSE;
- switch (imdes.nSamplesPerPixel) {
- case 3: /* RGB or YUV */
- if(imformat.sampleOrder != IL_SAMPLE_PIXELS) {
- imformat.sampleOrder = IL_SAMPLE_PIXELS;
- convert = TRUE;
- }
- if((imformat.nBitsPerSample[0] != 8) ||
- (imformat.nBitsPerSample[1] != 8) ||
- (imformat.nBitsPerSample[2] != 8)) {
- imformat.nBitsPerSample[0] = 8;
- imformat.nBitsPerSample[1] = 8;
- imformat.nBitsPerSample[2] = 8;
- convert = TRUE;
- }
- break;
- case 1:
- switch (imformat.nBitsPerSample[0]) {
- case 8: /* Byte per pixel */
- break;
- case 1: /* Bitonal */
- bitonal = TRUE;
- if (imformat.rowBitAlign != 32) {
- imformat.rowBitAlign = 32;
- convert = TRUE;
- }
- break;
- default: /* something other than 1 - try 8 */
- imformat.nBitsPerSample[0] = 8;
- convert = TRUE;
- }
- break;
- default:
- return ilDeclarePipeInvalid(pipe, IL_ERROR_NOT_IMPLEMENTED);
- }
- if(convert) {
- if (!ilConvert(pipe, &imdes, &imformat, 0, NULL))
- return FALSE;
- ilGetPipeInfo (pipe, FALSE, &info, (ilImageDes *)NULL, (ilImageFormat *)NULL);
- }
-
- /* Determine rotation type */
- cw = (factor > 0) ? TRUE : FALSE;
- switch ( abs(factor) % 4) {
- case 0:
- pipe->context->error = IL_OK; /* 0 Rotation - nothing required. */
- return TRUE;
- case 1:
- rtype = (cw) ? ROT90 : ROT270;
- break;
- case 2:
- rtype = ROT180;
- break;
- case 3:
- rtype = (cw) ? ROT270 : ROT90;
- }
- dstdata.producerObject = (ilObject) NULL;
- dstdata.pDes = (ilImageDes *) NULL;
- dstdata.pFormat = (ilImageFormat *) NULL;
- dstdata.pPalette = info.pPalette;
- /* flip-flop image if necessary */
- if(rtype != ROT180) {
- dstdata.width = info.height;
- dstdata.height = info.width;
- }
- else {
- dstdata.width = info.width;
- dstdata.height = info.height;
- }
- /* set output strip height */
- dstdata.stripHeight = dstdata.height;
- dstdata.constantStrip = TRUE;
- switch (imdes.nSamplesPerPixel) {
- case 3:
- switch (rtype) {
- case ROT90:
- pPriv = (ilRotatePrivptr) ilAddPipeElement(pipe, IL_FILTER, sizeof(ilRotatePriv), IL_ADD_PIPE_HOLD_DST, (ilSrcElementData *) NULL,
- &dstdata, ilRotateInit, IL_NPF, IL_NPF, ilRotate903ByteExecute, 0);
- break;
- case ROT180:
- pPriv = (ilRotatePrivptr) ilAddPipeElement(pipe, IL_FILTER, sizeof(ilRotatePriv), IL_ADD_PIPE_HOLD_DST, (ilSrcElementData *) NULL,
- &dstdata, ilRotateInit, IL_NPF, IL_NPF, ilRotate1803ByteExecute, 0);
- break;
- case ROT270:
- pPriv = (ilRotatePrivptr) ilAddPipeElement(pipe, IL_FILTER, sizeof(ilRotatePriv), IL_ADD_PIPE_HOLD_DST, (ilSrcElementData *) NULL,
- &dstdata, ilRotateInit, IL_NPF, IL_NPF, ilRotate2703ByteExecute, 0);
- break;
- }
- break;
- case 1:
- if(bitonal) {
- switch (rtype) {
- case ROT90:
- pPriv = (ilRotatePrivptr) ilAddPipeElement(pipe, IL_FILTER, sizeof(ilRotatePriv), IL_ADD_PIPE_HOLD_DST, (ilSrcElementData *) NULL,
- &dstdata, ilRotateInit, IL_NPF, IL_NPF, ilRotate90BitonalExecute, 0);
- break;
- case ROT180:
- pPriv = (ilRotatePrivptr) ilAddPipeElement(pipe, IL_FILTER, sizeof(ilRotatePriv), IL_ADD_PIPE_HOLD_DST, (ilSrcElementData *) NULL,
- &dstdata, ilRotateInit, IL_NPF, IL_NPF, ilRotate180BitonalExecute, 0);
- break;
- case ROT270:
- pPriv = (ilRotatePrivptr) ilAddPipeElement(pipe, IL_FILTER, sizeof(ilRotatePriv), IL_ADD_PIPE_HOLD_DST, (ilSrcElementData *) NULL,
- &dstdata, ilRotateInit, IL_NPF, IL_NPF, ilRotate270BitonalExecute, 0);
- break;
- }
- }
- else {
- switch (rtype) {
- case ROT90:
- pPriv = (ilRotatePrivptr) ilAddPipeElement(pipe, IL_FILTER, sizeof(ilRotatePriv), IL_ADD_PIPE_HOLD_DST, (ilSrcElementData *) NULL,
- &dstdata, ilRotateInit, IL_NPF, IL_NPF, ilRotate90ByteExecute, 0);
- break;
- case ROT180:
- pPriv = (ilRotatePrivptr) ilAddPipeElement(pipe, IL_FILTER, sizeof(ilRotatePriv), IL_ADD_PIPE_HOLD_DST, (ilSrcElementData *) NULL,
- &dstdata, ilRotateInit, IL_NPF, IL_NPF, ilRotate180ByteExecute, 0);
- break;
- case ROT270:
- pPriv = (ilRotatePrivptr) ilAddPipeElement(pipe, IL_FILTER, sizeof(ilRotatePriv), IL_ADD_PIPE_HOLD_DST, (ilSrcElementData *) NULL,
- &dstdata, ilRotateInit, IL_NPF, IL_NPF, ilRotate270ByteExecute, 0);
- break;
- }
- }
- }
- if(!pPriv)
- return FALSE;
- /* Save away true heights */
- pPriv->ilRotateDstheight = dstdata.height;
- pPriv->ilRotateSrcheight = info.height;
- pPriv->rtype = rtype;
- pipe->context->error = IL_OK;
- return TRUE;
- }
|