Sponsored Content
Full Discussion: matrix pointer
Top Forums Programming matrix pointer Post 302293116 by shamrock on Monday 2nd of March 2009 11:27:45 AM
Old 03-02-2009
Code:
/* creates a pointer named tab that points to an array of MAXCLASS items of type float */
float (*tab)[MAXCLASS];

/* 
  allocates memory for MAXCLASS elements each of size (MAXCLASS+1)*sizeof(float) bytes and
  initializes all memory locations to zeros and casts the pointer to the appropriate type
 */
tab=(float (*)[MAXCLASS]) calloc(MAXCLASS, (MAXCLASS+1)*sizeof(float));

The last one allocates too much memory and IMO the calloc should be...
Code:
/*
  allocates memory for MAXCLASS elements each of sizeof(float) bytes and sets
  the memory locations to zeros and casts the pointer to the appropriate type
 */
tab=(float (*)[MAXCLASS]) calloc(MAXCLASS, sizeof(float));

 

10 More Discussions You Might Find Interesting

1. Programming

pointer

void main() { int a={1,2,3,4,5,6,7,8,9,10}; int *p=a; int *q=&a; cout<<q-p+1<<endl; } The output is 10, how? if we give cout<<q it will print the address, value won't print.... if we give cout<<p it will print the address, value won't print.... p has the base addr; q... (1 Reply)
Discussion started by: sarwan
1 Replies

2. Programming

why we never delete a pointer twice

can u tell me the reson that why we should not delete a pointer twice.? if we delete ponter twice then what happen and why this happen Regards, Amit (2 Replies)
Discussion started by: amitpansuria
2 Replies

3. Programming

far pointer

what is far pointer in C (1 Reply)
Discussion started by: useless79
1 Replies

4. Programming

pass a pointer-to-pointer, or return a pointer?

