Changeset 708
- Timestamp:
- Aug 15, 2013, 9:04:33 PM (9 years ago)
- Location:
- abuse/branches/lol/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/branches/lol/src/clisp.cpp
r706 r708 1921 1921 for (int i = 0; i < 256; i++) 1922 1922 p->SetColor(i, (u8vec3)clamp((ivec3)p->GetColor(i) + delta, 0, 255)); 1923 p-> load();1923 p->Load(); 1924 1924 delete p; 1925 1925 } break; -
abuse/branches/lol/src/cop.cpp
r695 r708 794 794 for (int i = 0; i < 256; i++) 795 795 p->SetColor(i, (u8vec3)clamp((ivec3)p->GetColor(i) + delta, 0, 255)); 796 p-> load();796 p->Load(); 797 797 delete p; 798 798 } -
abuse/branches/lol/src/dev.cpp
r707 r708 3511 3511 { 3512 3512 wm->SetMouseShape(cache.img(c_normal)->copy(), ivec2(1, 1)); 3513 g_palette-> load();3513 g_palette->Load(); 3514 3514 } 3515 3515 else -
abuse/branches/lol/src/game.cpp
r707 r708 406 406 state = new_state; 407 407 408 g_palette-> load(); // restore old palette408 g_palette->Load(); // restore old palette 409 409 410 410 if(playing_state(state) && !(dev & EDIT_MODE)) … … 1064 1064 g_palette->SetColor(j, (u8vec3)((ivec3)tmp_pal->GetColor(j) * v / 256)); 1065 1065 1066 g_palette-> load();1066 g_palette->Load(); 1067 1067 wm->flush_screen(); 1068 1068 frame.Wait(duration); … … 1073 1073 main_screen->clear(); 1074 1074 wm->flush_screen(); 1075 tmp_pal-> load();1075 tmp_pal->Load(); 1076 1076 } 1077 1077 delete g_palette; … … 1146 1146 1147 1147 main_screen->clear(); 1148 g_palette-> load();1148 g_palette->Load(); 1149 1149 1150 1150 int dx = (xres + 1) / 2 - gray->Size().x / 2, dy = (yres + 1) / 2 - gray->Size().y / 2; … … 1277 1277 1278 1278 CreateScreen(argc, argv); 1279 g_palette-> load();1279 g_palette->Load(); 1280 1280 1281 1281 recalc_local_view_space(); // now that we know what size the screen is... … … 2348 2348 } 2349 2349 2350 if ( lastl)2350 if (Palette::LastLoaded()) 2351 2351 { 2352 2352 m_palette->Bind(); 2353 m_palette->SetData( lastl->Data());2353 m_palette->SetData(Palette::LastLoaded()->Data()); 2354 2354 } 2355 2355 … … 2529 2529 System::Init(argc, argv); 2530 2530 2531 Application app("Abuse", ivec2( 640, 480), 60.0f);2531 Application app("Abuse", ivec2(800, 600), 60.0f); 2532 2532 new DebugFps(5, 5); 2533 2533 new AbuseGame(argc, argv); -
abuse/branches/lol/src/gamma.cpp
r694 r708 100 100 gray_pal->SetColor(i, u8vec3(i * 4)); 101 101 102 gray_pal-> load();102 gray_pal->Load(); 103 103 104 104 int wm_bc = wm->bright_color(), wm_mc = wm->medium_color(), wm_dc = wm->dark_color(); … … 191 191 } 192 192 193 pal-> load();193 pal->Load(); 194 194 } -
abuse/branches/lol/src/imlib/image.cpp
r698 r708 904 904 if (x2<x1 || y2<y1) return NULL; 905 905 ret=new image(ivec2((x2-x1+8)/8, (y2-y1+1))); 906 if (! last_loaded())906 if (!Palette::LastLoaded()) 907 907 ret->clear(); 908 908 else … … 917 917 for (bo=7, rx=0, x=x1, ditx=x1%4; x<=x2; x++) 918 918 { 919 if ( last_loaded()->GetColor(sl2[x]).r > dither_matrix[ditx+dity])919 if (Palette::LastLoaded()->GetColor(sl2[x]).r > dither_matrix[ditx+dity]) 920 920 sl1[rx]|=1<<bo; 921 921 if (bo!=0) -
abuse/branches/lol/src/imlib/palette.cpp
r694 r708 154 154 if (m_colors.Count() == 256) 155 155 for (int i = 0; i < m_colors.Count(); i++) 156 m_colors[i] = u8vec3(RED3(i), GREEN3(i), BLUE2(i)); 156 m_colors[i] = u8vec3(((i >> 5) & 7) * 255 / 7, 157 ((i >> 2) & 7) * 255 / 7, 158 (i & 3) * 255 / 7); 157 159 else if (m_colors.Count() == 16) 158 160 for (int i = 0; i < m_colors.Count(); i++) … … 189 191 } 190 192 191 192 193 193 void Palette::SetColor(int n, u8vec3 color) 194 194 { … … 214 214 m_used.Resize(number_colors); 215 215 defaults(); 216 }217 218 219 220 quant_node::~quant_node()221 {222 /* if (!is_leaf())223 { for (i=0; i<8; i++)224 if (children[i])225 { delete children[i];226 children[i]=NULL;227 }228 } */229 }230 231 232 /*void quant_node::prune()233 {234 int t,r,g,b;235 ASSERT(!is_leaf(),"Cannot prune a leaf!");236 total(t,r,g,b);237 red=r/t;238 green=g/t;239 blue=b/t;240 be_childish();241 } */242 243 void quant_node::total(int &tnodes, int &tr, int &tg, int &tb)244 {245 int i;246 if (is_leaf())247 { tnodes+=tot;248 tr+=red*tot;249 tg+=green*tot;250 tb+=blue*tot;251 }252 else253 { for (i=0; i<8; i++)254 if (children[i])255 children[i]->total(tnodes,tr,tg,tb);256 }257 }258 259 quant_node::quant_node(int level, quant_node *dad,260 unsigned char r, unsigned char g, unsigned char b)261 {262 int i;263 ASSERT(level <= 8, "Tree cannot have more than eight levels");264 265 if (level == 8)266 be_childish();267 else268 for (i=0; i<8; i++) children[i]=NULL;269 padre = dad;270 red = r; green = g; blue = b;271 tot = 0;272 }273 274 quant_palette::quant_palette(int max_colors)275 { root=NULL; nc=0; mx=max_colors; }276 277 void quant_palette::re_delete(quant_node *who, int lev) // removes all children from memory278 { int x; // and recurses down279 if (who)280 {281 if (!who->is_leaf())282 { for (x=0; x<8; x++)283 if (who->children[x])284 {285 ASSERT(lev < 8, "Levl > 7");286 re_delete(who->children[x],lev+1);287 level[lev].unlink(who->children[x]);288 delete who->children[x];289 }290 }291 }292 }293 294 void quant_palette::prune()295 {296 int pruned,lev,x,r,g,b,t;297 quant_node *p=NULL,*f=NULL;298 for (pruned=0,lev=8; lev>1 && !pruned; lev--)299 {300 p=(quant_node *)level[lev-1].first();301 if (p)302 { do303 {304 f=p->father();305 for (x=0; x<8 && !pruned; x++)306 if (f->children[x])307 if (f->children[x]->Next()!=p->Next()) // if this son is not me!308 pruned=1; // I have a brother! stop309 p=(quant_node *)p->Next();310 } while (p != level[lev-1].first() && !pruned);311 }312 }313 ASSERT(lev > 0, "could not prune!");314 t=0; r=0; g=0; b=0;315 f->total(t,r,g,b);316 if (t<=1)317 {318 t=0; r=0; g=0; b=0;319 f->total(t,r,g,b);320 }321 ASSERT(t > 1, "Should be more colors");322 printf("%d Pruned at level %d, r=%d, g=%d, b=%d, total nodes off = %d\n",nc,323 lev,r/t,g/t,b/t,t);324 f->set(r/t,g/t,b/t);325 nc-=t;326 nc++;327 re_delete(f,lev);328 f->be_childish();329 }330 331 quant_palette::~quant_palette()332 {333 if (root)334 {335 re_delete(root,1);336 delete root;337 }338 216 } 339 217 … … 378 256 } 379 257 380 Palette *last_loaded() 258 void Palette::Load() 259 { 260 // Force to only 256 colours. 261 // Shouldn't be needed, but best to be safe. 262 if (m_colors.Count() > 256) 263 m_colors.Resize(256); 264 265 delete lastl; 266 lastl = Copy(); 267 } 268 269 Palette *Palette::LastLoaded() 381 270 { 382 271 return lastl; -
abuse/branches/lol/src/imlib/palette.h
r703 r708 14 14 #include "linked.h" 15 15 #include "specs.h" 16 #define COLOR_BITS 6 // On PC-6, most others -817 #define COLOR_SHIFT (8-COLOR_BITS)18 #define MAX_COLOR ((1<<COLOR_BITS)-1)19 #define RED3(x) (unsigned char) ((((int)x&(7<<5))>>5)*(int)255/(int)7)20 #define GREEN3(x) (unsigned char) (((x&(7<<2))>>2)*(int)255/(int)7)21 #define BLUE2(x) (unsigned char) ((x&3)*(int)255/(int)3)22 23 16 24 17 class Palette : public linked_node 25 18 { 26 19 public: 27 Palette(int number_colors=256);28 Palette(SpecEntry *e, bFILE *fp);29 Palette(bFILE *fp);20 Palette(int number_colors=256); 21 Palette(SpecEntry *e, bFILE *fp); 22 Palette(bFILE *fp); 30 23 31 Palette *Copy() const; 24 /* FIXME: this should actually be "Active()" or "SetActive()" */ 25 void Load(); 26 static Palette *LastLoaded(); 32 27 33 int Count() const { return m_colors.Count(); } 34 u8vec3 *Data() { return m_colors.Data(); } 35 u8vec3 const *Data() const { return m_colors.Data(); } 28 Palette *Copy() const; 36 29 37 u8vec3 GetColor(int x) const;38 uint8_t GetGray(int x) const;39 void SetColor(int x, u8vec3 color);30 int Count() const { return m_colors.Count(); } 31 u8vec3 *Data() { return m_colors.Data(); } 32 u8vec3 const *Data() const { return m_colors.Data(); } 40 33 41 int FindColor(u8vec3 color) const; 42 int FindClosest(u8vec3 color) const; 43 int FindBrightest(int all = 0) const; 44 int FindDarkest(int all = 0, int noblack = 1) const; 34 u8vec3 GetColor(int x) const; 35 uint8_t GetGray(int x) const; 36 void SetColor(int x, u8vec3 color); 45 37 46 void FadeTo(int total_fades, int fade_on, u8vec3 dest); 38 int FindColor(u8vec3 color) const; 39 int FindClosest(u8vec3 color) const; 40 int FindBrightest(int all = 0) const; 41 int FindDarkest(int all = 0, int noblack = 1) const; 42 43 void FadeTo(int total_fades, int fade_on, u8vec3 dest); 47 44 48 45 private: 49 Array<u8vec3> m_colors;50 Array<uint8_t> m_used;51 int bg;46 Array<u8vec3> m_colors; 47 Array<uint8_t> m_used; 48 int bg; 52 49 53 50 public : 54 uint32_t getquad(int x); 55 void shift(int amount); 56 void load(); 51 uint32_t getquad(int x); 52 void shift(int amount); 57 53 58 void defaults();59 void set_rgbs();60 void make_black_white();61 void black_white();54 void defaults(); 55 void set_rgbs(); 56 void make_black_white(); 57 void black_white(); 62 58 63 int used(int color_num);64 void set_all_used();65 void set_all_unused();66 int write(bFILE *fp);67 int size();59 int used(int color_num); 60 void set_all_used(); 61 void set_all_unused(); 62 int write(bFILE *fp); 63 int size(); 68 64 }; 69 65 70 class quant_node : public linked_node71 {72 quant_node *padre;73 public :74 unsigned tot;75 quant_node *children[8];76 int is_leaf() { return children[0]==this; }77 void be_childish() { children[0]=this; }78 quant_node *father() { return padre; }79 quant_node(int level, quant_node *dad,80 unsigned char r=0, unsigned char g=0, unsigned char b=0);81 void total(int &tnodes, int &tr, int &tg, int &tb);82 // void prune();83 void set(int r,int g,int b) { red=r; green=g; blue=b; }84 unsigned char red,green,blue;85 ~quant_node();86 } ;87 88 89 class quant_palette90 {91 linked_list level[8];92 quant_node *root;93 int nc,mx;94 void prune();95 void re_delete(quant_node *who, int lev);96 public :97 quant_palette(int max_colors=256);98 ~quant_palette();99 } ;100 101 Palette *last_loaded();102 66 #endif 103 67 -
abuse/branches/lol/src/imlib/supmorph.cpp
r706 r708 348 348 349 349 CreateScreen(argc,argv); 350 pal-> load();350 pal->Load(); 351 351 i1->put_image(screen,30,30); 352 352 update_dirty(screen); -
abuse/branches/lol/src/imlib/video.h
r701 r708 30 30 extern int xoff,yoff; 31 31 extern image *main_screen; 32 extern Palette *lastl;33 32 34 33 void CreateScreen(int argc, char **argv); -
abuse/branches/lol/src/sdlport/video.cpp
r701 r708 144 144 } 145 145 146 //147 // load()148 // Set the palette149 //150 void Palette::load()151 {152 // Force to only 256 colours.153 // Shouldn't be needed, but best to be safe.154 if (m_colors.Count() > 256)155 m_colors.Resize(256);156 157 if (lastl)158 delete lastl;159 lastl = Copy();160 161 // Now redraw the surface162 UpdateScreen();163 }164 165 146 // ---- support functions ---- 166 147
Note: See TracChangeset
for help on using the changeset viewer.