0 Members and 1 Guest are viewing this topic.
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;}
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]; } }}
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;}
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;}
Looks really good, but I hope you make it better than M$ Paint (basically, don't implement its bugs) What image format will this support in the end? Can we create sprites/tiles, sprite data, images we can re-use elsewhere, etc?
void saveBMP(char *filename, color_t *data, int width, int height){ BMPHEAD bh; memset ((char *)&bh,0,sizeof(BMPHEAD)); /* sets everything to 0 */ memcpy (bh.id,"BM",2); bh.reserved[0] = 0; bh.reserved[1] = 0; bh.headersize = 54L; bh.infoSize = 0x28L; bh.width = width; bh.depth = height; bh.biPlanes = 1; bh.bits = 24; bh.biCompression = 0L; int bytesPerLine; bytesPerLine = bh.width * 3; /* (for 24 bit images) */ /* round up to a dword boundary */ if (bytesPerLine & 0x0003) { bytesPerLine |= 0x0003; ++bytesPerLine; } bh.filesize=bh.headersize+(long)bytesPerLine*bh.depth; int size = bh.headersize+(long)bytesPerLine*bh.depth; char * PATH; PATH = alloca(strlen("\\\\fls0\\")+strlen1(filename)+strlen(".bmp")+1); strcpy(PATH, "\\\\fls0\\"); strcat(PATH, filename); strcat(PATH, ".bmp"); unsigned short * pFile = alloca(2*(strlen(PATH)+1)); Bfile_StrToName_ncpy(pFile, (unsigned char*)PATH, strlen(PATH)+1); Bfile_CreateEntry_OS(pFile, CREATEMODE_FILE, &size); int hFile = Bfile_OpenFile_OS(pFile, 2); Bfile_WriteFile_OS(hFile, &bh, sizeof(bh)); char *linebuf; linebuf = (char *) malloc(bytesPerLine*sizeof(char)); if (linebuf == NULL){ Bfile_CloseFile_OS(hFile); return; } int line; for (line = height; line >= 0; line --){ for(int i = 0; i < width; i++){ linebuf[i] = data[line*width+i]; } Bfile_WriteFile_OS(hFile, linebuf, sizeof(linebuf)); } Bfile_CloseFile_OS(hFile); free(linebuf);}
This isn't the right sub-forum to ask for programming help. You should use the Lua or C programming help section for that, else only people who check Casio stuff will see your request.
How do you support 24 bit pics editing if we can only see 65536 colors at once by the way? Also I like how moving the image around seems pretty fast.