get_histo_range strangeness - Script Writing - CHDK Forum

get_histo_range strangeness

  • 55 Replies
  • 4575 Views
get_histo_range strangeness
« on: 16 / May / 2022, 16:01:35 »
Advertisements
@reyalp

Sorry I need your insight again ;-)

I'm tweaking some code and seem to be getting a strange result when using get_histo_range.

I thought get_histo_range went from 1 to 1024 and returned the percentage in the requested range.

If I use get_histo_range(1023,1024) all seems ok, but if I use get_histo_range(1024, 1024), ie looking at the highest bucket doesn't seem to work.

Am I missing something?

*

Offline Caefix

  • *****
  • 945
  • Sorry, busy deleting test shots...
Re: get_histo_range strangeness
« Reply #1 on: 16 / May / 2022, 16:07:41 »
Code: [Select]
/*
histogram,total=get_live_histo()
returns a histogram of Y values from the viewport buffer (downsampled by HISTO_STEP_SIZE)
histogram[Y value] = count, so it is zero based unlike a normal lua array
total is the total number of pixels, may vary depending on viewport size
*/
static int luaCB_get_live_histo( lua_State* L )
{
  unsigned short *h = malloc(256*sizeof(short));
  if(!h) {
      return luaL_error(L,"malloc fail");
  }
  int total=live_histogram_read_y(h);
  lua_createtable(L, 0, 256);
  int i;
  for(i=0;i<256;i++) {
    lua_pushnumber(L,h[i]);
    lua_rawseti(L,-2,i);
  }
  free(h);
  lua_pushnumber(L,total);
  return 2;
}
1024 chars ?  ???
All lifetime is a loan from eternity.

Re: get_histo_range strangeness
« Reply #2 on: 16 / May / 2022, 16:10:57 »
@Caefix

I'm not using the get live histo ;-)

Re: get_histo_range strangeness
« Reply #3 on: 16 / May / 2022, 16:30:50 »
Looking at things, it seems I can't get the percentage in a single cell, ie only inbetween.

Thus the best I can do is get_histo_range(1023,1024).

In other words, unlike get_live_histo, I can't get the count or percentage in the highlight/top histo bucket, ie a single histo cell.


*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: get_histo_range strangeness
« Reply #4 on: 16 / May / 2022, 17:03:11 »
The parameters for get_histo_range should be from 0 to 1023.
It is accessing a C array so the index starts at 0, not 1.

CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

Re: get_histo_range strangeness
« Reply #5 on: 16 / May / 2022, 17:12:23 »
@philmoz

I had it in my head that that array was not zero based.

All ok now.

Cheers

Garry

*

Offline reyalp

  • ******
  • 14080
Re: get_histo_range strangeness
« Reply #6 on: 16 / May / 2022, 17:46:47 »
I had it in my head that that array was not zero based.
Indeed Lua arrays are one based, but get_histo_range is not an array.

If you want more flexibility, you can use rawop histo https://chdk.fandom.com/wiki/Lua/Raw_Hook_Operations#Histogram_functions
Don't forget what the H stands for.

Re: get_histo_range strangeness
« Reply #7 on: 16 / May / 2022, 17:59:44 »
@reyalp

Thanks I’ll have look at the rawop histo option.

Cheers

Garry


Re: get_histo_range strangeness
« Reply #8 on: 17 / May / 2022, 11:53:31 »
@reyalp

Looking at the rawop ‘stuff’, I will need to study this a bit more;-)

What I would like to ‘request’ is that the get_histo_range function, which is 10 bit, returns the actual count in the requested range and the total count. That is, rather than an integer percentage.

Is there any chance you would consider doing this?

Cheers

Garry

*

Offline Caefix

  • *****
  • 945
  • Sorry, busy deleting test shots...
Re: get_histo_range strangeness
« Reply #9 on: 17 / May / 2022, 13:31:51 »
Something like ... :-[
get_histo_range(min,max)*100 / get_histo_range(0,1023)  ?
All lifetime is a loan from eternity.

 

Related Topics