Channel swap on-screen - Feature Requests - CHDK Forum  

Channel swap on-screen

  • 9 Replies
  • 3325 Views
*

Offline n6mod

  • *
  • 15
Channel swap on-screen
« on: 01 / December / 2009, 11:35:25 »
Advertisements
Some long-winded background to explain why I want this:  :D

I do a fair bit of infrared photography, and while most of my IR gear cameras are early G-series cameras (DIGIC I), I do have an S3IS I've converted.

Part of the magic of digital IR with compact cameras (DSLRs have a different set of tradeoffs) is that you can see IR on the display and compose your image looking at the IR. This is wonderful, in the film days you never really knew what you were going to get. Canons have pretty broad ranges for white balance, so you can use a custom WB to correct for the wild red/purple casts you often get with IR, so now you have a roughly black and white image in the viewfinder.

I say "roughly" black and white, because different IR filters interact with the red, green and blue filters in the bayer array differently. It's pretty common to shoot "false color", using a more permissive IR filter and then playing with the colors you get in post processing. Probably the most common false color operation in post is the "channel swap", swapping the red and blue channels. This gets you deep blue skies and delicate pink foliage.

Now, I agree with the general sentiment of folks around here, that these processing steps should be done in post. It might be fun to play around with writing JPEGs with the channels swapped, but I'm really going to be shooting RAW anyway.

(End of background...)

But... what about the viewfinder? Would it be possible to swap the red and blue channels in the image displayed on the LCD/viewfinder? It seems like if CHDK can do zebras, it should be able to do other image manipulations on-screen. The ideal case, (talking pie in the sky here) would be to have something like Photoshop's Channel Mixer available for the screen, and to be able to save a few presets. But even a quick hack to swap red and blue would be fantastic. I don't want the image saved this way, I just want to hack the display to help with composition.

I'm not much of a developer, (I'm a sysadmin/network engineer by trade), but if someone could point me at the right part of the code, I'm happy to start hacking around, and possibly get some help from the developers at work. I just don't know where to start.

Thanks!
-Zandr

(Sorry if this ends up as a double post, something got goofy with a session timeout)

Re: Channel swap on-screen
« Reply #1 on: 01 / December / 2009, 12:06:40 »
Well .......
There are two types of image buffer.
The live-image buffers use YUV 4:1:1 coding requiring 1.5 bytes per pixel.
The buffers are 720 pixels wide and the height is either 230 or 240 pixels.
Maybe someone knows of other heights for other modes.

The bytes are arranged |U|Y0|V|Y1|Y2|Y3|

The Canon firmware (or hardware ?) renders the 720-wide live buffer onto a 320 or 360 wide screen.

Code that reads the live-image buffer bytes is edge-outline, histogram, zebra, motion-detection and SDM's 'invert playback image'.

Edge outline actually uses Y1 and Y3 to store computed values.

The other image-buffer type is the bitmap overlay buffer.
This is where all the drawn information appears such as edge-outline, histogram, zebra, grids, etc.
It is just one byte per pixel and is typically 360x240 or 720x240 (but may be just part of a larger 960x270 buffer).

Quite simply, even if you could recompute the YUV byte-pattern for the entire screen fast enough and write it to the buffer, it would be immediately overwritten.

This is not a concern as you could not recompute it fast enough anyway.   :)

unless anyone disagrees ...


David

*

Offline n6mod

  • *
  • 15
Re: Channel swap on-screen
« Reply #2 on: 01 / December / 2009, 14:30:15 »
David-

So it sounds like I'm not going to get this live, but I could very likely add something that works like the Zebra and writes the modified image to the overlay buffer.

Having a button or two to press to see the modified image would be fine for most uses.

This is a great start, I'll start digging into the code.

Thanks!
-Zandr

Re: Channel swap on-screen
« Reply #3 on: 01 / December / 2009, 14:45:03 »
With some cameras the sizes of the various buffers can be very confusing.

The S3IS loks OK.

See \platform\s3is\sub\100a\lib.c for buffer sizes.