If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it: (1) one is to pass a pointer-to-pointer parameter, like: int my_malloc(int size, char **pmem) { *pmem=(char *)malloc(size); if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies

5. Shell Programming and Scripting

diagonal matrix to square matrix

Hello, all! I am struggling with a short script to read a diagonal matrix for later retrieval. 1.000 0.234 0.435 0.123 0.012 0.102 0.325 0.412 0.087 0.098 1.000 0.111 0.412 0.115 0.058 0.091 0.190 0.045 0.058 1.000 0.205 0.542 0.335 0.054 0.117 0.203 0.125 1.000 0.587 0.159 0.357... (11 Replies)
Discussion started by: yifangt
11 Replies

6. Programming

pointer conversion in c

hi there fellos could someone teach me how to convert a character pointer into an integer using c much love (1 Reply)
Discussion started by: surubi_abada
1 Replies

7. Ubuntu

How to convert full data matrix to linearised left data matrix?

Hi all, Is there a way to convert full data matrix to linearised left data matrix? e.g full data matrix Bh1 Bh2 Bh3 Bh4 Bh5 Bh6 Bh7 Bh1 0 0.241058 0.236129 0.244397 0.237479 0.240767 0.245245 Bh2 0.241058 0 0.240594 0.241931 0.241975 ... (8 Replies)
Discussion started by: evoll
8 Replies

8. Shell Programming and Scripting

awk? adjacency matrix to adjacency list / correlation matrix to list

Hi everyone I am very new at awk but think that that might be the best strategy for this. I have a matrix very similar to a correlation matrix and in practical terms I need to convert it into a list containing the values from the matrix (one value per line) with the first field of the line (row... (5 Replies)
Discussion started by: stonemonkey
5 Replies

9. Programming

pointer problem

Does anyone know? int x = 1; int *p = &++x; //ok ! int *q = &x++; //gives an error :O why the first pointer is ok but the second is an error? (13 Replies)
Discussion started by: nishrestha
13 Replies

10. Programming

Pointer for 2D array seems to be 3D in C

I am struggling with the pointer to 2D-array (cf: 2D array of pointers). Can anybody help me elaborate how the pointer x moves in the memory to access the individual of y, especially the high lighted lines? I have talked to one of the curators of the forum, but I am still not quite clear. Here... (1 Reply)
Discussion started by: yifangt
1 Replies
COLOR(3TIFF)															      COLOR(3TIFF)

NAME
TIFFYCbCrToRGBInit, TIFFYCbCrtoRGB, TIFFCIELabToRGBInit, TIFFCIELabToXYZ, TIFFXYZToRGB - color conversion routines. SYNOPSIS
#include <tiffio.h> int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB *ycbcr, float *luma, float *refBlackWhite");" void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *ycbcr, uint32 Y, int32 Cb, int32 Cr, uint32 *R, uint32 *G, uint32 *B ); int TIFFCIELabToRGBInit(TIFFCIELabToRGB *cielab, TIFFDisplay *display, float *refWhite); void TIFFCIELabToXYZ(TIFFCIELabToRGB *cielab, uint32 L, int32 a, int32 b, float *X, float *Y, float *Z); void TIFFXYZToRGB(TIFFCIELabToRGB *cielab, float X, float Y, float Z",uint32*"R, uint32 *G, uint32 *B); DESCRIPTION
TIFF supports several color spaces for images stored in that format. There is usually a problem of application to handle the data properly and convert between different colorspaces for displaying and printing purposes. To simplify this task libtiff implements several color con- version routines itself. In particular, these routines used in TIFFRGBAImage(3TIFF) interface. TIFFYCbCrToRGBInit() used to initialize YCbCr to RGB conversion state. Allocating and freeing of the ycbcr structure belongs to programmer. TIFFYCbCrToRGB defined in tiffio.h as typedef struct { /* YCbCr->RGB support */ TIFFRGBValue* clamptab; /* range clamping table */ int* Cr_r_tab; int* Cb_b_tab; int32* Cr_g_tab; int32* Cb_g_tab; int32* Y_tab; } TIFFYCbCrToRGB; luma is a float array of three values representing proportions of the red, green and blue in luminance, Y (see section 21 of the TIFF 6.0 specification, where the YCbCr images discussed). TIFFTAG_YCBCRCOEFFICIENTS holds that values in TIFF file. refBlackWhite is a float array of 6 values which specifies a pair of headroom and footroom image data values (codes) for each image component (see section 20 of the TIFF 6.0 specification where the colorinmetry fields discussed). TIFFTAG_REFERENCEBLACKWHITE is responsible for storing these values in TIFF file. Following code snippet should helps to understand the the technique: float *luma, *refBlackWhite; uint16 hs, vs; /* Initialize structures */ ycbcr = (TIFFYCbCrToRGB*) _TIFFmalloc(TIFFroundup(sizeof(TIFFYCbCrToRGB), sizeof(long)) + 4*256*sizeof(TIFFRGBValue) + 2*256*sizeof(int) + 3*256*sizeof(int32)); if (ycbcr == NULL) { TIFFError("YCbCr->RGB", "No space for YCbCr->RGB conversion state"); exit(0); } TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRCOEFFICIENTS, &luma); TIFFGetFieldDefaulted(tif, TIFFTAG_REFERENCEBLACKWHITE, &refBlackWhite); if (TIFFYCbCrToRGBInit(ycbcr, luma, refBlackWhite) < 0) exit(0); /* Start conversion */ uint32 r, g, b; uint32 Y; int32 Cb, Cr; for each pixel in image TIFFYCbCrtoRGB(img->ycbcr, Y, Cb, Cr, &r, &g, &b); /* Free state structure */ _TIFFfree(ycbcr); TIFFCIELabToRGBInit() initializes the CIE L*a*b* 1976 to RGB conversion state. TIFFCIELabToRGB defined as #define CIELABTORGB_TABLE_RANGE 1500 typedef struct { /* CIE Lab 1976->RGB support */ int range; /* Size of conversion table */ float rstep, gstep, bstep; float X0, Y0, Z0; /* Reference white point */ TIFFDisplay display; float Yr2r[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yr to r */ float Yg2g[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yg to g */ float Yb2b[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yb to b */ } TIFFCIELabToRGB; display is a display device description, declared as typedef struct { float d_mat[3][3]; /* XYZ -> luminance matrix */ float d_YCR; /* Light o/p for reference white */ float d_YCG; float d_YCB; uint32 d_Vrwr; /* Pixel values for ref. white */ uint32 d_Vrwg; uint32 d_Vrwb; float d_Y0R; /* Residual light for black pixel */ float d_Y0G; float d_Y0B; float d_gammaR; /* Gamma values for the three guns */ float d_gammaG; float d_gammaB; } TIFFDisplay; For example, the one can use sRGB device, which has the following parameters: TIFFDisplay display_sRGB = { { /* XYZ -> luminance matrix */ { 3.2410F, -1.5374F, -0.4986F }, { -0.9692F, 1.8760F, 0.0416F }, { 0.0556F, -0.2040F, 1.0570F } }, 100.0F, 100.0F, 100.0F, /* Light o/p for reference white */ 255, 255, 255, /* Pixel values for ref. white */ 1.0F, 1.0F, 1.0F, /* Residual light o/p for black pixel */ 2.4F, 2.4F, 2.4F, /* Gamma values for the three guns */ }; refWhite is a color temperature of the reference white. The TIFFTAG_WHITEPOINT contains the chromaticity of the white point of the image from where the reference white can be calculated using following formulae: refWhite_Y = 100.0 refWhite_X = whitePoint_x / whitePoint_y * refWhite_Y refWhite_Z = (1.0 - whitePoint_x - whitePoint_y) / whitePoint_y * refWhite_X The conversion itself performed in two steps: at the first one we will convert CIE L*a*b* 1976 to CIE XYZ using TIFFCIELabToXYZ() routine, and at the second step we will convert CIE XYZ to RGB using TIFFXYZToRGB(). Look at the code sample below: float *whitePoint; float refWhite[3]; /* Initialize structures */ img->cielab = (TIFFCIELabToRGB *) _TIFFmalloc(sizeof(TIFFCIELabToRGB)); if (!cielab) { TIFFError("CIE L*a*b*->RGB", "No space for CIE L*a*b*->RGB conversion state."); exit(0); } TIFFGetFieldDefaulted(tif, TIFFTAG_WHITEPOINT, &whitePoint); refWhite[1] = 100.0F; refWhite[0] = whitePoint[0] / whitePoint[1] * refWhite[1]; refWhite[2] = (1.0F - whitePoint[0] - whitePoint[1]) / whitePoint[1] * refWhite[1]; if (TIFFCIELabToRGBInit(cielab, &display_sRGB, refWhite) < 0) { TIFFError("CIE L*a*b*->RGB", "Failed to initialize CIE L*a*b*->RGB conversion state."); _TIFFfree(cielab); exit(0); } /* Now we can start to convert */ uint32 r, g, b; uint32 L; int32 a, b; float X, Y, Z; for each pixel in image TIFFCIELabToXYZ(cielab, L, a, b, &X, &Y, &Z); TIFFXYZToRGB(cielab, X, Y, Z, &r, &g, &b); /* Don't forget to free the state structure */ _TIFFfree(cielab); SEE ALSO
TIFFRGBAImage(3TIFF) libtiff(3TIFF), Libtiff library home page: http://www.remotesensing.org/libtiff/ libtiff December 21, 2003 COLOR(3TIFF)
All times are GMT -4. The time now is 10:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy