Welcome to iraf.net Thursday, April 25 2024 @ 01:12 PM GMT


 Forum Index > Help Desk > Systems New Topic Post Reply
 CDL improve stuff
   
Jason Quinn
 12/09/2015 01:14PM (Read 1416 times)  
+++++
Active Member

Status: offline


Registered: 04/07/2006
Posts: 175
In CDL, there's a few sequence point issues in eps.c in the functions eps_writeMono() and eps_writeMonoRGB(). I think I know what was intended by the code but since the actual behavior of the code is not well-defined, I have to ask what the intended behavior is. Both sections use the MONO macro from eps.h:

PHP Formatted Code
#define MONO(rd,gn,bl) ((int)(rd*11 + gn*16 + bl*5) >> 5)  /*.33R+ .5G+ .17B*/


The parameters of this macro are missing their parenthesis guards and it should itself be changed to

PHP Formatted Code
#define MONO(rd,gn,bl) ((int)((rd)*11 + (gn)*16 + (bl)*5) >> 5)  /*.33R+ .5G+ .17B*/


to prevent unintuitive behavior. For example using the current definition, if x and y are some values, MONO(x+y,0,0) would not in general be equal to MONO((x+y),0,0). (Also, off the top of my head I don't know where the ".33R+ .5G+ .17B" values come from and if they are calculated or ad hoc.)

In eps_writeMono(), here's the offending statement:

PHP Formatted Code
pval = (uchar) MONO (cmap->r[*pix], cmap->g[*pix], cmap->b[*pix++]);


I think this line is intended to do

PHP Formatted Code
pval = (uchar) MONO (cmap->r[*pix], cmap->g[*pix], cmap->b[*pix]); pix++;


Similarly, in eps_writeMonoRGB(), there are two statements like this

PHP Formatted Code
pval = (uchar) MONO (*pix++, *pix++, *pix++);


I think this line, which is far more problematic than the previous one, is intended as

PHP Formatted Code
pval = (uchar) MONO (*pix, *pix, *pix); pix+=3;


Currently, when compiled, these statements issue sequence-point warnings from gcc:
PHP Formatted Code
eps.c: In function ‘eps_writeMono’:
eps.c:813:25: warning: operation on ‘pix’ may be undefined [-Wsequence-point]
eps.c:813:25: warning: operation on ‘pix’ may be undefined [-Wsequence-point]
eps.c: In function ‘eps_writeMonoRGB’:
eps.c:860:20: warning: operation on ‘pix’ may be undefined [-Wsequence-point]
eps.c:860:20: warning: operation on ‘pix’ may be undefined [-Wsequence-point]
eps.c:867:20: warning: operation on ‘pix’ may be undefined [-Wsequence-point]
eps.c:867:20: warning: operation on ‘pix’ may be undefined [-Wsequence-point]
 


Since by definition the interpretation of these statements is compiler dependent, I cannot say for sure what the intended meaning. I think the intended behavior is obvious and that I've guessed correctly but could I get confirmation that:

a) the MONO macro's change is good
b) my suggested meaning for eps_writeMono()'s statement
c) my suggested meaning for the eps_writeMonoRGB()'s statement.


Cheers,
Jason

 
Profile Email
 Quote
Jason Quinn
 12/09/2015 01:33PM  
+++++
Active Member

Status: offline


Registered: 04/07/2006
Posts: 175
Whoops, I forgot to put a +1 and d+2 in part C about eps_writeMonoRGB(). It should say I think
PHP Formatted Code
pval = (uchar) MONO(*pix++, *pix++, *pix++);


has intended meaning

PHP Formatted Code
pval = (uchar) MONO(*pix, *pix+1, *pix+2); pix+=3


Cheers,
Jason

 
Profile Email
 Quote
Jason Quinn
 12/10/2015 10:05PM  
+++++
Active Member

Status: offline


Registered: 04/07/2006
Posts: 175
PHP Formatted Code
pval = (uchar) MONO(*pix, *(pix+1), *(pix+2)); pix+=3


That was supposed to be like this.

 
Profile Email
 Quote
Jason Quinn
 01/04/2016 08:47PM  
+++++
Active Member

Status: offline


Registered: 04/07/2006
Posts: 175
I think I found an bug comm.c that affects com_readData() and com_readSubraster(). These two functions do not correctly propagate an ERR condition to the higher CDL (imd and cdl) functions. They incorrectly (as far as I see) require com_debug to be two or greater for this to happen. I don't see why we'd want to suppress it based on the debug value. An error is an error so we should propagate it regardless of com_debug's value.

For example, in com_readSubraster() the erroneous segment of code reads

PHP Formatted Code
status = com_read(fdin, (char *)pix+nb, n, &n);
if (status && com_debug >= 2) {
        printf("com_readSubraster: error return from data read.\n");
        return ERR;
}


This code occurs within a loop, and it's possible for a call to com_read() failure in a middle iteration of the loop to go unreported. What seems to be wanted here (and the idiom used in many places in comm.c) is

PHP Formatted Code
if (com_read(fdin, (char *)pix+nb, n, &n)) {
        if (com_debug >= 2) {
                printf("com_readSubraster: error return from data read.\n");
        }
        return ERR;
}


This has the advantage of eliminating the need for the status variable, which results in a 1% increase in speed too based on my testing, and being a tad easier to read.

Jason



 
Profile Email
 Quote
   
Content generated in: 0.28 seconds
New Topic Post Reply

Normal Topic Normal Topic
Sticky Topic Sticky Topic
Locked Topic Locked Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Anonymous users can post 
Filtered HTML Allowed 
Censored Content 
dog allergies remedies cialis 20 mg chilblain remedies


Privacy Policy
Terms of Use

User Functions

Login