1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
//! # Do not use
//! Do not use functions from this module outside of `imageflow_core`
//!
//! **Use the `imageflow_abi` crate when creating bindings**
//!
//! These aren't to be exposed, but rather to connect to `imageflow_c`/`c_components` internals.
//! Overlaps in naming are artifacts from restructuring
//!

pub use imageflow_types::EdgeKind;

pub use imageflow_types::Filter;
pub use imageflow_types::IoDirection;
pub use imageflow_types::PixelFormat;
use ::internal_prelude::works_everywhere::*;


// These are reused in the external ABI, but only as opaque pointers
///
/// `ImaeflowJsonResponse` contains a buffer and buffer length (in bytes), as well as a status code
/// The status code can be used to avoid actual parsing of the response in some cases.
/// For example, you may not care about parsing an error message if you're hacking around -
/// Or, you may not care about success details if you were sending a command that doesn't imply
/// a result.
///
/// The contents of the buffer MAY NOT include any null characters.
/// The contents of the buffer MUST be a valid UTF-8 byte sequence.
/// The contents of the buffer MUST be valid JSON per RFC 7159.
///
/// The schema of the JSON response is not globally defined; consult the API methods in use.
///
/// Use `imageflow_json_response_destroy` to free (it will otherwise remain on the heap and
/// tracking list until the context is destroyed).
///
/// Use `imageflow_context_read_response` to access
#[repr(C)]
pub struct ImageflowJsonResponse {
    pub status_code: i64,
    pub buffer_utf8_no_nulls: *const libc::uint8_t,
    pub buffer_size: libc::size_t,
}

#[repr(C)]
pub struct ImageflowJobIo {
    placeholder: i64,
    // If you want to know what kind of I/O structure is inside user_data, compare the read_func/write_func function
    // pointers. No need for another human-assigned set of custom structure identifiers.

    /* flow_c * context;
                      * flow_io_mode mode; // Call nothing, dereference nothing, if this is 0
                      * flow_io_read_function read_func; // Optional for write modes
                      * flow_io_write_function write_func; // Optional for read modes
                      * flow_io_position_function position_func; // Optional for sequential modes
                      * flow_io_seek_function seek_function; // Optional for sequential modes
                      * flow_destructor_function dispose_func; // Optional.
                      * void * user_data;
                      * int64_t optional_file_length; // Whoever sets up this structure can populate this value - or set it to -1 - as they
                      * wish. useful for resource estimation.
                      * */
}


#[repr(C)]
#[derive(Debug,Copy,Clone, PartialEq)]
pub enum IoMode {
    None = 0,
    ReadSequential = 1,
    WriteSequential = 2,
    ReadSeekable = 5, // 1 | 4,
    WriteSeekable = 6, // 2 | 4,
    ReadWriteSeekable = 15, // 1 | 2 | 4 | 8
}


#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct ImageflowContext {
    pub error: ErrorInfo,
    pub underlying_heap: Heap,
    pub log: ProfilingLog,
    pub colorspace: ColorspaceInfo,
    pub object_tracking: ObjTrackingInfo,
    pub codec_set: *mut ContextCodecSet,
}

// end reuse

#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct CodecInstance {
    pub io_id: int32_t,
    pub codec_id: int64_t,
    pub codec_state: *mut c_void,
    pub io: *mut ImageflowJobIo,
    pub direction: IoDirection,
}






#[repr(C)]
#[derive(Copy,Clone, Debug)]
pub enum Floatspace {
    srgb = 0,
    linear = 1, // gamma = 2,
}

// #[repr(C)]
// #[derive(Copy,Clone, Debug)]
// pub enum BitmapCompositingMode {
// replace_with_self = 0,
// blend_with_self = 1,
// blend_with_matte = 2,
// }
//


#[repr(C)]
#[derive(Copy,Clone,Debug, PartialEq)]
pub enum FlowStatusCode {
    NoError = 0,
    OutOfMemory = 10,
    IOError = 20,
    InvalidInternalState = 30,
    NotImplemented = 40,
    InvalidArgument = 50,
    NullArgument = 51,
    InvalidDimensions = 52,
    UnsupportedPixelFormat = 53,
    ItemDoesNotExist = 54,

