April 5, 2008
WikiPixelbypixel Class3 Notes
#wiki
- We are using pixels to draw on the screen.
- SetCPixel(x,y,&ourColor); // drawing through this function, this is coming from quickdraw.
- The way we imagine a pixdel array is, we have matrix, we can address each of them x, y and for each one of them we expect to have an rgb value. The problem occurs when we want to address the pixels. Because the memory in the computer is one dimension but we intend to think matrix in 2d. We need to convert from the former to the latter. Or both ways. So we have a formula to convert from 2d to 1d. if we put in an example: Wdith:3, then y*width+x. and we need to add base address to this in order to find the exact place in the memory. This equation changes when we use color as opposed to one byte.
- So in each pixel if we have RGB we need to multiply it by three. as we have 8bitx3!
- Handler is more deep than a pointer, it is like pointer to pointer. On macs you cannott do it anymore, handle. you could go to two levels up by that in the past.
- the width of the pixel array is not the width of the number of the pixels. (RGBA). Every pixel in memory ARGB, ARGB, ARGB.. every pixel in memory occupies 4 bytes.
- we need to know width in bytes, we need to know x position, y posioition, R,G,B, and base address.
- how do we get width in bytes:
rowBytes = ((**(ourPixmap)).rowBytes) & 0x7fff;
- memcopy() copy addresses from one place to another.
- Now our application knows how to go from one dimension to another, so we have our buffer, so our mouse is somewhere in the buffer and what we are trying to calculate is a distance from our mouse position to certain distance. So we have the worst case scenario which we put our mouse in one corner and the pixel we are reading from the other corner. In order to calculate this, we already put those distances in an array like [width2][height2] and then populate this in distance. This is more memory intensive. The idea is, for using static graphics like this, we don’t really care about memory size but it is more important to cycles, make them quicker and less. But in pic sense it could be different, the important thing becomes memory instead of cycling.
- When we open our application we created a window and then we also created a buffer and what we did inside our buffer we invented different values for pixels and then we copy this ocntent into the window. Today what we want to do is, to manipulate existing images. Open a file image file from our hdd, and take this image and put this image in a second buffer which will hold our image and then what we want to do is read thsoe values of image and copy those values to another buffer and send this buffer to the window.
- We are using quicktime library to import images to our application. (You should figure out if that works the same for SDL)The importFile function.
- Then take each values from ARGB pixels. What we are going to do today is to manipulate the value of the single pixel and change it according to initial that pixel. Examples: invert, adjusting RGB values and change them. Not blur! We are doing point manipulation this week! Thresholding, contrast, brightness. Initial state of pixels plus user interaction.
- Saturation is changing the RGB system to HSB and then changing the hue value and then changing this back to RGB value. What is saturation increase? Let’s say we have a pixel value of: 100,0,0. What would be the grayscale twin of this pixel? 100+0+0/3 = 33. This is the saturation in grayscale. Each value try to shy away from the average value. If it is over the average it gets to go higher. Reverse, it tries to go more lower. If we take the saturation down, we would get grayscale. Shy away from the average brightness.
- Contrast: Shy away from average brightness value of the image.
- Adding Noise: It is not considered as a point manipulation.
Continue Reading
Back to Archive