Index: picedit.c ================================================================== --- picedit.c +++ picedit.c @@ -173,11 +173,11 @@ if(t==3) c=p[-pic->size]; *p++=c; } } -static inline void load_rotate(Picture*pic) { +static void load_rotate(Picture*pic) { int x,y; int m=pic->meth; int s=pic->size; Uint8*d=pic->data+s; static Uint8*buf; @@ -194,10 +194,77 @@ if(m&1) x=s-x-1; if(m&2) y=s-y-1; } memcpy(d,buf,s*s); } + +static void out_run(FILE*fp,int ch,int am,const Uint8*d,int le) { + int n=am%85?:85; + fputc(ch+n-1,fp); + if(le) fwrite(d,1,le7225?7225:am; + fputc(ch+n/85-1,fp); + if(le>0) fwrite(d,1,lesize; + int ms=ps*ps; + const Uint8*d=pic->data+ps; + int i=0; + int ca,homo,hetero; + while(i=homo && (ca>=hetero || homo>1)) { + out_run(fp,170,ca,0,0); + i+=ca; + } else if(homo>1) { + out_run(fp,0,homo-1,d+i,1); + i+=homo; + } else { + if(hetero>85) hetero=85; + out_run(fp,85,hetero,d+i,hetero); + i+=hetero; + } + } +} + +static void compress_picture(FILE*out,Picture*pic) { + int bm=15; + int bs=pic->size*pic->size; + FILE*fp=fmemopen(0,bs,"w"); + int i,j; + if(!fp) fatal("Error with fmemopen"); + for(i=0;i<8;i++) { + compress_picture_1(fp,pic); + if(!ferror(fp)) { + j=ftell(fp); + if(j>0 && jmeth="\1\3\1\7\1\3\1\7"[i]; + load_rotate(pic); + } + pic->meth=bm; + if(bm && bm!=15) load_rotate(pic); + fclose(fp); + if(bm==15) fwrite(pic->data+pic->size,pic->size,pic->size,out); else compress_picture_1(out,pic); +} static void block_rotate(Uint8*d,Uint8 s,Uint8 w,Uint8 h,Uint8 m) { Uint8*b=malloc(w*h); Uint8*p=b; int x,y; @@ -797,11 +864,14 @@ static void edit_picture(sqlite3_int64 id) { sqlite3_stmt*st; Picture*pict[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; char*name; const unsigned char*data; - int i; + Uint8*buf=0; + size_t size=0; + FILE*fp; + int i,n; if(i=sqlite3_prepare_v2(userdb,"SELECT SUBSTR(`NAME`,1,LENGTH(`NAME`)-4),`DATA` FROM `PICEDIT` WHERE `ID`=?1;",-1,&st,0)) { screen_message(sqlite3_errmsg(userdb)); return; } sqlite3_bind_int64(st,1,id); @@ -824,15 +894,32 @@ pict[0]->size=i; memset(pict[0]->data,0,(i+1)*i); } edit_picture_1(pict,name); free(name); - for(i=0;i<16;i++) { - - free(pict[i]); + fp=open_memstream((char**)&buf,&size); + if(!fp) fatal("Cannot open memory stream\n"); + for(i=n=0;i<16;i++) if(pict[i]) n++; + fputc(n,fp); + for(i=0;isize,fp); + for(i=0;i>1;i++) fputc(0,fp); + for(i=0;imeth<<4; + for(i=1;i>1)]|=pict[i]->meth<<(i&1?0:4); + for(i=0;i<16;i++) free(pict[i]); + if(i=sqlite3_prepare_v2(userdb,"UPDATE `PICEDIT` SET `DATA`=?2 WHERE ID=?1;",-1,&st,0)) { + screen_message(sqlite3_errmsg(userdb)); + free(buf); + return; } - + sqlite3_bind_int64(st,1,id); + sqlite3_bind_blob(st,2,buf,size,free); + i=sqlite3_step(st); + if(i!=SQLITE_DONE) screen_message(sqlite3_errmsg(userdb)); + sqlite3_finalize(st); } static int add_picture(int t) { sqlite3_stmt*st; const char*s=screen_prompt("Enter name of new picture:"); Index: picedit.doc ================================================================== --- picedit.doc +++ picedit.doc @@ -18,10 +18,14 @@ The main menu displays the list of the names of all pictures. This list is sorted by name. You can push escape to quit and save, or shift+escape quits without saving. +The F1 key adds a picture. + +The F2 key deletes a picture by name. + The F3 key allows entering a name of a picture to edit. === Drawing ===