    ImageDecodingFailed = 60,
    ImageEncodingFailed = 61,
    GraphInvalid = 70,
    GraphIsCyclic = 71,
    InvalidInputsToNode = 72,
    MaximumGraphPassesExceeded = 73,
    OtherError = 1024,
    // FIXME: FirstUserDefinedError is 1025 in C but it conflicts with __LastLibraryError
    // ___LastLibraryError,
    FirstUserDefinedError = 1025,
    LastUserDefinedError = 2147483647,
}


pub const TESTED_FILTER_OPTIONS: &'static [&'static str] = &["",
                                                             "robidoux",
                                                             "robidouxsharp",
                                                             "ginseng",
                                                             "lanczos",
                                                             "lanczos2",
                                                             "catmullrom",
                                                             "catrom",
                                                             "mitchell",
                                                             "cubicbspline",
                                                             "bspline",
                                                             "cubic_0_1",
                                                             "hermite",
                                                             "triangle",
                                                             "ncubic",
                                                             "ncubicsharp"];

pub const FILTER_OPTIONS: &'static [&'static str] = &["robidouxfast",
                                                      "robidoux",
                                                      "robidouxsharp",
                                                      "ginseng",
                                                      "ginsengsharp",
                                                      "lanczos",
                                                      "lanczossharp",
                                                      "lanczos2",
                                                      "lanczos2sharp",
                                                      "cubicfast",
                                                      "cubic_0_1",
                                                      "cubicsharp",
                                                      "catmullrom",
                                                      "catrom",
                                                      "mitchell",
                                                      "cubicbspline",
                                                      "bspline",
                                                      "hermite",
                                                      "jinc",
                                                      "rawlanczos3",
                                                      "rawlanczos3sharp",
                                                      "rawlanczos2",
                                                      "rawlanczos2sharp",
                                                      "triangle",
                                                      "linear",
                                                      "box",
                                                      "catmullromfast",
                                                      "catmullromfastsharp",
                                                      "fastest",
                                                      "mitchellfast",
                                                      "ncubic",
                                                      "ncubicsharp"];



impl Default for DecoderInfo {
    fn default() -> DecoderInfo {
        DecoderInfo {
            codec_id: -1,
            preferred_mime_type: ptr::null(),
            preferred_extension: ptr::null(),
            frame_count: 0,
            current_frame_index: 0,
            image_width: 0,
            image_height: 0,
            frame_decodes_into: PixelFormat::Bgra32,
        }
    }
}

#[repr(C)]
pub struct DecoderInfo {
    pub codec_id: i64,
    pub preferred_mime_type: *const i8,
    pub preferred_extension: *const i8,
    pub frame_count: usize,
    pub current_frame_index: i64,
    pub image_width: i32,
    pub image_height: i32,
    pub frame_decodes_into: PixelFormat,
}



#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct BitmapBgra {
    /// bitmap width in pixels
    pub w: u32,
    /// bitmap height in pixels
    pub h: u32,
    /// byte length of each row (may include any amount of padding)
    pub stride: u32,
    // FIXME: replace with a vec or slice
    /// pointer to pixel 0,0; should be of length > h * stride
    pub pixels: *mut u8,
    /// If true, we don't dispose of *pixels when we dispose the struct
    pub borrowed_pixels: bool,
    /// If false, we can even ignore the alpha channel on 4bpp
    pub alpha_meaningful: bool,
    /// If false, we can edit pixels without affecting the stride
    pub pixels_readonly: bool,
    /// If false, we can change the stride of the image
    pub stride_readonly: bool,
    /// If true, we can reuse the allocated memory for other purposes
    pub can_reuse_space: bool,
    pub fmt: PixelFormat,
    /// When using compositing mode blend_with_matte, this color will be used. We should probably define this as
    /// always being sRGBA, 4 bytes.
    pub matte_color: [u8; 4],

    pub compositing_mode: BitmapCompositingMode,
}
// imageflow_core::ffi::FlowBitmapBgra{
// alpha_meaningful: false,
// can_reuse_space: false,
// compositing_mode: ffi::BitmapCompositingMode::blend_with_self,
// matte_color: [0,0,0,0],
// pixels_readonly: false,
// stride_readonly: false,
// pixels: ptr::null_mut(),
// stride: 0,
// w: 0,
// h: 0,
// borrowed_pixels: false,
// fmt: ffi::PixelFormat::bgra32
// };



