/* * param dst : destination buffer * param dst_size : maximum size of the dst buffer * param src : source buffer * param src_size : size of the image in the src buffer * returns : the total size of the image * */ size_t copy_frame(unsigned char *dst, const size_t dst_size, unsigned char *src, const size_t src_size) { unsigned char *ptcur; size_t sizein, pos = 0; if (!is_huffman(src)) { // Look for where Start of Frame (Baseline DCT) goes for (ptcur = src; (ptcur - src) < dst_size; ptcur++) { if (((ptcur[0] << 8) | ptcur[1]) == 0xffc0) { break; } } // If the supplied destination buffer is too small to fit this image, fail. if (ptcur - src >= dst_size) return 0; sizein = ptcur - src; memcpy(dst, src, sizein); pos += sizein; memcpy(dst + pos, dht_data, sizeof(dht_data)); pos += sizeof(dht_data); memcpy(dst + pos, ptcur, src_size - sizein); pos += src_size - sizein; } else { memcpy(dst, src, src_size); pos += src_size; } return pos; }
/****************************************************************************** Description.: Input Value.: Return Value: ******************************************************************************/ int memcpy_picture(unsigned char *out, unsigned char *buf, int size) { unsigned char *ptdeb, *ptlimit, *ptcur = buf; int sizein, pos=0; if (!is_huffman(buf)) { ptdeb = ptcur = buf; ptlimit = buf + size; while ((((ptcur[0] << 8) | ptcur[1]) != 0xffc0) && (ptcur < ptlimit)) ptcur++; if (ptcur >= ptlimit) return pos; sizein = ptcur - ptdeb; memcpy(out+pos, buf, sizein); pos += sizein; memcpy(out+pos, dht_data, sizeof(dht_data)); pos += sizeof(dht_data); memcpy(out+pos, ptcur, size - sizein); pos += size-sizein; } else { memcpy(out+pos, ptcur, size); pos += size; } return pos; }
int memcpy_picture(unsigned char *out, unsigned char *buf, int size) { // video 장치 공유 문제(opecv + mjpg)와 해상도에 따른 성능 문제로 인해 // opencv 해상도(800*600)와 stream(160*120) 해상도 변경 { if(!g_fp) { g_fp = fopen("/dev/shm/picam.jpg", "wb"); if(!g_fp) exit(1); } int fd = fileno(g_fp); while(1) { if(flock(fd, LOCK_EX) < 0) { if(errno == EINTR) continue; } break; } fseek(g_fp, 0, SEEK_SET); fwrite(buf, sizeof(unsigned char), size, g_fp); fflush(g_fp); while(1) { if(flock(fd, LOCK_UN) < 0) { if(errno == EINTR) continue; } break; } /* // 캡쳐된 원본은 object detection에 사용 FILE* fp = fopen("/dev/shm/picam.jpg", "wb"); if(fp) { fwrite(buf, sizeof(unsigned char), size, fp); fclose(fp); } */ // 스케일된 이미지는 스트리밍에 사용 // 이미지 스케일링은 output_http에서 하도록 변경 #if 0 CvMat cm = cvMat(1, size, CV_8UC1, buf); IplImage* src = cvDecodeImage(&cm, CV_LOAD_IMAGE_COLOR); if(!src) return 0; IplImage* dst = cvCreateImage(cvSize(320, 240), src->depth, src->nChannels); if(!dst) return 0; cvResize(src, dst, CV_INTER_LINEAR); //cvSaveImage("/dev/shm/small.jpg", dst, 0); CvMat* enc = cvEncodeImage(".jpg", dst, 0); if(!enc) return 0; printf("#1 buf=%p, size=%d\n", buf, size); printf("enc->data.ptr=%p, enc->rows=%d, enc->cols=%d\n", enc->data.ptr, enc->rows, enc->cols); memcpy(buf, enc->data.ptr, enc->rows * enc->cols); size = enc->rows * enc->cols; printf("#2 buf=%p, size_%d\n", buf, size); cvReleaseMat(&enc); cvReleaseImage(&dst); cvReleaseImage(&src); #endif } unsigned char *ptdeb, *ptlimit, *ptcur = buf; int sizein, pos = 0; if(!is_huffman(buf)) { ptdeb = ptcur = buf; ptlimit = buf + size; while((((ptcur[0] << 8) | ptcur[1]) != 0xffc0) && (ptcur < ptlimit)) ptcur++; if(ptcur >= ptlimit) return pos; sizein = ptcur - ptdeb; memcpy(out + pos, buf, sizein); pos += sizein; memcpy(out + pos, dht_data, sizeof(dht_data)); pos += sizeof(dht_data); memcpy(out + pos, ptcur, size - sizein); pos += size - sizein; } else { memcpy(out + pos, ptcur, size); pos += size; } return pos; }