intra_trace.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #ifdef HAVE_CONFIG_H
  2. #include "config.h"
  3. #endif
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "od_defs.h"
  7. #include "od_filter.h"
  8. #include "image_tools.h"
  9. #include "stats_tools.h"
  10. #include "trans_tools.h"
  11. #include "od_intra.h"
  12. typedef struct intra_trace_ctx intra_trace_ctx;
  13. struct intra_trace_ctx{
  14. int x;
  15. int y;
  16. int d;
  17. int c;
  18. image_data img;
  19. od_coeff min[OD_INTRA_NMODES];
  20. od_coeff max[OD_INTRA_NMODES];
  21. };
  22. void intra_trace_ctx_reset(intra_trace_ctx *_this){
  23. _this->x=0;
  24. _this->y=0;
  25. _this->d=3;
  26. _this->c=0;
  27. }
  28. void intra_trace_ctx_init(intra_trace_ctx *_this){
  29. int i;
  30. intra_trace_ctx_reset(_this);
  31. image_data_init(&_this->img,NULL,B_SZ_LOG,1,1);
  32. for(i=0;i<OD_INTRA_NMODES;i++){
  33. _this->min[i]=INT_MAX;
  34. _this->max[i]=-INT_MAX;
  35. }
  36. }
  37. void intra_trace_ctx_clear(intra_trace_ctx *_this){
  38. image_data_clear(&_this->img);
  39. }
  40. int intra_trace_ctx_next(intra_trace_ctx *_this,int _loop){
  41. int m;
  42. /*printf("%i %i %i\n",_this->x,_this->y,_this->d);*/
  43. m=0;
  44. if(_this->d&2){
  45. if(_this->d&1){
  46. if(_this->y==B_SZ*3-1){
  47. _this->x+=_this->x&1?-1:1;
  48. _this->d=2;
  49. m=1;
  50. }
  51. }
  52. else{
  53. if(_this->y==(_this->x^1)){
  54. _this->x++;
  55. _this->d=1;
  56. m=1;
  57. }
  58. }
  59. }
  60. else{
  61. if(_this->d&1){
  62. if(_this->x==B_SZ*4-1){
  63. _this->y+=_this->y&1?-1:1;
  64. _this->d=0;
  65. m=1;
  66. }
  67. }
  68. else{
  69. if(_this->x==(_this->y&1?_this->y+1:_this->y-1)){
  70. _this->y++;
  71. _this->d=3;
  72. m=1;
  73. }
  74. }
  75. }
  76. if(!m){
  77. if(_this->d&2){
  78. _this->y+=_this->d&1?1:-1;
  79. }
  80. else{
  81. _this->x+=_this->d&1?1:-1;
  82. }
  83. }
  84. if(_loop&&_this->x==2*B_SZ&&_this->y==2*B_SZ){
  85. _this->x=2*B_SZ-1;
  86. _this->y=2*B_SZ-1;
  87. _this->d=3;
  88. }
  89. _this->c++;
  90. if(_loop){
  91. return(_this->x==0&&_this->y==0);
  92. }
  93. else{
  94. return(_this->x==B_SZ&&_this->y==B_SZ);
  95. }
  96. }
  97. #define SUPPORT_SZ 32
  98. #define SPACE_SZ 16
  99. #define BLOCK_SZ 128
  100. #define IMAGE_X (5*(SPACE_SZ+BLOCK_SZ)+SPACE_SZ)
  101. #define IMAGE_Y (3*(SPACE_SZ+BLOCK_SZ)+SPACE_SZ)
  102. static void draw_pulse(od_rgba16_image *_image,int _x,int _y){
  103. int x0;
  104. int y0;
  105. od_rgba16_pixel c;
  106. int n;
  107. int j;
  108. int i;
  109. x0=(IMAGE_X-4*SUPPORT_SZ)/2;
  110. y0=SPACE_SZ+(BLOCK_SZ-3*SUPPORT_SZ)/2;
  111. n=SUPPORT_SZ/B_SZ;
  112. c[3]=(unsigned short)0xFFFFU;
  113. /* Clear region. */
  114. c[0]=c[1]=c[2]=0;
  115. for(j=0;j<3*SUPPORT_SZ;j++){
  116. for(i=0;i<4*SUPPORT_SZ;i++){
  117. od_rgba16_image_draw_point(_image,x0+i,y0+j,c);
  118. }
  119. }
  120. /* Draw blocks. */
  121. x0+=SUPPORT_SZ/2;
  122. y0+=SUPPORT_SZ/2;
  123. c[0]=c[1]=c[2]=0x7F00;
  124. for(j=0;j<SUPPORT_SZ;j++){
  125. for(i=0;i<SUPPORT_SZ;i++){
  126. od_rgba16_image_draw_point(_image,x0+SUPPORT_SZ*0+i,y0+SUPPORT_SZ*0+j,c);
  127. od_rgba16_image_draw_point(_image,x0+SUPPORT_SZ*1+i,y0+SUPPORT_SZ*0+j,c);
  128. od_rgba16_image_draw_point(_image,x0+SUPPORT_SZ*2+i,y0+SUPPORT_SZ*0+j,c);
  129. od_rgba16_image_draw_point(_image,x0+SUPPORT_SZ*0+i,y0+SUPPORT_SZ*1+j,c);
  130. }
  131. }
  132. /* Draw pulse. */
  133. x0-=SUPPORT_SZ/2;
  134. y0-=SUPPORT_SZ/2;
  135. c[0]=c[1]=c[2]=0xFF00;
  136. for(j=0;j<n;j++){
  137. for(i=0;i<n;i++){
  138. od_rgba16_image_draw_point(_image,x0+n*_x+i,y0+n*_y+j,c);
  139. }
  140. }
  141. }
  142. static void draw_point(od_rgba16_image *_image,int _m,int _x,int _y,
  143. unsigned char _v){
  144. int x0;
  145. int y0;
  146. int n;
  147. od_rgba16_pixel c;
  148. int j;
  149. int i;
  150. x0=SPACE_SZ+(SPACE_SZ+BLOCK_SZ)*(_m%5);
  151. y0=(SPACE_SZ+BLOCK_SZ)*(_m/5+1);
  152. n=BLOCK_SZ/(2*B_SZ);
  153. c[3]=(unsigned short)0xFFFFU;
  154. c[0]=c[1]=c[2]=_v*0x101;
  155. for(j=0;j<n;j++){
  156. for(i=0;i<n;i++){
  157. od_rgba16_image_draw_point(_image,x0+n*_x+i,y0+n*_y+j,c);
  158. }
  159. }
  160. }
  161. static void intra_trace_ctx_step(intra_trace_ctx *_ctx,od_rgba16_image *_image,
  162. const int *_f){
  163. unsigned char data[4*B_SZ*4*B_SZ];
  164. int m;
  165. (void)_f;
  166. memset(data,0,4*B_SZ*4*B_SZ);
  167. data[4*B_SZ*_ctx->y+_ctx->x]=255;
  168. draw_pulse(_image,_ctx->x,_ctx->y);
  169. image_data_pre_block(&_ctx->img,&data[4*B_SZ*(3*B_SZ>>1)+(3*B_SZ>>1)],4*B_SZ,
  170. 0,0);
  171. image_data_fdct_block(&_ctx->img,0,0);
  172. #if TF_BLOCKS
  173. image_data_tf_block(&_ctx->img,0,0);
  174. #endif
  175. for(m=0;m<OD_INTRA_NMODES;m++){
  176. int j;
  177. int i;
  178. _ctx->img.mode[0]=m;
  179. image_data_pred_block(&_ctx->img,0,0);
  180. image_data_idct_block(&_ctx->img,0,0);
  181. /* Set non-predicted blocks to zero before post-filtering. */
  182. for(j=0;j<3*B_SZ;j++){
  183. for(i=0;i<3*B_SZ;i++){
  184. if(j/B_SZ!=1||i/B_SZ!=1){
  185. _ctx->img.idct[3*B_SZ*j+i]=-128*INPUT_SCALE;
  186. }
  187. }
  188. }
  189. image_data_post_block(&_ctx->img,0,0);
  190. for(j=0;j<2*B_SZ;j++){
  191. for(i=0;i<2*B_SZ;i++){
  192. od_coeff v;
  193. v=(_ctx->img.post[2*B_SZ*j+i]+INPUT_SCALE*128+INPUT_SCALE/2)/INPUT_SCALE;
  194. if(_ctx->min[m]>v){
  195. _ctx->min[m]=v;
  196. }
  197. if(_ctx->max[m]<v){
  198. _ctx->max[m]=v;
  199. }
  200. draw_point(_image,m,i,j,OD_CLAMPI(0,v+128,255));
  201. }
  202. }
  203. }
  204. }
  205. int main(int _argc,char *_argv[]){
  206. intra_trace_ctx ctx;
  207. const int *f;
  208. od_rgba16_image image;
  209. (void)_argc;
  210. (void)_argv;
  211. ne_filter_params_init();
  212. od_scale_init(OD_SCALE[B_SZ_LOG-OD_LOG_BSIZE0],B_SZ_LOG);
  213. #if B_SZ==4
  214. f=NE_FILTER_PARAMS4;
  215. #elif B_SZ==8
  216. f=NE_FILTER_PARAMS8;
  217. #elif B_SZ==16
  218. f=NE_FILTER_PARAMS16;
  219. #else
  220. # error "Unsupported block size."
  221. #endif
  222. od_intra_init();
  223. intra_trace_ctx_init(&ctx);
  224. od_rgba16_image_init(&image,IMAGE_X,IMAGE_Y);
  225. do {
  226. char name[16];
  227. intra_trace_ctx_step(&ctx,&image,f);
  228. sprintf(name,"trace%04i",ctx.c);
  229. image_write_png(&image,name);
  230. }
  231. while(!intra_trace_ctx_next(&ctx,1));
  232. {
  233. int i;
  234. for(i=0;i<OD_INTRA_NMODES;i++){
  235. printf("%4i %4i\n",ctx.min[i],ctx.max[i]);
  236. }
  237. }
  238. intra_trace_ctx_clear(&ctx);
  239. od_rgba16_image_clear(&image);
  240. return EXIT_SUCCESS;
  241. }