#[repr(C)]
#[derive(Copy,Clone,Debug,PartialEq)]
pub enum BitmapCompositingMode {
    ReplaceSelf = 0,
    BlendWithSelf = 1,
    BlendWithMatte = 2,
}


/// floating-point bitmap, typically linear RGBA, premultiplied
#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct BitmapFloat {
    /// buffer width in pixels
    w: uint32_t,
    /// buffer height in pixels
    h: uint32_t,
    /// The number of floats per pixel
    channels: uint32_t,
    /// The pixel data
    pixels: *mut c_float,
    /// If true, don't dispose the buffer with the struct
    pixels_borrowed: bool,
    /// The number of floats in the buffer
    float_count: uint32_t,
    /// The number of floats betwen (0,0) and (0,1)
    float_stride: uint32_t,

    /// If true, alpha has been premultiplied
    alpha_premultiplied: bool,
    /// If true, the alpha channel holds meaningful data
    alpha_meaningful: bool,
}

/** flow context: Heap Manager **/
#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct Heap {
    placeholder: u8, /* FIXME: fill in the rest
                      * flow_heap_calloc_function _calloc;
                      * flow_heap_malloc_function _malloc;
                      * flow_heap_realloc_function _realloc;
                      * flow_heap_free_function _free;
                      * flow_heap_terminate_function _context_terminate;
                      * void * _private_state;
                      * */
}

// struct flow_objtracking_info;
// void flow_context_objtracking_initialize(struct flow_objtracking_info * heap_tracking);
// void flow_context_objtracking_terminate(flow_c * c);

/** flow context: struct `flow_error_info` **/
// struct flow_error_callstack_line {
// const char * file;
// int line;
// const char * function_name;
// };
//
#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct ErrorInfo {
    placeholder: u8, /* FIXME: replace
                      * flow_status_code reason;
                      * struct flow_error_callstack_line callstack[14];
                      * int callstack_count;
                      * int callstack_capacity;
                      * bool locked;
                      * char message[FLOW_ERROR_MESSAGE_SIZE + 1];
                      * */
}

// #ifdef EXPOSE_SIGMOID
// flow context: Colorspace
// struct flow_SigmoidInfo {
// float constant;
// float x_coeff;
// float x_offset;
// float y_offset;
// float y_coeff;
// };
// #endif
//

#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct ColorspaceInfo {
    placeholder: u8, /* FIXME: replace
                      * float byte_to_float[256]; // Converts 0..255 -> 0..1, but knowing that 0.255 has sRGB gamma.
                      * flow_working_floatspace floatspace;
                      * bool apply_srgb;
                      * bool apply_gamma;
                      * float gamma;
                      * float gamma_inverse;
                      * #ifdef EXPOSE_SIGMOID
                      * struct flow_SigmoidInfo sigmoid;
                      * bool apply_sigmoid;
                      * #endif
                      * */
}

#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct HeapObjectRecord {
    placeholder: u8, /* FIXME: fill in the rest
                      * void * ptr;
                      * size_t bytes;
                      * void * owner;
                      * flow_destructor_function destructor;
                      * bool destructor_called;
                      * const char * allocated_by;
                      * int allocated_by_line;
                      * bool is_owner;
                      * */
}

#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct ObjTrackingInfo {
    pub allocs: HeapObjectRecord,
    pub next_free_slot: size_t,
    pub total_slots: size_t,
    pub bytes_allocated_net: size_t,
    pub bytes_allocated_gross: size_t,
    pub allocations_net: size_t,
    pub allocations_gross: size_t,
    pub bytes_free: size_t,
    pub allocations_net_peak: size_t,
    pub bytes_allocations_net_peak: size_t,
}

type CodecInitializeFn = extern "C" fn(*mut ImageflowContext, *mut CodecInstance) -> bool;
type CodecWriteFrameFn = extern "C" fn(*mut ImageflowContext,
                                       *mut libc::c_void,
                                       *mut BitmapBgra,
                                       *const EncoderHints)
                                       -> bool;


#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct CodecDefinition {
    pub codec_id: i64,
    pub initialize: Option<CodecInitializeFn>,
    get_info: *const libc::c_void,
    get_frame_info: *const libc::c_void,
    set_downscale_hints: *const libc::c_void,
    switch_frame: *const libc::c_void,
    read_frame: *const libc::c_void,
    pub write_frame: Option<CodecWriteFrameFn>,
    name: *const u8,
    preferred_mime_type: *const u8,
    preferred_extension: *const u8,
    placeholder: u8, // FIXME: replace
}

#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct ContextCodecSet {
    // FIXME: replace with a Vec?
    codecs: *mut CodecDefinition,
    codecs_count: size_t,
}


#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct ProfilingLog {
    placeholder: u8, // FIXME: replace
}



#[repr(C)]
#[derive(Copy,Clone,Debug,PartialEq)]
pub enum CodecType {
    Null = 0,
    DecodePng = 1,
    EncodePng = 2,
    DecodeJpeg = 3,
    EncodeJpeg = 4,
    DecodeGif = 5,
}


#[repr(C)]
#[derive(Copy,Clone,Debug,PartialEq)]
enum InterpolationFilter {
    RobidouxFast = 1,
    Robidoux = 2,
    RobidouxSharp = 3,
    Ginseng = 4,
    GinsengSharp = 5,
    Lanczos = 6,
    LanczosSharp = 7,
    Lanczos2 = 8,
    Lanczos2Sharp = 9,
    CubicFast = 10,
    Cubic = 11,
    CubicSharp = 12,
    CatmullRom = 13,
    Mitchell = 14,

    CubicBSpline = 15,
    Hermite = 16,
    Jinc = 17,
    RawLanczos3 = 18,
    RawLanczos3Sharp = 19,
    RawLanczos2 = 20,
    RawLanczos2Sharp = 21,
    Triangle = 22,
    Linear = 23,
    Box = 24,
    CatmullRomFast = 25,
    CatmullRomFastSharp = 26,

    Fastest = 27,

    MitchellFast = 28,

    NCubic = 29,

    NCubicSharp = 30,
}


#[repr(C)]
#[derive(Copy,Clone,Debug,PartialEq)]
enum ScaleFlags {
    None = 0,
    UseScale2d = 1,
}

#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct DecoderDownscaleHints {
    pub downscale_if_wider_than: int64_t,
    pub or_if_taller_than: int64_t,
    pub downscaled_min_width: int64_t,
    pub downscaled_min_height: int64_t,
    pub scale_luma_spatially: bool,
    pub gamma_correct_for_srgb_during_spatial_luma_scaling: bool,
}

#[repr(C)]
#[derive(Clone,Debug,PartialEq)]
pub struct EncoderHints {
    pub jpeg_encode_quality: int32_t,
    pub disable_png_alpha: bool,
}



#[repr(C)]
#[derive(Clone,Debug,Copy)]
pub struct Scale2dRenderToCanvas1d {
    // There will need to be consistency checks against the createcanvas node
    //
    // struct flow_interpolation_details * interpolationDetails;
    pub scale_to_width: i32,
    pub scale_to_height: i32,
    pub sharpen_percent_goal: f32,
    pub interpolation_filter: Filter,
    pub scale_in_colorspace: Floatspace,
}
#[repr(C)]
#[derive(Clone,Debug,Copy)]
pub struct RenderToCanvas1d {
    // There will need to be consistency checks against the createcanvas node
    pub interpolation_filter: Filter,
    pub scale_to_width: i32,
    pub transpose_on_write: bool, // Other fields skipped, not acessed.
}

#[repr(C)]
#[derive(Clone,Debug,Copy)]
pub struct Rect {
    pub x1: i32,
    pub y1: i32,
    pub x2: i32,
    pub y2: i32
}



// struct flow_nodeinfo_render_to_canvas_1d {
//    // There will need to be consistency checks against the createcanvas node
//
//    flow_interpolation_filter interpolation_filter;
//    // struct flow_interpolation_details * interpolationDetails;
//    int32_t scale_to_width;
//    bool transpose_on_write;
//    flow_working_floatspace scale_in_colorspace;
//
//    float sharpen_percent_goal;
//
//    flow_compositing_mode compositing_mode;
//    // When using compositing mode blend_with_matte, this color will be used. We should probably define this as always
//    // being sRGBA, 4 bytes.
//    uint8_t matte_color[4];
//
//    struct flow_scanlines_filter * filter_list;
// };

mod must_replace{
    use super::*;
    use ::libc;
    extern "C" {

    }

}

mod long_term{
    use super::*;
    use ::libc;
    extern "C" {
        pub fn flow_context_create() -> *mut ImageflowContext;
        pub fn flow_context_begin_terminate(context: *mut ImageflowContext) -> bool;
        pub fn flow_context_destroy(context: *mut ImageflowContext);
        pub fn flow_destroy(context: *mut ImageflowContext,
                            pointer: *const libc::c_void,
                            file: *const libc::c_char,
                            line: i32)
                            -> bool;



        pub fn flow_bitmap_bgra_flip_vertical(c: *mut ImageflowContext, bitmap: *mut BitmapBgra);
        pub fn flow_bitmap_bgra_flip_horizontal(c: *mut ImageflowContext, bitmap: *mut BitmapBgra);

        pub fn flow_bitmap_bgra_create(c: *mut ImageflowContext,
                                       sx: i32,
                                       sy: i32,
                                       zeroed: bool,
                                       format: PixelFormat)
                                       -> *mut BitmapBgra;


        pub fn flow_node_execute_scale2d_render1d(c: *mut ImageflowContext,
                                                  input: *mut BitmapBgra,
                                                  canvas: *mut BitmapBgra,
                                                  info: *const Scale2dRenderToCanvas1d)
                                                  -> bool;
        pub fn flow_node_execute_render_to_canvas_1d(c: *mut ImageflowContext,
                                                     input: *mut BitmapBgra,
                                                     canvas: *mut BitmapBgra,
                                                     info: *const RenderToCanvas1d)
                                                     -> bool;

        pub fn flow_bitmap_bgra_fill_rect(c: *mut ImageflowContext,
                                          input: *mut BitmapBgra,
                                          x1: u32,
                                          y1: u32,
                                          x2: u32,
                                          y2: u32,
                                          color_srgb_argb: u32)
                                          -> bool;
    }
}

mod mid_term {
    use super::*;
    use ::libc;

