How to understand CHDK source code, raw.c - General Discussion and Assistance - CHDK Forum supplierdeeply

How to understand CHDK source code, raw.c

  • 14 Replies
  • 13352 Views
How to understand CHDK source code, raw.c
« on: 12 / October / 2012, 08:50:42 »
Advertisements
Hallo ,

I just want add some function to make a personal modification to the raw image pixel. But as a non professional programmer , I found it is hard to make a clue of the sourse code, for example the raw.c .

Q1, is there any Docs to give a guide of the source code? so that I can have a clue how chdk codes works in general.

Q2, regarding the raw.c , I am confused with the functions make_pixel_list , get_raw_pixel ,get_raw_image_addr, hook_raw_save_complete,  core_rawdata_available
and also the Vars develop_raw,hook_raw_image_addr, raw_image_addr,  raw_save_stage, raw_data_available, RAWDATA_AVAILABLE.
What does the function started() and finshed() mean? where can I find them?

Q3, If I want to manually change the value of a certain pixel, say at position 2000*1500 (center of the image, I want to make a  pixel simply  to be red ), how can I do this ?

Q4, regarding the camera.h  ,  int raw_rows, raw_rowpix, raw_rowlen, raw_size , what does these values stand for ?

Great thanks for your time to help ! :)

Ling
« Last Edit: 12 / October / 2012, 09:11:03 by zell »

*

Offline zeno

  • *****
  • 891
Re: How to understand CHDK source code, raw.c
« Reply #1 on: 12 / October / 2012, 09:00:51 »
Understanding the CHDK source is not a task that's easy, even for proefessional programmers. You need source-code search tools to find things - for example started() and finished() are actually not functions but 'macros' defined in platform.h:

  #define started() debug_led(1)
  #define finished() debug_led(0)
A570, S100, Ixus 127
Author of ASSIST, STICK, WASP, ACID, SDMInst, LICKS, WICKS, MacBoot, UBDB, CFGEdit

Re: How to understand CHDK source code, raw.c
« Reply #2 on: 12 / October / 2012, 09:07:26 »
Understanding the CHDK source is not a task that's easy, even for proefessional programmers. You need source-code search tools to find things - for example started() and finished() are actually not functions but 'macros' defined in platform.h:

  #define started() debug_led(1)
  #define finished() debug_led(0)

Thanks !  Sorry again , could you suggest such a tool ?  I am hardware guy not a  proefessional programmer.
I am now using notepad++ to read the c code, but do not know how to cross search a key word in different files.


*

Offline zeno

  • *****
  • 891
Re: How to understand CHDK source code, raw.c
« Reply #3 on: 12 / October / 2012, 09:24:31 »
Hi Zell. I'm not the best person to ask because (a) I am a Mac user now and don't use Windows much (except to test my cross-platform java apps and (b) all the Windows tools I used to use have long since been replaced. Others may suggest better alternatives, but Ack (freeware - see http://betterthangrep.com/) looks useful - though you'll need to know a bit about regular expressions to get full use out of it. 
A570, S100, Ixus 127
Author of ASSIST, STICK, WASP, ACID, SDMInst, LICKS, WICKS, MacBoot, UBDB, CFGEdit


Re: How to understand CHDK source code, raw.c
« Reply #4 on: 12 / October / 2012, 09:33:43 »
Thanks anyway, zeno !

Re: How to understand CHDK source code, raw.c
« Reply #5 on: 12 / October / 2012, 20:30:31 »
If I want to manually change the value of a certain pixel, say at position 2000*1500 (center of the image, I want to make a  pixel simply  to be red ), how can I do this ?


Quite honestly, from the other questions you asked, you will not have the knowledge to do that at present.
You say 'manually' change but how do you move a 'cursor' to the desired position, how do you mark the spot, how is this feature enabled, etc.,etc.

If you ONLY want to put a red dot at the very centre of the image (or maybe a cross-hair) the easiest way is to use a grid :-

http://chdk.wikia.com/wiki/Grids#--_Cross-hair
http://chdk.wikia.com/wiki/Grids



David

*

Offline reyalp

  • ******
  • 14120
Re: How to understand CHDK source code, raw.c
« Reply #6 on: 12 / October / 2012, 22:43:48 »
Hi Zell. I'm not the best person to ask because (a) I am a Mac user now and don't use Windows much (except to test my cross-platform java apps and (b) all the Windows tools I used to use have long since been replaced. Others may suggest better alternatives, but Ack (freeware - see http://betterthangrep.com/) looks useful - though you'll need to know a bit about regular expressions to get full use out of it. 
I am fond of grepwin http://tools.tortoisesvn.net/grepWin.html

That's pretty much the answer to the original quesiton too. Start reading, use grep to track down where things are, rinse, repeat.

Q1, is there any Docs to give a guide of the source code? so that I can have a clue how chdk codes works in general.
There is no documentation beyond the developer pages on the wiki (start here http://chdk.wikia.com/wiki/For_Developers ) and comments in the code. Reliability of both is... variable.

Quote
Q3, If I want to manually change the value of a certain pixel, say at position 2000*1500 (center of the image, I want to make a  pixel simply  to be red ), how can I do this ?
The format of the raw frame buffer is discussed here: http://chdk.wikia.com/wiki/Frame_buffers#Raw
Quote
Q4, regarding the camera.h  ,  int raw_rows, raw_rowpix, raw_rowlen, raw_size , what does these values stand for ?
I guess you are asking about the _cam_sensor struct. This is used to provide information from the defines to modules. The struct is initialized in core/main.c. The values of the defines used to initialize it are pretty well documented in camera.h
Don't forget what the H stands for.

Re: How to understand CHDK source code, raw.c
« Reply #7 on: 15 / October / 2012, 07:17:51 »
Great Thanks, it is very helpful to me!
It seems that if I am able to write to the frame buffer, then I am able to change the pixels. Hard thing is to find the right address of the desired pixel , if I understand them right.
By the way, when I was reading the frame buffer page ,  the data structures really looks odd to me, make things harder for me to understand it. I guess that is why in RAW.C,  switch{case0,..,case7} code was used.

I will experiment later to see...

Hi Zell. I'm not the best person to ask because (a) I am a Mac user now and don't use Windows much (except to test my cross-platform java apps and (b) all the Windows tools I used to use have long since been replaced. Others may suggest better alternatives, but Ack (freeware - see http://betterthangrep.com/) looks useful - though you'll need to know a bit about regular expressions to get full use out of it. 
I am fond of grepwin http://tools.tortoisesvn.net/grepWin.html

That's pretty much the answer to the original quesiton too. Start reading, use grep to track down where things are, rinse, repeat.

Q1, is there any Docs to give a guide of the source code? so that I can have a clue how chdk codes works in general.
There is no documentation beyond the developer pages on the wiki (start here http://chdk.wikia.com/wiki/For_Developers ) and comments in the code. Reliability of both is... variable.

Quote
Q3, If I want to manually change the value of a certain pixel, say at position 2000*1500 (center of the image, I want to make a  pixel simply  to be red ), how can I do this ?
The format of the raw frame buffer is discussed here: http://chdk.wikia.com/wiki/Frame_buffers#Raw
Quote
Q4, regarding the camera.h  ,  int raw_rows, raw_rowpix, raw_rowlen, raw_size , what does these values stand for ?
I guess you are asking about the _cam_sensor struct. This is used to provide information from the defines to modules. The struct is initialized in core/main.c. The values of the defines used to initialize it are pretty well documented in camera.h


Re: How to understand CHDK source code, raw.c
« Reply #8 on: 15 / October / 2012, 08:23:55 »
It seems that if I am able to write to the frame buffer, then I am able to change the pixels. Hard thing is to find the right address of the desired pixel , if I understand them right.
I just took a quick look at raw.c.   The function set_raw_pixel() looks like it should do what you want ?

Quote
By the way, when I was reading the frame buffer page ,  the data structures really looks odd to me, make things harder for me to understand it.
You did say you are not a professional programmer .....
Ported :   A1200    SD940   G10    Powershot N    G16

Re: How to understand CHDK source code, raw.c
« Reply #9 on: 15 / October / 2012, 11:13:37 »
Yes, and I also figured out how the get_raw_pixel obtain the exact pixel I want, and how bad pixels are averaged from 4 neighboring pixels. Thanks to the help of forum members. I hope I can do something funny and useful later.

Another Question is , if anyone want to do something to the raw image pixel,  should they put their own code between read and close(fd)
code from RAW.C:

if (develop_raw) {
        started();
        fd = open(fn, O_RDONLY, 0777);
        if (fd>=0) {
            read(fd, rawadr, hook_raw_size());
            close(fd);

        }
#ifdef OPT_CURVES
        if (conf.curve_enable) {
           if (module_curves_load())
            libcurves->curve_apply();
      }
#endif
        finished();
        develop_raw=0;
        return 0;
    }


Please notice,  later in the code , there is a comment: // got here second time in a row. Skip second RAW saving.
 Actually I don't understand this.
After this comment , there is again a   started() .......  finished(); structure, I guess that is related to write the file to the SD card, right?

Thanks again in advance!


It seems that if I am able to write to the frame buffer, then I am able to change the pixels. Hard thing is to find the right address of the desired pixel , if I understand them right.
I just took a quick look at raw.c.   The function set_raw_pixel() looks like it should do what you want ?

Quote
By the way, when I was reading the frame buffer page ,  the data structures really looks odd to me, make things harder for me to understand it.
You did say you are not a professional programmer .....

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal