The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Farabi on April 21, 2009, 03:15:10 AM

Title: Translating C header
Post by: Farabi on April 21, 2009, 03:15:10 AM
Am I right translating it?
Quote
  typedef struct _IplImage
    {
        int  nSize;         /* sizeof(IplImage) */
        int  ID;            /* version (=0)*/
        int  nChannels;     /* Most of OpenCV functions support 1,2,3 or 4 channels */
        int  alphaChannel;  /* ignored by OpenCV */
        int  depth;         /* pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16U,
                               IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported */
        char colorModel[4]; /* ignored by OpenCV */
        char channelSeq[4]; /* ditto */
        int  dataOrder;     /* 0 - interleaved color channels, 1 - separate color channels.
                               cvCreateImage can only create interleaved images */
        int  origin;        /* 0 - top-left origin,
                               1 - bottom-left origin (Windows bitmaps style) */
        int  align;         /* Alignment of image rows (4 or 8).
                               OpenCV ignores it and uses widthStep instead */
        int  width;         /* image width in pixels */
        int  height;        /* image height in pixels */
        struct _IplROI *roi;/* image ROI. when it is not NULL, this specifies image region to process */
        struct _IplImage *maskROI; /* must be NULL in OpenCV */
        void  *imageId;     /* ditto */
        struct _IplTileInfo *tileInfo; /* ditto */
        int  imageSize;     /* image data size in bytes
                               (=image->height*image->widthStep
                               in case of interleaved data)*/
        char *imageData;  /* pointer to aligned image data */
        int  widthStep;   /* size of aligned image row in bytes */
        int  BorderMode[4]; /* border completion mode, ignored by OpenCV */
        int  BorderConst[4]; /* ditto */
        char *imageDataOrigin; /* pointer to a very origin of image data
                                  (not necessarily aligned) -
                                  it is needed for correct image deallocation */
    }
    IplImage;

Quote


Quote
IplImage struct
nSize         dword 0;         /* sizeof(IplImage) */
ID            dword 0;            /* version (=0)*/
nChannels      dword 0;     /* Most of OpenCV functions support 1,2,3 or 4 channels */
alphaChannel   dword 0;  /* ignored by OpenCV */
depth         dword 0   ;         /* pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16U,
                               IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported */
colorModel      dword 0; /* ignored by OpenCV */
channelSeq      dword 0; /* ditto */
dataOrder      dword 0;     /* 0 - interleaved color channels, 1 - separate color channels.
                               cvCreateImage can only create interleaved images */
origin         dword 0;        /* 0 - top-left origin,
                       ;        1 - bottom-left origin (Windows bitmaps style) */
_align         dword 0;         /* Alignment of image rows (4 or 8).
                               OpenCV ignores it and uses widthStep instead */
_width         dword 0;         /* image width in pixels */
height         dword 0;        /* image height in pixels */
roi            dword 0;/* image ROI. when it is not NULL, this specifies image region to process */
maskROI         dword 0; /* must be NULL in OpenCV */
imageId         dword 0;     /* ditto */
tileInfo      dword 0; /* ditto */
imageSize      dword 0;     /* image data size in bytes
                               (=image->height*image->widthStep
                               in case of interleaved data)*/
imageData      dword 0;  /* pointer to aligned image data */
widthStep      dword 0;   /* size of aligned image row in bytes */
BorderMode      dword 0; /* border completion mode, ignored by OpenCV */
BorderMode1      dword 0
BorderMode2      dword 0
BorderMode3      dword 0   
BorderConst      dword 0
BorderConst1   dword 0
BorderConst2   dword 0
BorderConst3   dword 0