    extern "C" {
        pub fn flow_context_set_floatspace(c: *mut ImageflowContext,
                                           space: Floatspace,
                                           a: f32,
                                           b: f32,
                                           c: f32);



    pub fn flow_bitmap_bgra_load_png(c: *mut ImageflowContext,
    b_ref: *mut *const BitmapBgra,
    path: *const libc::c_char)
    -> bool;

        pub fn flow_bitmap_bgra_save_png(c: *mut ImageflowContext,
                                         input: *const BitmapBgra,
                                         path: *const libc::c_char)
                                         -> bool;

        pub fn flow_codecs_jpg_decoder_get_exif(context: *mut ImageflowContext,
                                                codec_instance: *mut CodecInstance)
                                                -> i32;

        pub fn flow_context_has_error(context: *mut ImageflowContext) -> bool;
        pub fn flow_context_clear_error(context: *mut ImageflowContext);
        pub fn flow_context_error_and_stacktrace(context: *mut ImageflowContext,
                                                 buffer: *mut u8,
                                                 buffer_length: libc::size_t,
                                                 full_file_path: bool)
                                                 -> i64;
        pub fn flow_context_print_and_exit_if_err(context: *mut ImageflowContext) -> bool;

        pub fn flow_context_error_reason(context: *mut ImageflowContext) -> i32;

        pub fn flow_context_set_error_get_message_buffer(context: *mut ImageflowContext,
                                                         code: i32, // FlowStatusCode
                                                         file: *const libc::c_char,
                                                         line: i32,
                                                         function_name: *const libc::c_char)
                                                         -> *const libc::c_char;

        pub fn flow_context_raise_error(context: *mut ImageflowContext,
                                        error_code: i32,
                                        message: *const libc::c_char,
                                        file: *const libc::c_char,
                                        line: i32,
                                        function_name: *const libc::c_char)
                                        -> bool;


        pub fn flow_context_add_to_callstack(context: *mut ImageflowContext,
                                             file: *const libc::c_char,
                                             line: i32,
                                             function_name: *const libc::c_char)
                                             -> bool;




        pub fn flow_context_calloc(context: *mut ImageflowContext,
                                   instance_count: usize,
                                   instance_size: usize,
                                   destructor: *const libc::c_void,
                                   owner: *const libc::c_void,
                                   file: *const libc::c_char,
                                   line: i32)
                                   -> *mut libc::c_void;


        pub fn flow_io_create_for_file(context: *mut ImageflowContext,
                                       mode: IoMode,
                                       filename: *const libc::c_char,
                                       owner: *const libc::c_void)
                                       -> *mut ImageflowJobIo;

        pub fn flow_io_create_from_memory(context: *mut ImageflowContext,
                                          mode: IoMode,
                                          memory: *const u8,
                                          length: libc::size_t,
                                          owner: *const libc::c_void,
                                          destructor_function: *const libc::c_void)
                                          -> *mut ImageflowJobIo;

        pub fn flow_io_create_for_output_buffer(context: *mut ImageflowContext,
                                                owner: *const libc::c_void)
                                                -> *mut ImageflowJobIo;


        // Returns false if the flow_io struct is disposed or not an output buffer type (or for any other error)
        //
        pub fn flow_io_get_output_buffer(context: *mut ImageflowContext,
                                         io: *mut ImageflowJobIo,
                                         result_buffer: *mut *const u8,
                                         result_buffer_length: *mut libc::size_t)
                                         -> bool;



        pub fn flow_codec_initialize(c: *mut ImageflowContext, instance: *mut CodecInstance) -> bool;

        pub fn flow_codec_get_definition(c: *mut ImageflowContext,
                                         codec_id: i64)
                                         -> *mut CodecDefinition;

        pub fn flow_codec_execute_read_frame(c: *mut ImageflowContext,
                                             instance: *mut CodecInstance)
                                             -> *mut BitmapBgra;

        pub fn flow_codec_select_from_seekable_io(context: *mut ImageflowContext, io: *mut ImageflowJobIo) -> i64;

        pub fn flow_codec_decoder_get_info(c: *mut ImageflowContext,
                                           codec_state: *mut libc::c_void, codec_id: i64, info: *mut DecoderInfo) -> bool;

        pub fn flow_codec_decoder_set_downscale_hints(c: *mut ImageflowContext,
                                                      instance: *mut CodecInstance, hints: *const DecoderDownscaleHints, crash_if_not_implemented: bool) -> bool;


        pub fn detect_content(c: *mut ImageflowContext, input: *mut BitmapBgra, threshold: u32 ) -> Rect;
    }
}

pub use self::must_replace::*;
pub use self::long_term::*;
pub use self::mid_term::*;



// https://github.com/rust-lang/rust/issues/17417


#[test]
fn flow_context_create_destroy_works() {
    unsafe {
        let c = flow_context_create();
        assert!(!c.is_null());

        flow_context_destroy(c);
    }
}