MCPcopy Create free account
hub / github.com/AOMediaCodec/libavif / avifSetTileConfiguration

Function avifSetTileConfiguration

src/write.c:89–119  ·  view source on GitHub ↗

Set the tile configuration: the number of tiles and the tile size. Tiles improve encoding and decoding speeds when multiple threads are available. However, for image coding, the total tile boundary length affects the compression efficiency because intra prediction can't go across tile boundaries. So the more tiles there are in an image, the worse the compression ratio is. For a given number of ti

Source from the content-addressed store, hash-verified

87// tends to reduce the total tile boundary length inside the image. Use more tiles along the longer
88// dimension of the image to make the tile size closer to a square.
89void avifSetTileConfiguration(int threads, uint32_t width, uint32_t height, int * tileRowsLog2, int * tileColsLog2)
90{
91 *tileRowsLog2 = 0;
92 *tileColsLog2 = 0;
93 if (threads > 1) {
94 // Avoid small tiles because they are particularly bad for image coding.
95 //
96 // Use no more tiles than the number of threads. Aim for one tile per thread. Using more
97 // than one thread inside one tile could be less efficient. Using more tiles than the
98 // number of threads would result in a compression penalty without much benefit.
99 const uint32_t kMinTileArea = 512 * 512;
100 const uint32_t kMaxTiles = 32;
101 // AV1 requires width <= 65536 and height <= 65536, so their product fits
102 // in uint64_t and the resulting tile count fits in uint32_t.
103 const uint64_t imageArea = (uint64_t)width * height;
104 uint32_t tiles = (uint32_t)((imageArea + kMinTileArea - 1) / kMinTileArea);
105 if (tiles > kMaxTiles) {
106 tiles = kMaxTiles;
107 }
108 if (tiles > (uint32_t)threads) {
109 tiles = threads;
110 }
111 int tilesLog2 = floorLog2(tiles);
112 // If the image's width is greater than the height, use more tile columns than tile rows.
113 if (width >= height) {
114 splitTilesLog2(width, height, tilesLog2, tileColsLog2, tileRowsLog2);
115 } else {
116 splitTilesLog2(height, width, tilesLog2, tileRowsLog2, tileColsLog2);
117 }
118 }
119}
120
121// ---------------------------------------------------------------------------
122// avifCodecEncodeOutput

Callers 2

TESTFunction · 0.85

Calls 2

floorLog2Function · 0.85
splitTilesLog2Function · 0.85

Tested by 1

TESTFunction · 0.68