MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / count_pixels

Function count_pixels

libavcodec/rle.c:33–55  ·  view source on GitHub ↗

* Count up to 127 consecutive pixels which are either all the same or * all differ from the previous and next pixels. * @param start Pointer to the first pixel * @param len Maximum number of pixels * @param bpp Bytes per pixel * @param same 1 if searching for identical pixel values. 0 for differing * @return Number of matching consecutive pixels found */

Source from the content-addressed store, hash-verified

31 * @return Number of matching consecutive pixels found
32 */
33static int count_pixels(const uint8_t *start, int len, int bpp, int same)
34{
35 const uint8_t *pos;
36 int count = 1;
37
38 for(pos = start + bpp; count < FFMIN(127, len); pos += bpp, count ++) {
39 if(same != !memcmp(pos-bpp, pos, bpp)) {
40 if(!same) {
41 /* if bpp == 1, then 0 1 1 0 is more efficiently encoded as a single
42 * raw block of pixels. for larger bpp, RLE is as good or better */
43 if(bpp == 1 && count + 1 < FFMIN(127, len) && *pos != *(pos+1))
44 continue;
45
46 /* if RLE can encode the next block better than as a raw block,
47 * back up and leave _all_ the identical pixels for RLE */
48 count --;
49 }
50 break;
51 }
52 }
53
54 return count;
55}
56
57int ff_rle_encode(uint8_t *outbuf, int out_size, const uint8_t *ptr , int bpp, int w,
58 int add_rep, int xor_rep, int add_raw, int xor_raw)

Callers 1

ff_rle_encodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected