Esempio n. 1
0
// Note: On my systems, the operation kInvert shows a speedup on multiple CPUs only!
void
ImageProcessor::Run(int32 i, int32 n)
{
	int32 from, to;
	int32 height = (fHeight+1) / n;
	from = i * height;
	if (i+1 == n) {
		to = fHeight;
	} else {
		to = from + height - 1;
	}

	int32 x, y, destX, destY;
	const uchar* src = (uchar*)GetSrcImage()->Bits();
	uchar* dest = (uchar*)GetDestImage()->Bits();

	switch (fOp) {
		case kRotateClockwise:
			for (y = from; y <= to; y ++) {
				for (x = 0; x <= fWidth; x ++) {
					destX = fHeight - y;
					destY = x;
					CopyPixel(dest, destX, destY, src, x, y);
				}
			}
			break;
		case kRotateCounterClockwise:
			for (y = from; y <= to; y ++) {
				for (x = 0; x <= fWidth; x ++) {
					destX = y;
					destY = fWidth - x;
					CopyPixel(dest, destX, destY, src, x, y);
				}
			}
			break;
		case kFlipTopToBottom:
			for (y = from; y <= to; y ++) {
				for (x = 0; x <= fWidth; x ++) {
					destX = x;
					destY = fHeight - y;
					CopyPixel(dest, destX, destY, src, x, y);
				}
			}
			break;
		case kFlipLeftToRight:
			for (y = from; y <= to; y ++) {
				for (x = 0; x <= fWidth; x ++) {
					destX = fWidth - x;
					destY = y;
					CopyPixel(dest, destX, destY, src, x, y);
				}
			}
			break;
		case kInvert:
			for (y = from; y <= to; y ++) {
				for (x = 0; x <= fWidth; x ++) {
					InvertPixel(x, y, dest, src);
				}
			}
			break;
	}

}
Esempio n. 2
0
int ImageData::AddImage (const int req_wid,
                         byte* dest)
{
    LineHeader head;                 // header of data line being copied
    int    headPos      = 0;     // position in buffer 'dest'
    int    dataPos      = 0;     // position in buffer 'dest'
    int    pos          = 0;     // position in 'src'
    int    numOnPixels  = 0;     // num of on pixels in the chuck
                                 // deposited
    int    numDataLines = 0;     // number of lines of non zero
                                 // data in deposited chunck
    bool   isPixelOn    = false; // pixel scaned is on or off
    bool   foundLine    = false; // a image data line found

    const byte* src = m_clippedImage;
    const int   startx = m_startx;
    const int   starty = m_starty;
    const int   sizex  = m_sizex;
    const int   sizey  = m_sizey;

    if (NULL != dest)
    {
        // prepare to copy out image data
        headPos = sizeof (ImageHeader);
        dataPos = headPos + (sizeof (LineHeader) * m_numDataLines);
	ImageHeader *ihead=(ImageHeader *)dest;
	ihead->m_lines=m_numDataLines;
    }
	
    if (NULL != src)
    {
        for (int y=0; y<sizey; y++)
        {
            for (int x=0; x<sizex; x++)
            {
                isPixelOn = IsPixelOn (src + pos);

                if ((false == foundLine) && (true == isPixelOn))
                {
                    // found a data line
                    if (NULL != dest)
                    {
                        head.m_pos	= ((starty + y)*(req_wid)) + 
                                     (startx + x);
                        head.m_size	= 0;
                    }
				
                    foundLine	= true;
                }

                if (true == isPixelOn)
                {
                    if (NULL != dest)
                    {
                        // update header
                        head.m_size ++;

                        // copy this pixel
                        CopyPixel (dest+dataPos, src+pos);

                        // update dataPos
                        dataPos += m_bytesPerPixel;
                    }

                    numOnPixels ++;
                }
                else
                {
                    if (true == foundLine)
                    {
                        // end of data line
                        if (NULL != dest)
                        {
                            // copy header
                            memcpy (dest + headPos, 
                                    &head,
                                    sizeof (LineHeader));

                            // update headPos
                            headPos += sizeof (LineHeader);
                        }

                        numDataLines ++;
                        foundLine = false;
                    }
                }
			
                pos += m_bytesPerPixel;
            }

            if (true == foundLine)
            {
                // end of data line
                if (NULL != dest)
                {
                     // copy header
                     memcpy (dest + headPos, 
                             &head,
                             sizeof (LineHeader));

                     // update headPos
                     headPos += sizeof (LineHeader);
                }

                numDataLines ++;
                foundLine = false;
            }
        }
    }

    SetSize(numDataLines,numOnPixels);

    return m_size;
}