~ubuntu-branches/ubuntu/trusty/gavl/trusty

« back to all changes in this revision

Viewing changes to gavl/scale_context.c

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2009-01-17 20:38:33 UTC
  • mfrom: (1.1.3 upstream) (4.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090117203833-t8fq1e1jdquyelmy
Tags: 1.1.0-2
Fixed debian/copyright 

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
  return (gavl_video_scale_scanline_func)0;
184
184
  }
185
185
 
186
 
static void get_offset_internal(gavl_pixelformat_t pixelformat,
187
 
                                int plane,
188
 
                                int * advance, int * offset)
189
 
  {
190
 
  switch(pixelformat)
191
 
    {
192
 
    case GAVL_PIXELFORMAT_NONE:
193
 
      break;
194
 
    case GAVL_RGB_15:
195
 
    case GAVL_BGR_15:
196
 
      *advance = 2;
197
 
      *offset = 0;
198
 
      break;
199
 
    case GAVL_GRAY_8:
200
 
      *advance = 1;
201
 
      *offset = 0;
202
 
      break;
203
 
    case GAVL_RGB_16:
204
 
    case GAVL_BGR_16:
205
 
    case GAVL_GRAY_16:
206
 
    case GAVL_GRAYA_16:
207
 
      *advance = 2;
208
 
      *offset = 0;
209
 
      break;
210
 
    case GAVL_RGB_24:
211
 
    case GAVL_BGR_24:
212
 
      *advance = 3;
213
 
      *offset = 0;
214
 
      break;
215
 
    case GAVL_RGB_32:
216
 
    case GAVL_BGR_32:
217
 
    case GAVL_YUVA_32:
218
 
    case GAVL_RGBA_32:
219
 
    case GAVL_GRAYA_32:
220
 
      *advance = 4;
221
 
      *offset = 0;
222
 
      break;
223
 
    case GAVL_YUY2:
224
 
      switch(plane)
225
 
        {
226
 
        /* YUYV */
227
 
        case 0:
228
 
          *advance = 2;
229
 
          *offset = 0;
230
 
          break;
231
 
        case 1:
232
 
          *advance = 4;
233
 
          *offset = 1;
234
 
          break;
235
 
        case 2:
236
 
          *advance = 4;
237
 
          *offset = 3;
238
 
          break;
239
 
        }
240
 
      break;
241
 
    case GAVL_UYVY:
242
 
      switch(plane)
243
 
        {
244
 
        /* UYVY */
245
 
        case 0:
246
 
          *advance = 2;
247
 
          *offset = 1;
248
 
          break;
249
 
        case 1:
250
 
          *advance = 4;
251
 
          *offset = 0;
252
 
          break;
253
 
        case 2:
254
 
          *advance = 4;
255
 
          *offset = 2;
256
 
          break;
257
 
        }
258
 
      break;
259
 
    case GAVL_YUV_420_P:
260
 
    case GAVL_YUV_422_P:
261
 
    case GAVL_YUV_444_P:
262
 
    case GAVL_YUV_411_P:
263
 
    case GAVL_YUV_410_P:
264
 
      *advance = 1;
265
 
      *offset = 0;
266
 
      break;
267
 
    case GAVL_YUVJ_420_P:
268
 
    case GAVL_YUVJ_422_P:
269
 
    case GAVL_YUVJ_444_P:
270
 
      *advance = 1;
271
 
      *offset = 0;
272
 
      break;
273
 
    case GAVL_YUV_444_P_16:
274
 
    case GAVL_YUV_422_P_16:
275
 
      *advance = 2;
276
 
      *offset = 0;
277
 
      break;
278
 
    case GAVL_RGB_48:
279
 
      *advance = 6;
280
 
      *offset = 0;
281
 
      break;
282
 
    case GAVL_RGBA_64:
283
 
    case GAVL_YUVA_64:
284
 
      *advance = 8;
285
 
      *offset = 0;
286
 
      break;
287
 
    case GAVL_GRAY_FLOAT:
288
 
      *advance = sizeof(float);
289
 
      *offset = 0;
290
 
      break;
291
 
    case GAVL_GRAYA_FLOAT:
292
 
      *advance = 2 * sizeof(float);
293
 
      *offset = 0;
294
 
      break;
295
 
    case GAVL_RGB_FLOAT:
296
 
    case GAVL_YUV_FLOAT:
297
 
      *advance = 3 * sizeof(float);
298
 
      *offset = 0;
299
 
      break;
300
 
    case GAVL_RGBA_FLOAT:
301
 
    case GAVL_YUVA_FLOAT:
302
 
      *advance = 4 * sizeof(float);
303
 
      *offset = 0;
304
 
      break;
305
 
    }
306
 
  }
