Menu

Visual C++ 10 dll problem

Anonymous
2016-03-28
2016-03-31
1 2 3 > >> (Page 1 of 3)
  • Anonymous

    Anonymous - 2016-03-28

    Hi,

    I'm trying to compile a dll in Visual C++ 10 (W8.1) with the bilinear resize function (using the latest Simd version):

    #include "SimdMemory.h"
    #include "SimdBase.h"
    #include "SimdStore.h"
    #include "SimdLib.h"
    #include "SimdSse2.h"
    #include "SimdSsse3.h"
    
    extern "C"
    {
       DECLDIR unsigned char * sendpngframe(int frameindex, unsigned int &framesize, unsigned int &framedelay);
       DECLDIR int loadapngfile(unsigned char * bufdata, unsigned int bufsize);
       DECLDIR void closeapngfile(void);
       DECLDIR void registercallback(CallBackFunction func);
       DECLDIR void BilinearResize(const uint8_t *src, size_t srcWidth, size_t srcHeight, size_t srcStride, uint8_t *dst, size_t dstWidth, size_t dstHeight, size_t dstStride, size_t channelCount);
    }
    
    ....
    
    DECLDIR void BilinearResize(const uint8_t *src, size_t srcWidth, size_t srcHeight, size_t srcStride, uint8_t *dst, size_t dstWidth, size_t dstHeight, size_t dstStride, size_t channelCount)
    {
        Simd::Sse2::ResizeBilinear(src, srcWidth, srcHeight, srcStride, dst, dstWidth, dstHeight, dstStride, channelCount);
    }
    

    It compiles fine but I get an access violation in the host application when calling the exported function.
    The other 4 exported functions work fine.

    Is the declaration/usage of the resize function in dll ok?

    Btw, I have a Intel Celeron CPU with MMX..SSE4.2

    Thank you for your help.

     
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-03-28

    Hello.

    If you use Simd Library as DLL, then I want to notice that the library does not contain dll-exported function Simd::Sse2::ResizeBilinear(), only SimdResizeBilinear(). So if you try to call first one, then there will be an exception.

    It is strongly recomended to use only function SimdResizeBilinear(), because it performs checking of CPU capabilities and minimal size of output image (SIMD version of the function can't resize very small images) and then calls the best available method.

    If you anyway want to use Simd::Sse2::ResizeBilinear() directly, you have to compile Simd Library as static.

     
  • Anonymous

    Anonymous - 2016-03-28

    Thank you.

    If I try with SimdResizeBilinear() in dll the compiler says:

    error LNK2001: unresolved external symbol __imp__SimdResizeBilinear

    If I add the SimdLib.cpp to the project, I get the same error but for 275 functions (!).
    Should I add all the cpp files, even thow I only need a function?

     
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-03-28

    I'm sorry but I don't have Visual Studio 2010 to reproduce this bug.

    Maybe you need add project dependencies?

     
  • Anonymous

    Anonymous - 2016-03-28

    It doesn't say it needs any.
    Before adding Simd header files and the exported function it compiled fine.

     

    Last edit: Anonymous 2016-03-28
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-03-28

    Could you send me the project file?

     
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-03-28

    I don't see any *.cpp files of Simd Library in your project.
    It is not suprized that linker can't find implementation of SimdResizeBilinear - it is absent.

    You have to add all *.cpp files of Simd Library to your project.

     

    Last edit: Yermalayeu Ihar 2016-03-28
  • Anonymous

    Anonymous - 2016-03-28

    That's what I asked a few posts ago.

    So, now I have to edit each h and cpp file to remove the "Simd/" before the included header files (it doesn't accept the path in Windows).
    about 250+ times (I solved a few till now).

    And after compile all functions will be included in the dll although I only need a few.

    Isn't there other way?

     
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-03-28

    Don't change source of Simd Library!
    Change "Additional Include Directories" in your project from:
    ..\..;..\..\libpng;..\..\zlib;Simd;
    to:
    ..\..;..\..\libpng;..\..\zlib;.;

     

    Last edit: Yermalayeu Ihar 2016-03-28
  • Anonymous

    Anonymous - 2016-03-29

    How do I solve these problems from SimdSsse3ResizeBilinear.cpp (see screenshot).

     
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-03-29

    You can change

    indexes[0] = {0, 0};
    

    to

    indexes[0].src = 0;
    indexes[0].dst = 0;
    

    The first one is supported by c++ 11 compilers.

     
  • Anonymous

    Anonymous - 2016-03-29

    Question: what kind of data requires the SimdResizeBilinear function for the src and dest parameters?
    In my application I use the color of the pixels (BGR and BGRA) by default. The data is from the bottom of the bitmap to the top (line by line).
    Do I need to change to DIB, RGBA or from the top to bottom...?

    I ask because I get an access violation in SimdSse3ResizeBilinear >> template <size_t channelcount=""> void ResizeBilinear >> line 297..307 somewhere in this cycle:</size_t>

               for(; k < 2; k++)
                {
                    Two * pb = (Two *)buffer.bx[k];
                    const One * psrc = (const One *)(src + (sy + k)*srcStride);
                    for(size_t x = 0; x < dstWidth; x++)
                        pb[x] = *(Two *)(psrc + buffer.ix[x]);
    
                    uint8_t * pbx = buffer.bx[k];
                    for(size_t i = 0; i < bufferSize; i += step)
                        InterpolateX<channelCount>((__m128i*)(buffer.ax + i), (__m128i*)(pbx + i));
                }
    
     
  • Anonymous

    Anonymous - 2016-03-29

    Btw, it shows error in the second iteration of the cycle.

     
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-03-29

    The library supposes that the image begins from left-top point.
    Image data must be the one continuous bit array.
    Note that srcStride and dstStride may be differ from srcWidth*channelCount and dstWidth*channelCount.

     

    Last edit: Yermalayeu Ihar 2016-03-29
  • Anonymous

    Anonymous - 2016-03-29

    The host application is in Delphi.
    The bitmaps in Delphi are having data stored as a contiguous bit array, but from the begining of the last row to the end of the first row.
    So I have to reverse the row order (twice), which will take some time and decrease the speed. And high speed is what I need...

    And regarding srcStride and dstStride: what are they actually and where do I get them from the bitmap's characteristics?
    I thought there are the length of a row. I'm using only 24 and 32 bit bitmaps so it was easy multiplying the width with 3 and 4.

     
  • Anonymous

    Anonymous - 2016-03-29

    Anyway, using 32 bit bitmaps and 4 * bitmap width for row width it still breaks but in another place: line 308..309

                for(size_t ib = 0, id = 0; ib < alignedSize; ib += DA, id += A)
                    InterpolateY<true>(buffer.bx[0] + ib, buffer.bx[1] + ib, a, dst + id);
    

    At about the 3rd iteration for the cycle

    for(size_t yDst = 0; yDst < dstHeight; yDst++, dst += dstStride)

    At line 279 to 213

     
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-03-29

    Stride may be negative. It useful for vertical flipping of image. I think it is your case.
    In Windows stride of Bitmap is always multiple of 4.

     
  • Anonymous

    Anonymous - 2016-03-29

    Ok, it may be negative, but is it safe to use a negative value for a size_t parameter?

     
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-03-29

    In most case it is safe (if algoritm only adds or substracts stride). But of course I need to change interface of Simd Library.

     
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-03-29

    I checked - it works and for multiplication too.

     
  • Anonymous

    Anonymous - 2016-03-29

    It would be great if I wouldn't have to reverse the rows order :)
    And your library would be more useful to Delphi programmers too.
    If you intend to modify it thank you in advance.

    Oh, do you think that modification would also solve the last problem I described about 6 posts ago?

     
  • Yermalayeu Ihar

    Yermalayeu Ihar - 2016-03-29

    If src points to image bottom (start of last row) and if you use positive stride then program will be crashed on first or second row because it goes out of range of array.

     
  • Anonymous

    Anonymous - 2016-03-29

    Ok then, thank you for the clarification.
    I'll wait for the modification.

    And, btw, if you need help with something/anything don't hesitate to ask me.
    I will be glad to help you.

    Oh, just so you can understand for what I need the bilinear resize function, here is a test application:
    https://drive.google.com/open?id=0ByKxAD_t9uvLVWZFYVlFQ1BzVlU
    And a test file:
    https://drive.google.com/open?id=0ByKxAD_t9uvLZVRUa2tGZEYybGs
    Start the exe, load the file with the load button from the middle of the form and then click on preview.
    You can change the size of the result by using +/- or reset to default with 0.
    Your function will be used to resize the frames in real time.
    Right now I have a pretty good function (30 ms for a resize 768x768 to 700x700 on my 2 GHz processor). But it doesn't use MMX/SSE.
    I'm hoping your function, because it's using SSE2/3 will be faster.

     
1 2 3 > >> (Page 1 of 3)

Anonymous
Anonymous

Add attachments
Cancel