Exposed tile encoding to avifEncoder
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9eb7fa3..005c5b2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
+### Added
+- Exposed tile encoding to avifEncoder
 
 ## [0.3.5] - 2019-07-25
 ### Changed
diff --git a/include/avif/avif.h b/include/avif/avif.h
index 32dcf95..8d441dd 100644
--- a/include/avif/avif.h
+++ b/include/avif/avif.h
@@ -402,12 +402,16 @@
 // * if avifEncoderWrite() returns AVIF_RESULT_OK, output must be freed with avifRawDataFree()
 // * if (maxThreads < 2), multithreading is disabled
 // * quality range: [AVIF_BEST_QUALITY - AVIF_WORST_QUALITY]
+// * To enable tiling, set tileRowsLog2 > 0 and/or tileColsLog2 > 0.
+//   Tiling values range [0-6], where the value indicates a request for 2^n tiles in that dimension.
 typedef struct avifEncoder
 {
     // settings
     int maxThreads;
     int minQuantizer;
     int maxQuantizer;
+    int tileRowsLog2;
+    int tileColsLog2;
 
     // stats from the most recent write
     avifIOStats ioStats;
diff --git a/src/codec_aom.c b/src/codec_aom.c
index 879e8e2..e77bb55 100644
--- a/src/codec_aom.c
+++ b/src/codec_aom.c
@@ -317,8 +317,8 @@
     //   * 3 - CSP_RESERVED
     outputConfig->chromaSamplePosition = 0;
 
-    int minQuantizer = encoder->minQuantizer;
-    int maxQuantizer = encoder->maxQuantizer;
+    int minQuantizer = AVIF_CLAMP(encoder->minQuantizer, 0, 63);
+    int maxQuantizer = AVIF_CLAMP(encoder->maxQuantizer, 0, 63);
     if (alphaOnly) {
         minQuantizer = AVIF_QUANTIZER_LOSSLESS;
         maxQuantizer = AVIF_QUANTIZER_LOSSLESS;
@@ -341,6 +341,14 @@
     if (encoder->maxThreads > 1) {
         aom_codec_control(&aomEncoder, AV1E_SET_ROW_MT, 1);
     }
+    if (encoder->tileRowsLog2 != 0) {
+        int tileRowsLog2 = AVIF_CLAMP(encoder->tileRowsLog2, 0, 6);
+        aom_codec_control(&aomEncoder, AV1E_SET_TILE_ROWS, tileRowsLog2);
+    }
+    if (encoder->tileColsLog2 != 0) {
+        int tileColsLog2 = AVIF_CLAMP(encoder->tileColsLog2, 0, 6);
+        aom_codec_control(&aomEncoder, AV1E_SET_TILE_COLUMNS, tileColsLog2);
+    }
 
     uint32_t uvHeight = image->height >> yShift;
     aom_image_t * aomImage = aom_img_alloc(NULL, aomFormat, image->width, image->height, 16);