196
Casio PRIZM / [PRIZM] Paint
« on: May 03, 2013, 08:09:14 pm »
I was disappointed when zeldaking never finished his Paint program, so I Decided to make my own!
It's got circle drawing(no ellipse), rectangle drawing, line drawing, pen, floodfill, zooming in(plus button), zooming out(minus), has a grid for larger than 3x, and a color picker(hope I didn't leave anything out). It took me a while to figure out how to make it actually draw, but then I realized that I could draw a sprite to the screen and just edit the sprite data. The problems that I'm having is, opening files(.ppf files stands for Prizm Picture Files, I already have saving working okay), rotating image(I couldn't figure out how, I asked in my topic, but no one helped), resizing properly(resize it so the new image doesn't look corrupted and just adds white pixels in those places), displaying the hex of the color in the color picker(it is only displaying the #?), scaling gets corrupted after the displayed pic gets over 115(or something like that) pixels high or wide, and I think that's it unless I forgot.
Here is the opening code(if you can help, it segfaults the calc at the end of the progress bar):
I don't have any code for rotating(90 degree increments), but if you could help, it would be nice.
Here is my resizing code, so if you could help make the output less corrupted:
Here is the code for changing the RGB values to Hex(based off of my TI-BASIC program):
And, finally here is my nearest-neighbor scaling routine:
I really hope you can help with this. This is pretty much the farthest I've ever made on a Prizm C program from pretty much scratch.
Also, if you help, you get some credit(I'll make an About on the program that lists people who help).
Here's what I have right now:
-Rectangle
-Circle(not ellipses)
-Line
-Dropper
-Fill
-Color Picker with RGB editing(and hopefully hex code editing, but I need to get the hex displaying fixed first) and some preset colors(the same ones from Paint on Windows)
-Resizing(glitchy)
-Zooming/Scaling(glitchy, needs to be fixed; code is in first post)
-Saving(hopefully editing soon if I can get it to work; code is also in first post)
Planning for eventually:
-Eraser
-Select Tool with Copy, Paste, Crop, etc.
I'll take any suggestions if you have any.
It's got circle drawing(no ellipse), rectangle drawing, line drawing, pen, floodfill, zooming in(plus button), zooming out(minus), has a grid for larger than 3x, and a color picker(hope I didn't leave anything out). It took me a while to figure out how to make it actually draw, but then I realized that I could draw a sprite to the screen and just edit the sprite data. The problems that I'm having is, opening files(.ppf files stands for Prizm Picture Files, I already have saving working okay), rotating image(I couldn't figure out how, I asked in my topic, but no one helped), resizing properly(resize it so the new image doesn't look corrupted and just adds white pixels in those places), displaying the hex of the color in the color picker(it is only displaying the #?), scaling gets corrupted after the displayed pic gets over 115(or something like that) pixels high or wide, and I think that's it unless I forgot.
Here is the opening code(if you can help, it segfaults the calc at the end of the progress bar):
Code: [Select]
void openFile(char *PATH, color_t *data, int width, int height){
char databuf[5];
unsigned short buffer[sizeof(PATH)*2];
Bfile_StrToName_ncpy(buffer, (unsigned char*)PATH, strlen(PATH)+1);
int hFile = Bfile_OpenFile_OS(buffer, 0);
for(int i = 0; i < height; i++){
for(int j = 0; j < width; j++){
ProgressBar((i*width)+j, width*height);
Bfile_ReadFile_OS(hFile, databuf, 5, ((i*width+j)+2)*5);
data[(i*width+j)] = strtol(databuf, NULL, 10);
}
}
Bfile_CloseFile_OS(hFile);
return;
}
I don't have any code for rotating(90 degree increments), but if you could help, it would be nice.
Here is my resizing code, so if you could help make the output less corrupted:
Code: [Select]
void resizeImage(color_t *image, int w1, int h1, int w2, int h2){
int w, h;
color_t* holder = image;
color_t* temp = (color_t*)malloc(((w1*h1)*2)*sizeof(color_t));
temp = (color_t*)realloc(temp, ((w2*h2)*2)*sizeof(color_t));
if ( temp != NULL ){
image = temp;
} else {
free(temp);
return;
}
if(w1 < w2){
w = w1;
} else {
w = w2;
}
if(h1 < h2){
h = h1;
} else {
h = h2;
}
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
image[(i*w)+j] = holder[(i*w)+j];
}
}
}
Here is the code for changing the RGB values to Hex(based off of my TI-BASIC program):
Code: [Select]
char* RGBtoHex(int r, int g, int b, char buffer[7]){
char val[16] = "0123456789ABCDEF";
float a = (r/16);
float c = (g/16);
float d = (b/16);
int e = floor(a);
int f = floor(c);
int h = floor(d);
if(e > a)
e--;
if(f > d)
f--;
if(h > c)
h--;
a = a - e;
c = c - h;
d = d - f;
a = a * 16;
c = c * 16;
d = d * 16;
buffer[0] = '#';
buffer[1] = val[e];
buffer[2] = val[(int)a];
buffer[3] = val[f];
buffer[4] = val[(int)d];
buffer[5] = val[h];
buffer[6] = val[(int)c];
return buffer;
}
And, finally here is my nearest-neighbor scaling routine:
Code: [Select]
color_t* Scale(color_t *temp, const color_t* data,int w1,int h1,int w2,int h2) {
if((w2 <= 0) || (h2 <= 0)){
return 0;
} else {
color_t* milk = (color_t*)realloc(temp, (w2*h2*2)*sizeof(color_t));
temp = milk;
int x_ratio = ((w1<<16)/w2)+1;
int y_ratio = ((h1<<16)/h2)+1;
int x2, y2;
for(int i=0;i<h2;i++) {
for(int j=0;j<w2;j++) {
x2 = ((j*x_ratio)>>16);
y2 = ((i*y_ratio)>>16);
temp[(i*w2)+j] = data[(y2*w1)+x2];
}
}
}
return temp;
}
I really hope you can help with this. This is pretty much the farthest I've ever made on a Prizm C program from pretty much scratch.
Also, if you help, you get some credit(I'll make an About on the program that lists people who help).
Here's what I have right now:
-Rectangle
-Circle(not ellipses)
-Line
-Dropper
-Fill
-Color Picker with RGB editing(and hopefully hex code editing, but I need to get the hex displaying fixed first) and some preset colors(the same ones from Paint on Windows)
-Resizing(glitchy)
-Zooming/Scaling(glitchy, needs to be fixed; code is in first post)
-Saving(hopefully editing soon if I can get it to work; code is also in first post)
Planning for eventually:
-Eraser
-Select Tool with Copy, Paste, Crop, etc.
I'll take any suggestions if you have any.