imageDataOrigin   dword 0 ; /* pointer to a very origin of image data
IplImage ends
Title: Re: Translating C header
Post by: donkey on April 21, 2009, 03:28:46 AM
Though the colorModel and channelSeq are 4 bytes that does not make them DWORDs, the byte order of a DWORD is reversed, the reason they have been defined as  BYTE 4 DUP (?) is so the order remains unchanged...

IplImage STRUCT
nSize DWORD ?
ID DWORD ?
nChannels DWORD ?
alphaChannel DWORD ?
depth DWORD ?
colorModel BYTE 4 DUP (?)
channelSeq BYTE 4 DUP (?)
dataOrder DWORD ?
origin DWORD ?
align DWORD ?
width DWORD ?
height DWORD ?
roi DWORD ?
maskROI DWORD ?
imageId DWORD ?
tileInfo DWORD ?
imageSize DWORD ?
imageData DWORD ?
widthStep DWORD ?
BorderMode  DWORD 4 DUP (?)
BorderConst  DWORD 4 DUP (?)
imageDataOrigin  DWORD ?
IplImage ENDS
Title: Re: Translating C header
Post by: Farabi on April 21, 2009, 12:11:14 PM
Thanks donkey  :U
Title: Re: Translating C header
Post by: Farabi on April 29, 2009, 01:54:58 AM
What does this mean?

Quote
#ifndef MIN
#define MIN(a,b)  ((a) > (b) ? (b) : (a))
#endif
Title: Re: Translating C header
Post by: donkey on April 29, 2009, 02:31:33 AM
It is a macro, if a > b then return b, if a <= b then return a, it simply returns the smaller of the 2 parameters.

MACRO(Parameters) (Condition ? result TRUE : result FALSE)

In GoAsm the macro would be something like this:

MIN(%a,%b) MACRO
mov eax,%a
mov edx,%b
cmp edx,eax
jg >
xchg eax,edx
:
ENDM

MAX(%a,%b) MACRO
mov eax,%a
mov edx,%b
cmp edx,eax
jl >
xchg eax,edx
:
ENDM


Ofcourse it would overwrite EAX and EDX
Title: Re: Translating C header
Post by: Farabi on April 29, 2009, 05:39:19 AM
 :U Thanks I got it.
I can simply use japhets H2INC tools but I need to understand that first.
Title: Re: Translating C header
Post by: Farabi on May 03, 2009, 12:29:45 PM
Quote
   for(iTrain=0; iTrain<nTrainFaces; iTrain++)
   {
      double distSq=0;

      for(i=0; i<nEigens; i++)
      {
         float d_i =
            projectedTestFace -
            projectedTrainFaceMat->data.fl[iTrain*nEigens + i];
         //distSq += d_i*d_i / eigenValMat->data.fl;  // Mahalanobis
         distSq += d_i*d_i; // Euclidean
      }

      if(distSq < leastDistSq)
      {
         leastDistSq = distSq;
         iNearest = iTrain;
      }
   }

Is this code mean distSq reseted on every loop to 0?
Title: Re: Translating C header
Post by: mitchi on May 03, 2009, 07:57:47 PM
yes...
Title: Re: Translating C header
Post by: Farabi on May 04, 2009, 01:36:40 AM
Quote from: mitchi on May 03, 2009, 07:57:47 PM
yes...

Thanks.
Title: Re: Translating C header
Post by: Farabi on May 04, 2009, 07:32:37 AM
WHat does this do?
Quote
#define CV_CN_SHIFT   3
#define CV_8U   0
#define CV_8S   1
#define CV_16U  2
#define CV_16S  3
#define CV_32S  4
#define CV_32F  5
#define CV_64F  6
#define CV_USRTYPE1 7
#define CV_MAKETYPE(depth,cn) ((depth) + (((cn)-1) << CV_CN_SHIFT))

I need to know what value #define CV_32SC1 CV_MAKETYPE(CV_32S,1) is.

I simply put 4, but it seems does not work.
Title: Re: Translating C header
Post by: Farabi on May 04, 2009, 10:23:18 AM
Nevermind, I understand it.
Title: Re: Translating C header
Post by: rags on May 04, 2009, 10:25:18 AM
Farabi here is a website that should help you understand C better.
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/
Title: Re: Translating C header
Post by: ToutEnMasm on May 04, 2009, 12:18:37 PM

Made by the translator, It is nort always like that (for macro)
Quote
CV_CN_SHIFT   equ   < 3>
CV_8U   equ   < 0>
CV_8S   equ   < 1>
CV_16U   equ   < 2>
CV_16S   equ   < 3>
CV_32S   equ   < 4>
CV_32F   equ   < 5>
CV_64F   equ   < 6>
CV_USRTYPE1   equ   < 7>
   CV_MAKETYPE MACRO depth,cn
      local Value
      Value equ   depth +((  cn - 1 ) SHL CV_CN_SHIFT )
      EXITM <Value>
      ENDM

Title: Re: Translating C header
Post by: Farabi on May 04, 2009, 02:38:03 PM
Quote from: rags on May 04, 2009, 10:25:18 AM
Farabi here is a website that should help you understand C better.
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/


Thanks, so thats where the header is. I dont have any C compiler here.
Title: Re: Translating C header
Post by: Farabi on May 04, 2009, 02:38:40 PM
Quote from: ToutEnMasm on May 04, 2009, 12:18:37 PM

Made by the translator, It is nort always like that (for macro)
Quote
CV_CN_SHIFT   equ   < 3>
CV_8U   equ   < 0>
CV_8S   equ   < 1>
CV_16U   equ   < 2>
CV_16S   equ   < 3>
CV_32S   equ   < 4>
CV_32F   equ   < 5>
CV_64F   equ   < 6>
CV_USRTYPE1   equ   < 7>
   CV_MAKETYPE MACRO depth,cn
      local Value
      Value equ   depth +((  cn - 1 ) SHL CV_CN_SHIFT )
      EXITM <Value>
      ENDM


Thanks, I really need the translation.
Title: Re: Translating C header
Post by: Farabi on May 06, 2009, 02:44:39 AM
Is this
Quote
projectedTrainFaceMat->data.fl + i*offset
same with this?
Quote
projectedTrainFaceMat->data.fl[ i*offset]

Title: Re: Translating C header
Post by: Farabi on May 07, 2009, 12:28:57 PM
h2incx cannot translate this, anyone know what this mean?
Quote
#define CV_SEQUENCE_FIELDS()                                              \
    CV_TREE_NODE_FIELDS(CvSeq);                                           \
    int       total;          /* Total number of elements.            */  \
    int       elem_size;      /* Size of sequence element in bytes.   */  \
    schar*    block_max;      /* Maximal bound of the last block.     */  \
    schar*    ptr;            /* Current write pointer.               */  \
    int       delta_elems;    /* Grow seq this many at a time.        */  \
    CvMemStorage* storage;    /* Where the seq is stored.             */  \
    CvSeqBlock* free_blocks;  /* Free blocks list.                    */  \
    CvSeqBlock* first;        /* Pointer to the first sequence block. */

