| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C)2009-2011 D. R. Commander. All Rights Reserved. | 2 * Copyright (C)2009-2011 D. R. Commander. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are met: | 5 * modification, are permitted provided that the following conditions are met: |
| 6 * | 6 * |
| 7 * - Redistributions of source code must retain the above copyright notice, | 7 * - Redistributions of source code must retain the above copyright notice, |
| 8 * this list of conditions and the following disclaimer. | 8 * this list of conditions and the following disclaimer. |
| 9 * - Redistributions in binary form must reproduce the above copyright notice, | 9 * - Redistributions in binary form must reproduce the above copyright notice, |
| 10 * this list of conditions and the following disclaimer in the documentation | 10 * this list of conditions and the following disclaimer in the documentation |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 { | 61 { |
| 62 "4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0" | 62 "4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0" |
| 63 }; | 63 }; |
| 64 const char *subName[TJ_NUMSAMP]={"444", "422", "420", "GRAY", "440"}; | 64 const char *subName[TJ_NUMSAMP]={"444", "422", "420", "GRAY", "440"}; |
| 65 | 65 |
| 66 const char *pixFormatStr[TJ_NUMPF]= | 66 const char *pixFormatStr[TJ_NUMPF]= |
| 67 { | 67 { |
| 68 "RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "Grayscale" | 68 "RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "Grayscale" |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 const int alphaOffset[TJ_NUMPF] = {-1, -1, 3, 3, 0, 0, -1}; |
| 72 |
| 71 const int _3byteFormats[]={TJPF_RGB, TJPF_BGR}; | 73 const int _3byteFormats[]={TJPF_RGB, TJPF_BGR}; |
| 72 const int _4byteFormats[]={TJPF_RGBX, TJPF_BGRX, TJPF_XBGR, TJPF_XRGB}; | 74 const int _4byteFormats[]={TJPF_RGBX, TJPF_BGRX, TJPF_XBGR, TJPF_XRGB}; |
| 73 const int _onlyGray[]={TJPF_GRAY}; | 75 const int _onlyGray[]={TJPF_GRAY}; |
| 74 const int _onlyRGB[]={TJPF_RGB}; | 76 const int _onlyRGB[]={TJPF_RGB}; |
| 75 | 77 |
| 76 enum {YUVENCODE=1, YUVDECODE}; | 78 enum {YUVENCODE=1, YUVDECODE}; |
| 77 int yuv=0, alloc=0; | 79 int yuv=0, alloc=0; |
| 78 | 80 |
| 79 int exitStatus=0; | 81 int exitStatus=0; |
| 80 #define bailout() {exitStatus=-1; goto bailout;} | 82 #define bailout() {exitStatus=-1; goto bailout;} |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 retval=0; exitStatus=-1; goto bailout; \ | 151 retval=0; exitStatus=-1; goto bailout; \ |
| 150 }} | 152 }} |
| 151 | 153 |
| 152 | 154 |
| 153 int checkBuf(unsigned char *buf, int w, int h, int pf, int subsamp, | 155 int checkBuf(unsigned char *buf, int w, int h, int pf, int subsamp, |
| 154 tjscalingfactor sf, int flags) | 156 tjscalingfactor sf, int flags) |
| 155 { | 157 { |
| 156 int roffset=tjRedOffset[pf]; | 158 int roffset=tjRedOffset[pf]; |
| 157 int goffset=tjGreenOffset[pf]; | 159 int goffset=tjGreenOffset[pf]; |
| 158 int boffset=tjBlueOffset[pf]; | 160 int boffset=tjBlueOffset[pf]; |
| 161 int aoffset=alphaOffset[pf]; |
| 159 int ps=tjPixelSize[pf]; | 162 int ps=tjPixelSize[pf]; |
| 160 int index, row, col, retval=1; | 163 int index, row, col, retval=1; |
| 161 int halfway=16*sf.num/sf.denom; | 164 int halfway=16*sf.num/sf.denom; |
| 162 int blocksize=8*sf.num/sf.denom; | 165 int blocksize=8*sf.num/sf.denom; |
| 163 | 166 |
| 164 for(row=0; row<h; row++) | 167 for(row=0; row<h; row++) |
| 165 { | 168 { |
| 166 for(col=0; col<w; col++) | 169 for(col=0; col<w; col++) |
| 167 { | 170 { |
| 168 » » » unsigned char r, g, b; | 171 » » » unsigned char r, g, b, a; |
| 169 if(flags&TJFLAG_BOTTOMUP) index=(h-row-1)*w+col; | 172 if(flags&TJFLAG_BOTTOMUP) index=(h-row-1)*w+col; |
| 170 else index=row*w+col; | 173 else index=row*w+col; |
| 171 r=buf[index*ps+roffset]; | 174 r=buf[index*ps+roffset]; |
| 172 g=buf[index*ps+goffset]; | 175 g=buf[index*ps+goffset]; |
| 173 b=buf[index*ps+boffset]; | 176 b=buf[index*ps+boffset]; |
| 177 a=aoffset>=0? buf[index*ps+aoffset]:0xFF; |
| 174 if(((row/blocksize)+(col/blocksize))%2==0) | 178 if(((row/blocksize)+(col/blocksize))%2==0) |
| 175 { | 179 { |
| 176 if(row<halfway) | 180 if(row<halfway) |
| 177 { | 181 { |
| 178 checkval255(r); checkval255(g); checkv
al255(b); | 182 checkval255(r); checkval255(g); checkv
al255(b); |
| 179 } | 183 } |
| 180 else | 184 else |
| 181 { | 185 { |
| 182 checkval0(r); checkval0(g); checkval0(
b); | 186 checkval0(r); checkval0(g); checkval0(
b); |
| 183 } | 187 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 200 if(row<halfway) | 204 if(row<halfway) |
| 201 { | 205 { |
| 202 checkval255(r); checkval0(g);
checkval0(b); | 206 checkval255(r); checkval0(g);
checkval0(b); |
| 203 } | 207 } |
| 204 else | 208 else |
| 205 { | 209 { |
| 206 checkval255(r); checkval255(g);
checkval0(b); | 210 checkval255(r); checkval255(g);
checkval0(b); |
| 207 } | 211 } |
| 208 } | 212 } |
| 209 } | 213 } |
| 214 checkval255(a); |
| 210 } | 215 } |
| 211 } | 216 } |
| 212 | 217 |
| 213 bailout: | 218 bailout: |
| 214 if(retval==0) | 219 if(retval==0) |
| 215 { | 220 { |
| 216 printf("\n"); | 221 printf("\n"); |
| 217 for(row=0; row<h; row++) | 222 for(row=0; row<h; row++) |
| 218 { | 223 { |
| 219 for(col=0; col<w; col++) | 224 for(col=0; col<w; col++) |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 doTest(48, 48, _onlyRGB, 1, TJSAMP_440, "test_yuv0"); | 638 doTest(48, 48, _onlyRGB, 1, TJSAMP_440, "test_yuv0"); |
| 634 doTest(35, 39, _onlyRGB, 1, TJSAMP_440, "test_yuv1"); | 639 doTest(35, 39, _onlyRGB, 1, TJSAMP_440, "test_yuv1"); |
| 635 doTest(48, 48, _onlyRGB, 1, TJSAMP_GRAY, "test_yuv0"); | 640 doTest(48, 48, _onlyRGB, 1, TJSAMP_GRAY, "test_yuv0"); |
| 636 doTest(35, 39, _onlyRGB, 1, TJSAMP_GRAY, "test_yuv1"); | 641 doTest(35, 39, _onlyRGB, 1, TJSAMP_GRAY, "test_yuv1"); |
| 637 doTest(48, 48, _onlyGray, 1, TJSAMP_GRAY, "test_yuv0"); | 642 doTest(48, 48, _onlyGray, 1, TJSAMP_GRAY, "test_yuv0"); |
| 638 doTest(39, 41, _onlyGray, 1, TJSAMP_GRAY, "test_yuv1"); | 643 doTest(39, 41, _onlyGray, 1, TJSAMP_GRAY, "test_yuv1"); |
| 639 } | 644 } |
| 640 | 645 |
| 641 return exitStatus; | 646 return exitStatus; |
| 642 } | 647 } |
| OLD | NEW |