Permalink
Browse files

improved this crayzy code

  • Loading branch information...
1 parent 9407c4b commit 97d96d3004319321958668881abcbc5e10a52bcd @pkrumins committed Aug 5, 2010
Showing with 23 additions and 16 deletions.
  1. +23 −16 src/dynamic_jpeg_stack.cpp
View
@@ -86,37 +86,44 @@ DynamicJpegStack::Push(unsigned char *data_buf, int x, int y, int w, int h)
if (buf_type == BUF_RGB) {
for (int i = 0; i < h; i++) {
- for (int j = 0; j < 3*w; j+=3) {
- data[start + i*bg_width*3 + j] = data_buf[i*w*3 + j];
- data[start + i*bg_width*3 + j + 1] = data_buf[i*w*3 + j + 1];
- data[start + i*bg_width*3 + j + 2] = data_buf[i*w*3 + j + 2];
+ unsigned char *datap = &data[start + i*bg_width*3];
+ for (int j = 0; j < w; j++) {
+ *datap++ = *data_buf++;
+ *datap++ = *data_buf++;
+ *datap++ = *data_buf++;
}
}
}
else if (buf_type == BUF_BGR) {
for (int i = 0; i < h; i++) {
- for (int j = 0; j < 3*w; j+=3) {
- data[start + i*bg_width*3 + j] = data_buf[i*w*3 + j + 2];
- data[start + i*bg_width*3 + j + 1] = data_buf[i*w*3 + j + 1];
- data[start + i*bg_width*3 + j + 2] = data_buf[i*w*3 + j];
+ unsigned char *datap = &data[start + i*bg_width*3];
+ for (int j = 0; j < w; j++) {
+ *datap++ = *(data_buf+2);
+ *datap++ = *(data_buf+1);
+ *datap++ = *data_buf;
+ data_buf+=3;
}
}
}
else if (buf_type == BUF_RGBA) {
for (int i = 0; i < h; i++) {
- for (int j = 0, k = 0; j < 3*w; j+=3, k+=4) {
- data[start + i*bg_width*3 + j] = data_buf[i*w*4 + k];
- data[start + i*bg_width*3 + j + 1] = data_buf[i*w*4 + k + 1];
- data[start + i*bg_width*3 + j + 2] = data_buf[i*w*4 + k + 2];
+ unsigned char *datap = &data[start + i*bg_width*3];
+ for (int j = 0; j < w; j++) {
+ *datap++ = *data_buf++;
+ *datap++ = *data_buf++;
+ *datap++ = *data_buf++;
+ data_buf++;
}
}
}
else if (buf_type == BUF_BGRA) {
for (int i = 0; i < h; i++) {
- for (int j = 0, k = 0; j < 3*w; j+=3, k+=4) {
- data[start + i*bg_width*3 + j] = data_buf[i*w*4 + k + 2];
- data[start + i*bg_width*3 + j + 1] = data_buf[i*w*4 + k + 1];
- data[start + i*bg_width*3 + j + 2] = data_buf[i*w*4 + k];
+ unsigned char *datap = &data[start + i*bg_width*3];
+ for (int j = 0; j < w; j++) {
+ *datap++ = *(data_buf+2);
+ *datap++ = *(data_buf+1);
+ *datap++ = *data_buf;
+ data_buf += 4;
}
}
}

0 comments on commit 97d96d3

Please sign in to comment.