Definition of screen_width and screen_height in \core\gui_draw.c.

The live-image buffer is 720*1.5 BYTES  wide.
Some people write that as 360*3 which is slightly confusing.

Good luck !


David



*

Offline reyalp

  • ******
  • 12595
Re: Channel swap on-screen
« Reply #4 on: 01 / December / 2009, 15:18:24 »
David-

So it sounds like I'm not going to get this live, but I could very likely add something that works like the Zebra and writes the modified image to the overlay buffer.
Keep in mind the overlay buffer is 8 bit paletted (think original VGA). Oh, and we don't yet know how to control the palette, although that should be fairly straightforward to find.

As an alternative, maybe you can hack whatever mechanism canon uses for the mycolors stuff. I haven't seen any serious investigation as to how this works, but depending how flexible it is, you may be able to tell the fast DSP part of Digic exactly what you want to do. In fact, isn't color swap is one of the factory options ?
Don't forget what the H stands for.

*

Offline n6mod

  • *
  • 15
Re: Channel swap on-screen
« Reply #5 on: 01 / December / 2009, 15:33:44 »
As an alternative, maybe you can hack whatever mechanism canon uses for the mycolors stuff. I haven't seen any serious investigation as to how this works, but depending how flexible it is, you may be able to tell the fast DSP part of Digic exactly what you want to do. In fact, isn't color swap is one of the factory options ?

Oh, now *that* is really interesting. There's no color swap on the S3IS, and investigating further into the firmware is beyond me, but I'd be very interested helping/testing if someone else dug into that.

*

Offline ewavr

  • ****
  • 1057
  • A710IS
Re: Channel swap on-screen
« Reply #6 on: 01 / December / 2009, 15:54:48 »
Keep in mind the overlay buffer is 8 bit paletted (think original VGA). Oh, and we don't yet know how to control the palette, although that should be fairly straightforward to find.
Hmm, palette consist of only 16 basic colors (see PrintCurrPalette() for VxWorks).
If I remember correctly, example of setting 16 palette registers is SetClearPalette() function - last in DispDevUtil_TurnOnDisplay:
LDR     R0, =0xC0F14080 ; first register, last register is 0xC0F140BC
MOV     R1, #0xFF0000   ; AAYYUUVV
BL      EngDrvOut      
....
Quote
I haven't seen any serious investigation as to how this works, but depending how flexible it is, you may be able to tell the fast DSP part of Digic exactly what you want to do. In fact, isn't color swap is one of the factory options ?
vitalyb in russian forum discovered this function long time ago (for making fast zebra). He said that the resolution of color setting is low (something like 3 bit for each color component).


*

Offline n6mod

  • *
  • 15
Re: Channel swap on-screen
« Reply #7 on: 01 / December / 2009, 16:01:03 »
OK, so the S3IS does do color swap. It's in the SCN modes, not in My Colors, which is what threw me. It looks like the PropertyCases for to and from are known, so I'll play with swapping red/blue there and see how it works.

I confess that I have an aspirational goal of doing more complex stuff, specifically: R'=B, G'=R-B, B'=G-B

Here's why: http://photo.milewski.org/v/IR/EIR0911 (Digital Ektachrome IR!)


Re: Channel swap on-screen
« Reply #8 on: 19 / December / 2009, 12:48:41 »
Hi,
I'd like to do the following in real time in record mode:
YUVout = M * YUVin where M is a 3x3 matrix and YUVin and YUVout are 3x1 vectors.  I wonder if this could be done by somehow messing with a color balance matrix stored somewhere in the camera?

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Channel swap on-screen
« Reply #9 on: 20 / December / 2009, 03:13:46 »
I'd like to do the following in real time in record mode:
YUVout = M * YUVin where M is a 3x3 matrix and YUVin and YUVout are 3x1 vectors.  I wonder if this could be done by somehow messing with a color balance matrix stored somewhere in the camera?

See http://chdk.setepontos.com/index.php/topic,2941.0.html, it somewhat resembles this topic.

 

Related Topics