Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

graphics - Faster way to copy a region from a bitmap in C

I am using the following way to copy a region from a bitmap in rgb565 pixel format:

void bmpcpy(size_t left, size_t top, size_t right, size_t bottom) {
    size_t index = 0;
    
    do {
        do {
            bmpCopy[index] = bmpSrc[(top * BMP_WIDTH) + left];
            index++;
        } while (++left < right);
    } while (++top < bottom);
}

Is there a faster way to do the copy?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There might be faster ways using memcpy or accelerated graphics APIs, but first notice that your code is flawed:

  • bmpCopy and bmpSrc are not defined, it is unlikely they should be global variables.
  • bmpCopy is assumed to have a straddle value of right - left, not necessarily correct because of alignment constraints.
  • left is not reset for each row.
  • the width and height of the region are assumed to be non zero.

Depending on the type of bmpSrc, the parity and amplitude of width and the alignment of the source and destination pointers, it might be more efficient to copy multiple pixels at a time using a larger type.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...