307
 
 
308
186
static void get_minmax(gavl_pixelformat_t pixelformat,
309
187
                       int * min, int * max, float * min_f, float * max_f)
310
188
  {
704
582
  
705
583
  if(ctx->num_directions == 1)
706
584
    {
707
 
    get_offset_internal(src_format->pixelformat,
 
585
    gavl_pixelformat_get_offset(src_format->pixelformat,
708
586
                plane, &ctx->offset1.src_advance, &ctx->offset1.src_offset);
709
 
    get_offset_internal(dst_format->pixelformat,
 
587
    gavl_pixelformat_get_offset(dst_format->pixelformat,
710
588
                plane, &ctx->offset1.dst_advance, &ctx->offset1.dst_offset);
711
589
 
712
590
    /* We set this once here */
716
594
    }
717
595
  else if(ctx->num_directions == 2)
718
596
    {
719
 
    get_offset_internal(src_format->pixelformat,
 
597
    gavl_pixelformat_get_offset(src_format->pixelformat,
720
598
                plane, &ctx->offset1.src_advance, &ctx->offset1.src_offset);
721
 
    get_offset_internal(dst_format->pixelformat,
 
599
    gavl_pixelformat_get_offset(dst_format->pixelformat,
722
600
                plane, &ctx->offset2.dst_advance, &ctx->offset2.dst_offset);
723
601
 
724
602
    ctx->offset1.dst_offset = 0;
743
621
      ctx->func1 = copy_scanline_noadvance;
744
622
 
745
623
    /* Set source and destination offsets */
746
 
    get_offset_internal(src_format->pixelformat,
 
624
    gavl_pixelformat_get_offset(src_format->pixelformat,
747
625
                plane, &ctx->offset1.src_advance, &ctx->offset1.src_offset);
748
 
    get_offset_internal(dst_format->pixelformat,
 
626
    gavl_pixelformat_get_offset(dst_format->pixelformat,
749
627
                plane, &ctx->offset1.dst_advance, &ctx->offset1.dst_offset);
750
628
 
751
629
    /* We set this once here */
780
658
    if((tmp_opt.scale_mode == tmp_opt_y.scale_mode) &&
781
659
       (tmp_opt.scale_order == tmp_opt_y.scale_order))
782
660
      {
783
 
      memset(&funcs, 0, sizeof(funcs));
784
661
      gavl_init_scale_funcs(&funcs, &tmp_opt, ctx->offset1.src_advance,
785
 
                            ctx->offset2.dst_advance);
 
662
                            ctx->offset2.dst_advance, &(ctx->table_h), &(ctx->table_v));
786
663
      ctx->func1 = get_func(&(funcs.funcs_xy), src_format->pixelformat, &bits_h);
787
664
      //      fprintf(stderr, "X AND Y %d\n");
788
665
      }
790
667
    if(ctx->func1) /* Scaling routines for x-y are there, good */
791
668
      {
792
669
      ctx->num_directions = 1;
793
 
            
794
 
      gavl_video_scale_table_init_int(&(ctx->table_h), bits_h);
 
670
      if(bits_h)
 
671
        {
 
672
        gavl_video_scale_table_init_int(&(ctx->table_h), bits_h);
795
673
      /* Must be bits_h since we have only one function (and thus one accuracy) */
796
 
      gavl_video_scale_table_init_int(&(ctx->table_v), bits_h);
 
674
        gavl_video_scale_table_init_int(&(ctx->table_v), bits_h);
 
675
        }
797
676
      ctx->offset = &(ctx->offset1);
798
677
      ctx->dst_size = ctx->dst_rect.w;
799
678
      
829
708
        gavl_video_scale_table_shift_indices(&(ctx->table_v), -src_rect_i.y);
830
709
        ctx->first_scanline = src_rect_i.y;
831
710
        
832
 
        memset(&funcs, 0, sizeof(funcs));
833
 
        gavl_init_scale_funcs(&funcs, &tmp_opt,
 
711
            gavl_init_scale_funcs(&funcs, &tmp_opt,
834
712
                              ctx->offset1.src_advance,
835
 
                              ctx->offset1.dst_advance);
 
713
                              ctx->offset1.dst_advance,
 
714
                              &(ctx->table_h), NULL);
836
715
        ctx->func1 = get_func(&funcs.funcs_x, src_format->pixelformat, &bits_h);
 
716
        if(bits_h)
 
717
          gavl_video_scale_table_init_int(&(ctx->table_h), bits_h);
837
718
        
838
 
        gavl_video_scale_table_init_int(&(ctx->table_h), bits_h);
839
 
 
840
 
        memset(&funcs, 0, sizeof(funcs));
841
719
        gavl_init_scale_funcs(&funcs, &tmp_opt_y,
842
720
                              ctx->offset2.src_advance,
843
 
                              ctx->offset2.dst_advance);
 
721
                              ctx->offset2.dst_advance,
 
722
                              NULL, &(ctx->table_v));
844
723
        ctx->func2 = get_func(&funcs.funcs_y,
845
724
                              src_format->pixelformat, &bits_v);
846
725
 
847
 
        gavl_video_scale_table_init_int(&(ctx->table_v), bits_v);
 
726
        if(bits_v)
 
727
          gavl_video_scale_table_init_int(&(ctx->table_v), bits_v);
848
728
        }
849
729
      else
850
730
        {
858
738
        
859
739
        gavl_video_scale_table_shift_indices(&(ctx->table_h), -src_rect_i.x);
860
740
 
861
 
        memset(&funcs, 0, sizeof(funcs));
862
741
        gavl_init_scale_funcs(&funcs, &tmp_opt_y,
863
742
                              ctx->offset1.src_advance,
864
 
                              ctx->offset1.dst_advance);
 
743
                              ctx->offset1.dst_advance,
 
744
                              NULL, &(ctx->table_v));
865
745
        ctx->func1 = get_func(&funcs.funcs_y, src_format->pixelformat, &bits_v);
866
746
 
867
 
        gavl_video_scale_table_init_int(&(ctx->table_v), bits_v);
 
747
        if(bits_v)
 
748
          gavl_video_scale_table_init_int(&(ctx->table_v), bits_v);
868
749
 
869
 
        memset(&funcs, 0, sizeof(funcs));
870
750
        gavl_init_scale_funcs(&funcs, &tmp_opt,
871
751
                              ctx->offset2.src_advance,
872
 
                              ctx->offset2.dst_advance);
 
752
                              ctx->offset2.dst_advance,
 
753
                              &(ctx->table_h), NULL);
873
754
        ctx->func2 = get_func(&(funcs.funcs_x),
874
755
                              src_format->pixelformat, &bits_h);
875
 
        
876
 
        gavl_video_scale_table_init_int(&(ctx->table_h), bits_h);
 
756
        if(bits_h)
 
757
          gavl_video_scale_table_init_int(&(ctx->table_h), bits_h);
877
758
        }
878
759
      
879
760
      /* Allocate temporary buffer */
888
769
                                ctx->src_rect.w, ctx->dst_rect.w, src_width);
889
770
    //    fprintf(stderr, "Initializing x table done\n");
890
771
 
891
 
    memset(&funcs, 0, sizeof(funcs));
892
772
    gavl_init_scale_funcs(&funcs, &tmp_opt,
893
773
                          ctx->offset1.src_advance,
894
 
                          ctx->offset1.dst_advance);
 
774
                          ctx->offset1.dst_advance,
 
775
                          &(ctx->table_h), NULL);
895
776
    ctx->func1 = get_func(&(funcs.funcs_x), src_format->pixelformat, &bits_h);
896
777
 
897
 
 
898
 
    gavl_video_scale_table_init_int(&(ctx->table_h), bits_h);
 
778
    if(bits_h)
 
779
      gavl_video_scale_table_init_int(&(ctx->table_h), bits_h);
899
780
    }
900
781
  else if(scale_y)
901
782
    {
905
786
    gavl_video_scale_table_init(&(ctx->table_v), &tmp_opt, offset_y,
906
787
                                ctx->src_rect.h, ctx->dst_rect.h, src_height);
907
788
    //    fprintf(stderr, "Initializing y table done\n");
908
 
    memset(&funcs, 0, sizeof(funcs));
909
789
    gavl_init_scale_funcs(&funcs, &tmp_opt,
910
790
                          ctx->offset1.src_advance,
911
 
                          ctx->offset1.dst_advance);
 
791
                          ctx->offset1.dst_advance,
 
792
                          NULL, &(ctx->table_v));
912
793
    ctx->func1 = get_func(&(funcs.funcs_y), src_format->pixelformat, &bits_v);
913
794
    
914
 
    gavl_video_scale_table_init_int(&(ctx->table_v), bits_v);
 
795
    if(bits_v)
 
796
      gavl_video_scale_table_init_int(&(ctx->table_v), bits_v);
915
797
    }