typedef struct CvSeq
{
    CV_SEQUENCE_FIELDS()
}
CvSeq;
Title: Re: Translating C header
Post by: ToutEnMasm on May 07, 2009, 04:54:29 PM
This is a class definition,not translatable (c++)
For translate,you must identify what is each term.
In particular [CV_TREE_NODE_FIELDS(CvSeq)] ,Function ?,others are dword (data declare)
If CV_TREE_NODE_FIELDS contant,repeat structure ?!
/FA (c++ flat assembler ) can be of great help

Title: Re: Translating C header
Post by: Farabi on May 19, 2009, 09:28:37 AM

#define CV_TREE_NODE_FIELDS(node_type)                               \
    int       flags;             /* Miscellaneous flags.     */      \
    int       header_size;       /* Size of sequence header. */      \
    struct    node_type* h_prev; /* Previous sequence.       */      \
    struct    node_type* h_next; /* Next sequence.           */      \
    struct    node_type* v_prev; /* 2nd previous sequence.   */      \
    struct    node_type* v_next  /* 2nd next sequence.       */

/*
   Read/Write sequence.
   Elements can be dynamically inserted to or deleted from the sequence.
*/
#define CV_SEQUENCE_FIELDS()                                              \
    CV_TREE_NODE_FIELDS(CvSeq);                                           \
    int       total;          /* Total number of elements.            */  \
    int       elem_size;      /* Size of sequence element in bytes.   */  \
    schar*    block_max;      /* Maximal bound of the last block.     */  \
    schar*    ptr;            /* Current write pointer.               */  \
    int       delta_elems;    /* Grow seq this many at a time.        */  \
    CvMemStorage* storage;    /* Where the seq is stored.             */  \
    CvSeqBlock* free_blocks;  /* Free blocks list.                    */  \
    CvSeqBlock* first;       
#define CV_CONTOUR_FIELDS()  \
    CV_SEQUENCE_FIELDS()     \
    CvRect rect;             \
    int color;               \
    int reserved[3];

typedef struct CvContour
{
    CV_CONTOUR_FIELDS()
}
CvContour;



I need to find out how much byte the CvContour size it, this is so complicated.
Title: Re: Translating C header
Post by: Farabi on May 19, 2009, 09:30:56 AM
Quote from: Farabi on May 19, 2009, 09:28:37 AM

#define CV_TREE_NODE_FIELDS(node_type)                               \
    int       flags;             /* Miscellaneous flags.     */      \
    int       header_size;       /* Size of sequence header. */      \
    struct    node_type* h_prev; /* Previous sequence.       */      \
    struct    node_type* h_next; /* Next sequence.           */      \
    struct    node_type* v_prev; /* 2nd previous sequence.   */      \
    struct    node_type* v_next  /* 2nd next sequence.       */

