+// -----------------------------------------------
+// stuff related to cropping
+
+#define DARK 64
+
+static int row_all_dark( hb_title_t *title, uint8_t* luma, int row )
+{
+ int i = title->width;
+ luma += i * row;
+ while ( --i >= 0 )
+ {
+ if ( *luma++ > DARK )
+ return 0;
+ }
+ return 1;
+}
+
+static int column_all_dark( hb_title_t *title, uint8_t* luma, int top, int col )
+{
+ int i = title->height - top;
+ int stride = title->width;
+ luma += stride * top + col;
+ for ( ; --i >= 0; luma += stride )
+ {
+ if ( *luma > DARK )
+ return 0;
+ }
+ return 1;
+}
+#undef DARK
+
+typedef struct {
+ int n;
+ int t[10];
+ int b[10];
+ int l[10];
+ int r[10];
+} crop_record_t;
+
+static void record_crop( crop_record_t *crops, int t, int b, int l, int r )
+{
+ crops->t[crops->n] = t;
+ crops->b[crops->n] = b;
+ crops->l[crops->n] = l;
+ crops->r[crops->n] = r;
+ ++crops->n;
+}
+
+static int compare_int( const void *a, const void *b )
+{
+ return *(const int *)a - *(const int *)b;
+}
+
+static void sort_crops( crop_record_t *crops )
+{
+ qsort( crops->t, crops->n, sizeof(crops->t[0]), compare_int );
+ qsort( crops->b, crops->n, sizeof(crops->t[0]), compare_int );
+ qsort( crops->l, crops->n, sizeof(crops->t[0]), compare_int );
+ qsort( crops->r, crops->n, sizeof(crops->t[0]), compare_int );
+}
+
+// -----------------------------------------------
+// stuff related to title width/height/aspect info
+