简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM