Class: MorandiNative::RedEye

Inherits:
Object
  • Object
show all
Defined in:
lib/morandi/redeye.rb,
ext/morandi_native/morandi_native.c

Defined Under Namespace

Classes: Region

Instance Method Summary collapse

Constructor Details

#initialize(__v_pixbuf, __v_minX, __v_minY, __v_maxX, __v_maxY) ⇒ Object



758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
# File 'ext/morandi_native/morandi_native.c', line 758

static VALUE
RedEye_initialize(VALUE self OPTIONAL_ATTR, VALUE __v_pixbuf OPTIONAL_ATTR, VALUE __v_minX OPTIONAL_ATTR, VALUE __v_minY
                  OPTIONAL_ATTR, VALUE __v_maxX OPTIONAL_ATTR, VALUE __v_maxY OPTIONAL_ATTR) {
    GdkPixbuf *pixbuf;
    GdkPixbuf *__orig_pixbuf;
    int minX;
    int __orig_minX;
    int minY;
    int __orig_minY;
    int maxX;
    int __orig_maxX;
    int maxY;
    int __orig_maxY;
    __orig_pixbuf = pixbuf = GDK_PIXBUF(RVAL2GOBJ(__v_pixbuf));
    __orig_minX = minX = NUM2INT(__v_minX);
    __orig_minY = minY = NUM2INT(__v_minY);
    __orig_maxX = maxX = NUM2INT(__v_maxX);
    __orig_maxY = maxY = NUM2INT(__v_maxY);

    do {
        redeyeop_t *op;
        Data_Get_Struct(self, redeyeop_t, op);
        op->pixbuf = pixbuf;
        op->preview = NULL;
        g_object_ref(op->pixbuf);
        op->area.minX = minX;
        op->area.maxX = maxX;
        op->area.minY = minY;
        op->area.maxY = maxY;
        op->area.width = maxX - minX + 1;
        op->area.height = maxY - minY + 1;
        g_assert(op->pixbuf != NULL);
        g_assert(op->area.maxX <= gdk_pixbuf_get_width(op->pixbuf));
        g_assert(op->area.minX >= 0);
        g_assert(op->area.minX < op->area.maxX);
        g_assert(op->area.maxY <= gdk_pixbuf_get_height(op->pixbuf));
        g_assert(op->area.minY >= 0);
        g_assert(op->area.minY < op->area.maxY);
        op->mask = ALLOC_N(
        int, op->area.width * op->area.height);
        op->regions.data = ALLOC_N(
        int, op->area.width * op->area.height);
        op->regions.region = ALLOC_N(region_info, NO_REGIONS_DEFAULT);
        op->regions.len = 0;
        op->regions.size = NO_REGIONS_DEFAULT;

    } while (0);

    ;
    return Qnil;
}

Instance Method Details

#correct_blob(__v_blob_id) ⇒ Object



876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
# File 'ext/morandi_native/morandi_native.c', line 876

static VALUE
RedEye_correct_blob(VALUE self OPTIONAL_ATTR, VALUE __v_blob_id OPTIONAL_ATTR) {
    int blob_id;
    int __orig_blob_id;
    __orig_blob_id = blob_id = NUM2INT(__v_blob_id);

    do {
        redeyeop_t *op;
        Data_Get_Struct(self, redeyeop_t, op);
        if (op->regions.len <= blob_id)
            rb_raise(rb_eIndexError, "Only %i blobs in region - %i is invalid", op->regions.len, blob_id);
        desaturate_blob(op, blob_id);

    } while (0);

    return Qnil;
}

#highlight_blob(*__p_argv, self) ⇒ Object



894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
# File 'ext/morandi_native/morandi_native.c', line 894

static VALUE
RedEye_highlight_blob(int __p_argc, VALUE *__p_argv, VALUE self) {
    VALUE __v_blob_id = Qnil;
    int blob_id;
    int __orig_blob_id;
    VALUE __v_col = Qnil;
    int col;
    int __orig_col;

    /* Scan arguments */
    rb_scan_args(__p_argc, __p_argv, "11", &__v_blob_id, &__v_col);

    /* Set defaults */
    __orig_blob_id = blob_id = NUM2INT(__v_blob_id);

    if (__p_argc > 1)
        __orig_col = col = NUM2INT(__v_col);
    else
        col = 0x00ff00;

    do {
        redeyeop_t *op;
        Data_Get_Struct(self, redeyeop_t, op);
        if (op->regions.len <= blob_id)
            rb_raise(rb_eIndexError, "Only %i blobs in region - %i is invalid", op->regions.len, blob_id);
        highlight_blob(op, blob_id, col);

    } while (0);

    return Qnil;
}

#identify_blobs(*__p_argv, self) ⇒ Object



810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
# File 'ext/morandi_native/morandi_native.c', line 810

