forked from xiaozhuai/GifEncoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParallel_Example.txt
More file actions
20 lines (20 loc) · 984 Bytes
/
Copy pathParallel_Example.txt
File metadata and controls
20 lines (20 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
GifEncoder* e = new GifEncoder();
e->setTransparent(0, 0, 0); // black is transparent
e->open_parallel(ConvertToStdString(gifTempPath), w, h, 1, 0, &cancel->Token)
for(int i = 0; i < frames; ++i) task[i] = std::thread(ParallelThread, e, i);
for(int i = 0; i < frames; ++i) if(task[i].joinable()) task[i].join();
e->close();
while(true){ int u = e->getFinishedFrame();
switch(result = e->tryWrite(&cancel->Token))
case GifEncoderTryWriteResult::Failed: return "failed";
case GifEncoderTryWriteResult::FinishedFrame: b[u]->UnlockBits(d[u]);break;
case GifEncoderTryWriteResult::FinishedAnimation: return "success";
}}
void ParallelThread(GifEncoder* e, int i){
r = Rectangle(0, 0, w, h);
b[i] = gcnew Bitmap(w,h)
d[i] = b[i]->LockBits(r, ImageLockMode::WriteOnly, PixelFormat::Format24bppRgb);
uint8_t* p, mp = p = (uint8_t*)(void*)d[i]->Scan0;
for(int y = 0; y<h; ++y)for(int x = 0; x<w; ++x){p[2]=blue;p[1]=green;p[0]=red;p+=3;}
e->push_parallel(mp, w, h, delay, i, &cancel->Token);
}