Hi,
I have a new A720IS and just love what I can do with CHDK. I have been studying the viewport and writing some code to write it to a file and to load it from a file. I can also put my own images into the viewport. Since I am new I would like to post what I have learned about the viewport and the routines I have written. I hope to get some comments and corrections for those places where I have got it wrong.
Largely I got my info about the viewport from studying the histogram code.
On the 720IS the physical screen is 5.0cm x 3.8cm, a ratio of 1.32. The image aspect ratio is 1.333 so Canon seems to have squashed the physical screen a little. The physical screen of course consists of red, green and blue dots in a pattern.
Internally the viewport consists of 360x240x3bytes. This is an aspect ratio of 1.5. The format is not RGB, but consists of groups of 6 bytes with the format U,Y1,V,Y2,Y3,Y4. This gives info for 4 pixels with the U,V color information shared for Y1,Y2,Y3,Y4. The display hardware uses this info to create the pattern of dots that you see.
I can save the viewport data and load it from a file. I do this by changing the histogram code:
switch (histogram_stage) {
case 0:
img=((mode_get()&MODE_MASK) == MODE_PLAY)?vid_get_viewport_fb_d():((kbd_is_key_pressed(KEY_SHOOT_HALF))?vid_get_viewport_fb():vid_get_viewport_live_fb());
if (img==NULL){
img = vid_get_viewport_fb();
}
viewport_size = vid_get_viewport_height() * screen_width;
for (c=0; c<5; ++c) {
for (i=0; i<HISTO_WIDTH; ++i) {
histogram_proc[c]=0;
}
histo_max[c] = histo_max_center[c] = 0;
}
histogram_stage=1;
// JH code
if((mode_get()&MODE_MASK) == MODE_PLAY) {
if (kbd_is_key_pressed(KEY_SHOOT_HALF)) {
save_viewport(img, viewport_size);
// alternatively I comment out the above line and uncomment the following line
// load_viewport(img, viewport_size, "A/VPDATA/ViewPortData0"); }
histogram_stage=0;
}
break;
...
I use the blended histogram so I make this change to gui_osd_draw_blended_histo
static void gui_osd_draw_blended_histo(coord x, coord y) {
register unsigned int i, v, red, grn, blu, sel;
int m = ((mode_get()&MODE_MASK) == MODE_REC);
if(!m) return;//JH change
Here is my code for the read and load routines:
/* save the viewport data to a file */
static int nsaved = 0;
void save_viewport(char *img, int viewport_size) {
int fd, i;
char fn[64];
if(nsaved > 20) return;
mkdir("A/VPDATA");
sprintf(fn, "A/VPDATA/ViewPortData%d",nsaved++);
fd = open(fn, O_WRONLY|O_CREAT, 0777);
if (fd>=0) {
write(fd, img, viewport_size *3);
close(fd);
}
return;
}
/* load the viewport from a file */
void load_viewport(char *img, int viewport_size, char *fn){
int fd;
fd = open(fn, O_RDONLY, 0777);
if (fd>=0) {
int rcnt = read(fd, img, viewport_size *3);
close(fd);
}
return;
}
This post is getting a little long. I will post a second time to explain how I get the viewport data into an imaging program (ImageJ) and how I can load my own images into the viewport.
Jon