static VALUE
RedEye_identify_blobs(int __p_argc, VALUE *__p_argv, VALUE self) {
    VALUE __p_retval OPTIONAL_ATTR = Qnil;
    VALUE __v_green_sensitivity = Qnil;
    double green_sensitivity;
    double __orig_green_sensitivity;
    VALUE __v_blue_sensitivity = Qnil;
    double blue_sensitivity;
    double __orig_blue_sensitivity;
    VALUE __v_min_red_val = Qnil;
    int min_red_val;
    int __orig_min_red_val;

    /* Scan arguments */
    rb_scan_args(__p_argc, __p_argv, "03", &__v_green_sensitivity, &__v_blue_sensitivity, &__v_min_red_val);

    /* Set defaults */
    if (__p_argc > 0)
        __orig_green_sensitivity = green_sensitivity = NUM2DBL(__v_green_sensitivity);
    else
        green_sensitivity = 2.0;

    if (__p_argc > 1)
        __orig_blue_sensitivity = blue_sensitivity = NUM2DBL(__v_blue_sensitivity);
    else
        blue_sensitivity = 0.0;

    if (__p_argc > 2)
        __orig_min_red_val = min_red_val = NUM2INT(__v_min_red_val);
    else
        min_red_val = MIN_RED_VAL;

    do {
        redeyeop_t *op;
        Data_Get_Struct(self, redeyeop_t, op);
        MEMZERO(op->mask,
        int, op->area.width * op->area.height);
        MEMZERO(op->regions.data,
        int, op->area.width * op->area.height);
        identify_possible_redeye_pixels(op, green_sensitivity, blue_sensitivity, min_red_val);
        identify_blob_groupings(op);
        volatile VALUE ary =
                rb_ary_new2(op->regions.len);
        int i;
        for (i = MIN_ID;
             i < op->regions.len;
             i++) {
            region_info *r =
                    &op->regions.region[i];
            /* Ignore CCD noise */ if (r->noPixels < 2) continue;
            rb_ary_push(ary, rb_struct_new(structRegion, self, INT2NUM(i), INT2NUM(r->minX), INT2NUM(r->minY),
                                           INT2NUM(r->maxX), INT2NUM(r->maxY), INT2NUM(r->width), INT2NUM(r->height),
                                           INT2NUM(r->noPixels)));
        }
        do {
            __p_retval = ary;
            goto out;
        }
        while (0);

    } while (0);

    out:
    return __p_retval;
}

#pixbufObject



992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
# File 'ext/morandi_native/morandi_native.c', line 992

static VALUE
RedEye_pixbuf(VALUE self OPTIONAL_ATTR) {
    VALUE __p_retval OPTIONAL_ATTR = Qnil;

    do {
        redeyeop_t *op;
        Data_Get_Struct(self, redeyeop_t, op);
        do {
            __p_retval = GOBJ2RVAL(GDK_PIXBUF(op->pixbuf));
            goto out;
        }
        while (0);

    } while (0);

    out:
    return __p_retval;
}

#previewObject



973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
# File 'ext/morandi_native/morandi_native.c', line 973

static VALUE
RedEye_preview(VALUE self OPTIONAL_ATTR) {
    VALUE __p_retval OPTIONAL_ATTR = Qnil;

    do {
        redeyeop_t *op;
        Data_Get_Struct(self, redeyeop_t, op);
        do {
            __p_retval = GOBJ2RVAL(GDK_PIXBUF(redeye_preview(op, FALSE)));
            goto out;
        }
        while (0);

    } while (0);

    out:
    return __p_retval;
}

#preview_blob(*__p_argv, self) ⇒ Object



926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
# File 'ext/morandi_native/morandi_native.c', line 926

static VALUE
RedEye_preview_blob(int __p_argc, VALUE *__p_argv, VALUE self) {
    VALUE __p_retval OPTIONAL_ATTR = Qnil;
    VALUE __v_blob_id = Qnil;
    int blob_id;
    int __orig_blob_id;
    VALUE __v_col = Qnil;
    int col;
    int __orig_col;
    VALUE __v_reset_preview = Qnil;
    gboolean reset_preview;
    gboolean __orig_reset_preview;

    /* Scan arguments */
    rb_scan_args(__p_argc, __p_argv, "12", &__v_blob_id, &__v_col, &__v_reset_preview);

    /* Set defaults */
    __orig_blob_id = blob_id = NUM2INT(__v_blob_id);

    if (__p_argc > 1)
        __orig_col = col = NUM2INT(__v_col);
    else
        col = 0x00ff00;

    if (__p_argc > 2)
        __orig_reset_preview = reset_preview = RTEST(__v_reset_preview);
    else
        reset_preview = TRUE;

    do {
        redeyeop_t *op;
        Data_Get_Struct(self, redeyeop_t, op);
        if (op->regions.len <= blob_id)
            rb_raise(rb_eIndexError, "Only %i blobs in region - %i is invalid", op->regions.len, blob_id);
        preview_blob(op, blob_id, col, reset_preview);
        do {
            __p_retval = GOBJ2RVAL(GDK_PIXBUF(op->preview));
            goto out;
        }
        while (0);

    } while (0);

    out:
    return __p_retval;
}