79489133

Date: 2025-03-06 11:17:48
Score: 0.5
Natty:
Report link

Alright, there are lots of problems here:

  1. Swig does not like the keyword const and I cannot find a solution for that other than dropping it.
  2. As Human006 said, there is a Problem with passing NumPy scalars to float*. out{R,G,B} is now a 3x1 array and declared as an INPLACE_ARRAY. The numpy Swig documentation exactly explains this problem and gives as solution, which did not work for me thou.
  3. You cannot wrap code with 3 arrays and one dimension, so exposing the function declaration with the %include statement at the end of the SWIG interface file will cause problems. Solution: Remove the include and wrap the function manually like in following SWIG file:
%module AesAutoWhiteBalance

%{
#define SWIG_FILE_WITH_INIT
#include "AesAutoWhiteBalance.h"
%}

// Include the NumPy typemaps
%include "numpy.i"

%init %{
import_array();
%}

%fragment("NumPy_Fragments");

// Wrap the AesAutoWhiteBalance_Balance function
%apply (unsigned short* IN_ARRAY1, int DIM1) { 
(unsigned short* measurementsR, int size_r), 
(unsigned short* measurementsG, int size_g), 
(unsigned short* measurementsB, int size_b) };

// Apply the typemaps for output argument
%apply (float* INPLACE_ARRAY1, int DIM1) { (float* balancingCoeffs, int out_size) };

/*  Manual wrapping comes here */
%inline %{
    /*  takes as input two numpy arrays */
    void balance(
    unsigned short * measurementsR, int size_r, 
    unsigned short * measurementsG, int size_g, 
    unsigned short * measurementsB, int size_b, 
    int bitWidth, 
    float* balancingCoeffs, int out_size
    ) {
        if(3 != out_size)
        {
            PyErr_Format(PyExc_ValueError, "Parameter balancingCoeffs must have length 3.");
            return;
        }
        if((size_r != size_g) || (size_r != size_b))
        {
            PyErr_Format(PyExc_ValueError, "The measurement arrays have different lengths: R:%d, G:%d, B:%d", size_r, size_g, size_b);
            return;
        }

        /*  calls the original funcion, providing only the size of the first */
        AesAutoWhiteBalance_Balance(measurementsR, measurementsG, measurementsB, size_r, bitWidth, balancingCoeffs);
        return;
    }
%}
Reasons:
  • Blacklisted phrase (1): did not work
  • Blacklisted phrase (1.5): I cannot find
  • Blacklisted phrase (0.5): I cannot
  • Whitelisted phrase (-2): Solution:
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Philli