/*
   Read/Write sequence.
   Elements can be dynamically inserted to or deleted from the sequence.
*/
#define CV_SEQUENCE_FIELDS()                                              \
    CV_TREE_NODE_FIELDS(CvSeq);                                           \
    int       total;          /* Total number of elements.            */  \
    int       elem_size;      /* Size of sequence element in bytes.   */  \
    schar*    block_max;      /* Maximal bound of the last block.     */  \
    schar*    ptr;            /* Current write pointer.               */  \
    int       delta_elems;    /* Grow seq this many at a time.        */  \
    CvMemStorage* storage;    /* Where the seq is stored.             */  \
    CvSeqBlock* free_blocks;  /* Free blocks list.                    */  \
    CvSeqBlock* first;       
#define CV_CONTOUR_FIELDS()  \
    CV_SEQUENCE_FIELDS()     \
    CvRect rect;             \
    int color;               \
    int reserved[3];

typedef struct CvContour
{
    CV_CONTOUR_FIELDS()
}
CvContour;



I need to find out how much byte the CvContour size it, this is so complicated.

I simply translate it to this but does not work
Quote
CvContour struct
   flags dword 0
   header_size dword 0
   h_prev dword 0
   h_next dword 0
   v_prev dword 0
   v_next dword 0
   total dword 0
   elem_size dword 0
   block_max dword 0
   _ptr dword 0
   delta_elems dword 0
   storage dword 0
   free_blocks dword 0
   first dword 0
   rect RECT <0>
   color dword 0
   reserved dword 3 dup (0)
CvContour ends
Title: Re: Translating C header
Post by: bruce1948 on May 20, 2009, 01:27:48 AM





Quote from: Farabi on May 19, 2009, 09:30:56 AM
Quote from: Farabi on May 19, 2009, 09:28:37 AM

#define CV_TREE_NODE_FIELDS(node_type)                               \
    int       flags;             /* Miscellaneous flags.     */      \
    int       header_size;       /* Size of sequence header. */      \
    struct    node_type* h_prev; /* Previous sequence.       */      \
    struct    node_type* h_next; /* Next sequence.           */      \
    struct    node_type* v_prev; /* 2nd previous sequence.   */      \
    struct    node_type* v_next  /* 2nd next sequence.       */

/*
   Read/Write sequence.
   Elements can be dynamically inserted to or deleted from the sequence.
*/
#define CV_SEQUENCE_FIELDS()                                              \
    CV_TREE_NODE_FIELDS(CvSeq);                                           \
    int       total;          /* Total number of elements.            */  \
    int       elem_size;      /* Size of sequence element in bytes.   */  \
    schar*    block_max;      /* Maximal bound of the last block.     */  \
    schar*    ptr;            /* Current write pointer.               */  \
    int       delta_elems;    /* Grow seq this many at a time.        */  \
    CvMemStorage* storage;    /* Where the seq is stored.             */  \
    CvSeqBlock* free_blocks;  /* Free blocks list.                    */  \
    CvSeqBlock* first;       
#define CV_CONTOUR_FIELDS()  \
    CV_SEQUENCE_FIELDS()     \
    CvRect rect;             \
    int color;               \
    int reserved[3];

typedef struct CvContour
{
    CV_CONTOUR_FIELDS()
}
CvContour;



I need to find out how much byte the CvContour size it, this is so complicated.

I simply translate it to this but does not work
Quote
CvContour struct
   flags dword 0
   header_size dword 0
   h_prev dword 0
   h_next dword 0
   v_prev dword 0
   v_next dword 0
   total dword 0
   elem_size dword 0
   block_max dword 0
   _ptr dword 0
   delta_elems dword 0
   storage dword 0
   free_blocks dword 0
   first dword 0
   rect RECT <0>
   color dword 0
   reserved dword 3 dup (0)
CvContour ends





These are C macros and some of them take parameters. The first one takes a parameter of node_type and sets h_prev etc to be pointers to the structure which is passed as the macro parameter. You really have to find out where the macros are used and what the parameter passed to them is.  I suspect that they may be used in the code to put items on the stack. Not an easy task to convert this.
Title: Re: Translating C header
Post by: bruce1948 on May 20, 2009, 06:55:43 PM
I've looked at this again and are you sure that a CvRect is the same as a standard RECT?
Title: Re: Translating C header
Post by: Farabi on May 21, 2009, 04:40:31 AM
Quote from: bruce1948 on May 20, 2009, 06:55:43 PM
I've looked at this again and are you sure that a CvRect is the same as a standard RECT?
Yep I sure, the only different is there is no x2 and y2 but width and height.
After an hours trying I think the fist 6 parameter is right, but the other is unknown, I guess that is enough because I only need that first 6 parameter.
Title: Re: Translating C header
Post by: bruce1948 on May 21, 2009, 07:34:50 AM
Yeas the first 6 look OK to me.