Calculator Community > Casio PRIZM

[PRIZM] Paint

(1/4) > >>

Spenceboy98:
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):

--- Code: ---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;
}
--- End code ---

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: ---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];
        }
    }
}
--- End code ---

Here is the code for changing the RGB values to Hex(based off of my TI-BASIC program):

--- Code: ---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;
}
--- End code ---

And, finally here is my nearest-neighbor scaling routine:

--- Code: ---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;
}
--- End code ---

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.

DJ Omnimaga:
Looks really good, but I hope you make it better than M$ Paint (basically, don't implement its bugs) :P

What image format will this support in the end? Can we create sprites/tiles, sprite data, images we can re-use elsewhere, etc?

Spenceboy98:

--- Quote from: DJ Omnimaga on May 03, 2013, 10:06:40 pm ---Looks really good, but I hope you make it better than M$ Paint (basically, don't implement its bugs) :P

What image format will this support in the end? Can we create sprites/tiles, sprite data, images we can re-use elsewhere, etc?

--- End quote ---

It saves it in a .ppf file(Prizm Picture File) with numbers from 0-65535 colors for now.

Spenceboy98:
More Screenies:
Me changing width(also changed height, but no screenie for that):

After drawing zoomed in:

Zoomed out:

Saving(I tried to save, but unfortunately the calc crashed. I'll look into it):





For saving, you don't have to add the ".ppf"; it does it for you.

Here's what's in a .ppf file(width and height followed by color codes): http://pastebin.com/Fc0qt7aT

Resizing still isn't working right(using my scale routine and resizing array with realloc). I fixed a small problem with my flood filling routine(it used to reset every time I tried to fill without a boundary/border). Saving is incredibly slow and it gets slower as the image gets larger(the larger the image, the slower it takes).

As you can see in the last sreenshot, something weird is happening(my guess is that it is from my fill routine because it starts soon after I start using the fill routine).

DJ Omnimaga:
Very nice. I especially like zoomed in drawing, since it's hard to draw small stuff on such small screen.

Navigation

[0] Message Index

[#] Next page

Go to full version