916
798
 
917
799
  if(!ctx->func1 || ((ctx->num_directions == 2) && !ctx->func2))
928
810
  fprintf(stderr, "Vertical table:\n");
929
811
  gavl_video_scale_table_dump(&(ctx->table_v));
930
812
#endif
931
 
 
932
 
  
933
 
  get_minmax(src_format->pixelformat, ctx->min_values_h, ctx->max_values_h, ctx->min_values_f, ctx->max_values_f);
934
 
  get_minmax(src_format->pixelformat, ctx->min_values_v, ctx->max_values_v, ctx->min_values_f, ctx->max_values_f);
935
 
 
 
813
  
 
814
  get_minmax(src_format->pixelformat, ctx->min_values_h,
 
815
             ctx->max_values_h, ctx->min_values_f, ctx->max_values_f);
 
816
  
 
817
  get_minmax(src_format->pixelformat, ctx->min_values_v,
 
818
             ctx->max_values_v, ctx->min_values_f, ctx->max_values_f);
 
819
  
936
820
#if 0
937
821
  fprintf(stderr, "Min: %d %d %d, max: %d %d %d\n",
938
822
          ctx->min_values_h[0],
1201
1085
 
1202
1086
  if(ctx->num_directions == 1)
1203
1087
    {
1204
 
    get_offset_internal(format->pixelformat,
 
1088
    gavl_pixelformat_get_offset(format->pixelformat,
1205
1089
                plane, &ctx->offset1.src_advance, &ctx->offset1.src_offset);
1206
 
    get_offset_internal(format->pixelformat,
 
1090
    gavl_pixelformat_get_offset(format->pixelformat,
1207
1091
                plane, &ctx->offset1.dst_advance, &ctx->offset1.dst_offset);
1208
1092
 
1209
1093
    /* We set this once here */
1213
1097
    }
1214
1098
  else if(ctx->num_directions == 2)
1215
1099
    {
1216
 
    get_offset_internal(format->pixelformat,
 
1100
    gavl_pixelformat_get_offset(format->pixelformat,
1217
1101
                plane, &ctx->offset1.src_advance, &ctx->offset1.src_offset);
1218
1102
 
1219
 
    get_offset_internal(format->pixelformat,
 
1103
    gavl_pixelformat_get_offset(format->pixelformat,
1220
1104
                plane, &ctx->offset2.dst_advance, &ctx->offset2.dst_offset);
1221
1105
 
1222
1106
    ctx->offset1.dst_offset = 0;
1243
1127
      ctx->func1 = copy_scanline_noadvance;
1244
1128
    
1245
1129
    /* Set source and destination offsets */
1246
 
    get_offset_internal(format->pixelformat,
 
1130
    gavl_pixelformat_get_offset(format->pixelformat,
1247
1131
                plane, &ctx->offset1.src_advance, &ctx->offset1.src_offset);
1248
 
    get_offset_internal(format->pixelformat,
 
1132
    gavl_pixelformat_get_offset(format->pixelformat,
1249
1133
                plane, &ctx->offset1.dst_advance, &ctx->offset1.dst_offset);
1250
1134
 
1251
1135
    /* We set this once here */
1283
1167
    if((tmp_opt.scale_mode == tmp_opt_y.scale_mode) &&
1284
1168
       (tmp_opt.scale_order == tmp_opt_y.scale_order))
1285
1169
      {
1286
 
      memset(&funcs, 0, sizeof(funcs));
1287
 
      gavl_init_scale_funcs(&funcs, &tmp_opt,
1288
 
                          ctx->offset1.src_advance,
1289
 
                          ctx->offset2.dst_advance);
 
1170
        gavl_init_scale_funcs(&funcs, &tmp_opt,
 
1171
                            ctx->offset1.src_advance,
 
1172
                            ctx->offset2.dst_advance,
 
1173
                            &(ctx->table_h), &(ctx->table_v));
1290
1174
      ctx->func1 = get_func(&(funcs.funcs_xy), format->pixelformat, &bits_h);
1291
1175
      //      fprintf(stderr, "X AND Y\n");
1292
1176
      }
1316
1200
        
1317
1201
      gavl_video_scale_table_shift_indices(&(ctx->table_v),
1318
1202
                                           -src_rect_i.y);
1319
 
      memset(&funcs, 0, sizeof(funcs));
1320
 
      gavl_init_scale_funcs(&funcs, &tmp_opt,
1321
 
                          ctx->offset1.src_advance,
1322
 
                          ctx->offset1.dst_advance);
 
1203
        gavl_init_scale_funcs(&funcs, &tmp_opt,
 
1204
                            ctx->offset1.src_advance,
 
1205
                            ctx->offset1.dst_advance,
 
1206
                            &(ctx->table_h), NULL);
1323
1207
      ctx->func1 = get_func(&funcs.funcs_x, format->pixelformat, &bits_h);
1324
1208
 
1325
1209
      gavl_video_scale_table_init_int(&(ctx->table_h), bits_h);
1326
1210
 
1327
 
      memset(&funcs, 0, sizeof(funcs));
1328
 
      gavl_init_scale_funcs(&funcs, &tmp_opt_y,
 
1211
        gavl_init_scale_funcs(&funcs, &tmp_opt_y,
1329
1212
                            ctx->offset2.src_advance,
1330
 
                            ctx->offset2.dst_advance);
 
1213
                            ctx->offset2.dst_advance,
 
1214
                            NULL, &(ctx->table_v));
1331
1215
      ctx->func2 = get_func(&funcs.funcs_y, format->pixelformat, &bits_v);
1332
1216
 
1333
1217
 
1348
1232
                                         h_radius, h_coeffs,
1349
1233
                                         src_width);
1350
1234
    //    fprintf(stderr, "Initializing x table done\n");
1351
 
    memset(&funcs, 0, sizeof(funcs));
1352
1235
    gavl_init_scale_funcs(&funcs, &tmp_opt,
1353
1236
                          ctx->offset1.src_advance,
1354
 
                          ctx->offset1.dst_advance);
 
1237
                          ctx->offset1.dst_advance,
 
1238
                          &(ctx->table_h), NULL);
1355
1239
    ctx->func1 = get_func(&(funcs.funcs_x), format->pixelformat, &bits_h);
1356
1240
    
1357
1241
    gavl_video_scale_table_init_int(&(ctx->table_h), bits_h);
1367
1251
                                         src_height);
1368
1252
    
1369
1253
    //    fprintf(stderr, "Initializing y table done\n");
1370
 
    memset(&funcs, 0, sizeof(funcs));
1371
1254
    gavl_init_scale_funcs(&funcs, &tmp_opt,
1372
1255
                          ctx->offset1.src_advance,
1373
 
                          ctx->offset1.dst_advance);
 
1256
                          ctx->offset1.dst_advance,
 
1257
                          NULL, &(ctx->table_v));
1374
1258
    ctx->func1 = get_func(&(funcs.funcs_y), format->pixelformat, &bits_v);
1375
1259
    
1376
1260
    gavl_video_scale_table_init_int(&(ctx->table_v), bits_v);