gst_plugins_base/gst/videoscale/vs_scanline.c
branchRCL_3
changeset 29 567bb019e3e3
parent 0 0e761a78d257
child 30 7e817e7e631c
equal deleted inserted replaced
6:9b2c3c7a1a9c 29:567bb019e3e3
    24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    25  * POSSIBILITY OF SUCH DAMAGE.
    25  * POSSIBILITY OF SUCH DAMAGE.
    26  */
    26  */
    27 
    27 
    28 #include "vs_scanline.h"
    28 #include "vs_scanline.h"
    29 #include <gst/liboil.h>
    29 
       
    30 #include <liboil/liboil.h>
    30 
    31 
    31 /* greyscale, i.e., single componenet */
    32 /* greyscale, i.e., single componenet */
    32 #ifdef __SYMBIAN32__
    33 #ifdef __SYMBIAN32__
       
    34 #include <liboil/globals.h>
       
    35 #endif
       
    36 #include <glib.h>
       
    37 #ifdef __SYMBIAN32__
    33 EXPORT_C
    38 EXPORT_C
    34 #endif
    39 #endif
    35 
    40 
    36 
    41 
    37 void
    42 void
    47 EXPORT_C
    52 EXPORT_C
    48 #endif
    53 #endif
    49 
    54 
    50 
    55 
    51 void
    56 void
    52 vs_scanline_resample_nearest_Y (uint8_t * dest, uint8_t * src, int n,
    57 vs_scanline_resample_nearest_Y (uint8_t * dest, uint8_t * src, int src_width,
    53     int *accumulator, int increment)
    58     int n, int *accumulator, int increment)
    54 {
    59 {
    55   int acc = *accumulator;
    60   int acc = *accumulator;
    56   int i;
    61   int i;
    57   int j;
    62   int j;
    58   int x;
    63   int x;
    59 
    64 
    60   for (i = 0; i < n; i++) {
    65   for (i = 0; i < n; i++) {
    61     j = acc >> 16;
    66     j = acc >> 16;
    62     x = acc & 0xffff;
    67     x = acc & 0xffff;
    63     dest[i] = (x < 32768) ? src[j] : src[j + 1];
    68     dest[i] = (x < 32768 || j + 1 >= src_width) ? src[j] : src[j + 1];
    64 
    69 
    65     acc += increment;
    70     acc += increment;
    66   }
    71   }
    67 
    72 
    68   *accumulator = acc;
    73   *accumulator = acc;
    69 }
    74 }
    70 #ifdef __SYMBIAN32__
    75 #ifdef __SYMBIAN32__
    71 EXPORT_C
    76 EXPORT_C
    72 #endif
    77 #endif
    73 
    78 
    74 
    79 void
    75 void
    80 vs_scanline_resample_linear_Y (uint8_t * dest, uint8_t * src, int src_width,
    76 vs_scanline_resample_linear_Y (uint8_t * dest, uint8_t * src, int n,
    81     int n, int *accumulator, int increment)
    77     int *accumulator, int increment)
    82 {
    78 {
    83   int acc = *accumulator;
    79   uint32_t vals[2];
    84   int i;
    80 
    85   int j;
    81   vals[0] = *accumulator;
    86   int x;
    82   vals[1] = increment;
    87 
    83 
    88   for (i = 0; i < n; i++) {
    84   oil_resample_linear_u8 (dest, src, n, vals);
    89     j = acc >> 16;
    85 
    90     x = acc & 0xffff;
    86   *accumulator = vals[0];
    91 
       
    92     if (j + 1 < src_width)
       
    93       dest[i] = (src[j] * (65536 - x) + src[j + 1] * x) >> 16;
       
    94     else
       
    95       dest[i] = src[j];
       
    96 
       
    97     acc += increment;
       
    98   }
       
    99 
       
   100   *accumulator = acc;
    87 }
   101 }
    88 #ifdef __SYMBIAN32__
   102 #ifdef __SYMBIAN32__
    89 EXPORT_C
   103 EXPORT_C
    90 #endif
   104 #endif
    91 
   105 
    96 {
   110 {
    97   uint32_t value = x >> 8;
   111   uint32_t value = x >> 8;
    98 
   112 
    99   oil_merge_linear_u8 (dest, src1, src2, &value, n);
   113   oil_merge_linear_u8 (dest, src1, src2, &value, n);
   100 }
   114 }
   101 
   115 #ifdef __SYMBIAN32__
       
   116 EXPORT_C
       
   117 #endif
       
   118 
       
   119 void
       
   120 vs_scanline_downsample_Y16 (uint8_t * dest, uint8_t * src, int n)
       
   121 {
       
   122   int i;
       
   123   uint16_t *d = (uint16_t *) dest, *s = (uint16_t *) src;
       
   124 
       
   125   for (i = 0; i < n; i++) {
       
   126     d[i] = (s[i * 2] + s[i * 2 + 1]) / 2;
       
   127   }
       
   128 }
       
   129 #ifdef __SYMBIAN32__
       
   130 EXPORT_C
       
   131 #endif
       
   132 
       
   133 void
       
   134 vs_scanline_resample_nearest_Y16 (uint8_t * dest, uint8_t * src, int src_width,
       
   135     int n, int *accumulator, int increment)
       
   136 {
       
   137   int acc = *accumulator;
       
   138   int i;
       
   139   int j;
       
   140   int x;
       
   141   uint16_t *d = (uint16_t *) dest, *s = (uint16_t *) src;
       
   142 
       
   143   for (i = 0; i < n; i++) {
       
   144     j = acc >> 16;
       
   145     x = acc & 0xffff;
       
   146     d[i] = (x < 32768 || j + 1 >= src_width) ? s[j] : s[j + 1];
       
   147 
       
   148     acc += increment;
       
   149   }
       
   150 
       
   151   *accumulator = acc;
       
   152 }
       
   153 
       
   154 #include <glib.h>
       
   155 
       
   156 #ifdef __SYMBIAN32__
       
   157 EXPORT_C
       
   158 #endif
       
   159 
       
   160 void
       
   161 vs_scanline_resample_linear_Y16 (uint8_t * dest, uint8_t * src, int src_width,
       
   162     int n, int *accumulator, int increment)
       
   163 {
       
   164   int acc = *accumulator;
       
   165   int i;
       
   166   int j;
       
   167   int x;
       
   168   uint16_t *d = (uint16_t *) dest, *s = (uint16_t *) src;
       
   169 
       
   170   for (i = 0; i < n; i++) {
       
   171     j = acc >> 16;
       
   172     x = acc & 0xffff;
       
   173 
       
   174     if (j + 1 < src_width)
       
   175       d[i] = (s[j] * (65536 - x) + s[j + 1] * x) >> 16;
       
   176     else
       
   177       d[i] = s[j];
       
   178 
       
   179     acc += increment;
       
   180   }
       
   181 
       
   182   *accumulator = acc;
       
   183 }
       
   184 #ifdef __SYMBIAN32__
       
   185 EXPORT_C
       
   186 #endif
       
   187 
       
   188 void
       
   189 vs_scanline_merge_linear_Y16 (uint8_t * dest, uint8_t * src1, uint8_t * src2,
       
   190     int n, int x)
       
   191 {
       
   192   int i;
       
   193   uint16_t *d = (uint16_t *) dest, *s1 = (uint16_t *) src1, *s2 =
       
   194       (uint16_t *) src2;
       
   195 
       
   196   for (i = 0; i < n; i++) {
       
   197     d[i] = (s1[i] * (65536 - x) + s2[i] * x) >> 16;
       
   198   }
       
   199 }
   102 
   200 
   103 /* RGBA */
   201 /* RGBA */
   104 #ifdef __SYMBIAN32__
   202 #ifdef __SYMBIAN32__
   105 EXPORT_C
   203 EXPORT_C
   106 #endif
   204 #endif
   122 EXPORT_C
   220 EXPORT_C
   123 #endif
   221 #endif
   124 
   222 
   125 
   223 
   126 void
   224 void
   127 vs_scanline_resample_nearest_RGBA (uint8_t * dest, uint8_t * src, int n,
   225 vs_scanline_resample_nearest_RGBA (uint8_t * dest, uint8_t * src, int src_width,
   128     int *accumulator, int increment)
   226     int n, int *accumulator, int increment)
   129 {
   227 {
   130   int acc = *accumulator;
   228   int acc = *accumulator;
   131   int i;
   229   int i;
   132   int j;
   230   int j;
   133   int x;
   231   int x;
   134 
   232 
   135   for (i = 0; i < n; i++) {
   233   for (i = 0; i < n; i++) {
   136     j = acc >> 16;
   234     j = acc >> 16;
   137     x = acc & 0xffff;
   235     x = acc & 0xffff;
   138     dest[i * 4 + 0] = (x < 32768) ? src[j * 4 + 0] : src[j * 4 + 4];
   236 
   139     dest[i * 4 + 1] = (x < 32768) ? src[j * 4 + 1] : src[j * 4 + 5];
   237     if (j + 1 < src_width) {
   140     dest[i * 4 + 2] = (x < 32768) ? src[j * 4 + 2] : src[j * 4 + 6];
   238       dest[i * 4 + 0] = (x < 32768) ? src[j * 4 + 0] : src[j * 4 + 4];
   141     dest[i * 4 + 3] = (x < 32768) ? src[j * 4 + 3] : src[j * 4 + 7];
   239       dest[i * 4 + 1] = (x < 32768) ? src[j * 4 + 1] : src[j * 4 + 5];
   142 
   240       dest[i * 4 + 2] = (x < 32768) ? src[j * 4 + 2] : src[j * 4 + 6];
   143     acc += increment;
   241       dest[i * 4 + 3] = (x < 32768) ? src[j * 4 + 3] : src[j * 4 + 7];
   144   }
   242     } else {
   145 
   243       dest[i * 4 + 0] = src[j * 4 + 0];
   146   *accumulator = acc;
   244       dest[i * 4 + 1] = src[j * 4 + 1];
   147 }
   245       dest[i * 4 + 2] = src[j * 4 + 2];
   148 #ifdef __SYMBIAN32__
   246       dest[i * 4 + 3] = src[j * 4 + 3];
   149 EXPORT_C
   247     }
   150 #endif
   248 
   151 
   249     acc += increment;
   152 
   250   }
   153 void
   251 
   154 vs_scanline_resample_linear_RGBA (uint8_t * dest, uint8_t * src, int n,
   252   *accumulator = acc;
   155     int *accumulator, int increment)
   253 }
       
   254 
       
   255 #include <stdio.h>
       
   256 #ifdef __SYMBIAN32__
       
   257 EXPORT_C
       
   258 #endif
       
   259 
       
   260 void
       
   261 vs_scanline_resample_linear_RGBA (uint8_t * dest, uint8_t * src, int src_width,
       
   262     int n, int *accumulator, int increment)
   156 {
   263 {
   157   uint32_t vals[2];
   264   uint32_t vals[2];
   158 
   265 
   159   vals[0] = *accumulator;
   266   vals[0] = *accumulator;
   160   vals[1] = increment;
   267   vals[1] = increment;
   161 
   268 
   162   oil_resample_linear_argb ((uint32_t *) dest, (uint32_t *) src, n, vals);
   269   if (src_width % 2 == 0) {
       
   270     oil_resample_linear_argb ((uint32_t *) dest, (uint32_t *) src, n, vals);
       
   271   } else if (src_width > 1) {
       
   272     if (n > 1)
       
   273       oil_resample_linear_argb ((uint32_t *) dest, (uint32_t *) src, n - 1,
       
   274           vals);
       
   275     dest[4 * (n - 1) + 0] = src[(vals[0] >> 16) + 0];
       
   276     dest[4 * (n - 1) + 1] = src[(vals[0] >> 16) + 1];
       
   277     dest[4 * (n - 1) + 2] = src[(vals[0] >> 16) + 2];
       
   278     dest[4 * (n - 1) + 3] = src[(vals[0] >> 16) + 3];
       
   279     vals[0] += increment;
       
   280   } else {
       
   281     int i;
       
   282 
       
   283     for (i = 0; i < n; i++) {
       
   284       dest[4 * i + 0] = src[0];
       
   285       dest[4 * i + 1] = src[1];
       
   286       dest[4 * i + 2] = src[2];
       
   287       dest[4 * i + 3] = src[3];
       
   288       vals[0] += increment;
       
   289     }
       
   290   }
   163 
   291 
   164   *accumulator = vals[0];
   292   *accumulator = vals[0];
   165 }
   293 }
   166 #ifdef __SYMBIAN32__
   294 #ifdef __SYMBIAN32__
   167 EXPORT_C
   295 EXPORT_C
   200 EXPORT_C
   328 EXPORT_C
   201 #endif
   329 #endif
   202 
   330 
   203 
   331 
   204 void
   332 void
   205 vs_scanline_resample_nearest_RGB (uint8_t * dest, uint8_t * src, int n,
   333 vs_scanline_resample_nearest_RGB (uint8_t * dest, uint8_t * src, int src_width,
   206     int *accumulator, int increment)
   334     int n, int *accumulator, int increment)
   207 {
   335 {
   208   int acc = *accumulator;
   336   int acc = *accumulator;
   209   int i;
   337   int i;
   210   int j;
   338   int j;
   211   int x;
   339   int x;
   212 
   340 
   213   for (i = 0; i < n; i++) {
   341   for (i = 0; i < n; i++) {
   214     j = acc >> 16;
   342     j = acc >> 16;
   215     x = acc & 0xffff;
   343     x = acc & 0xffff;
   216     dest[i * 3 + 0] = (x < 32768) ? src[j * 3 + 0] : src[j * 3 + 3];
   344     dest[i * 3 + 0] = (x < 32768
   217     dest[i * 3 + 1] = (x < 32768) ? src[j * 3 + 1] : src[j * 3 + 4];
   345         || j + 1 >= src_width) ? src[j * 3 + 0] : src[j * 3 + 3];
   218     dest[i * 3 + 2] = (x < 32768) ? src[j * 3 + 2] : src[j * 3 + 5];
   346     dest[i * 3 + 1] = (x < 32768
   219 
   347         || j + 1 >= src_width) ? src[j * 3 + 1] : src[j * 3 + 4];
   220     acc += increment;
   348     dest[i * 3 + 2] = (x < 32768
   221   }
   349         || j + 1 >= src_width) ? src[j * 3 + 2] : src[j * 3 + 5];
   222 
   350 
   223   *accumulator = acc;
   351     acc += increment;
   224 }
   352   }
   225 #ifdef __SYMBIAN32__
   353 
   226 EXPORT_C
   354   *accumulator = acc;
   227 #endif
   355 }
   228 
   356 #ifdef __SYMBIAN32__
   229 
   357 EXPORT_C
   230 void
   358 #endif
   231 vs_scanline_resample_linear_RGB (uint8_t * dest, uint8_t * src, int n,
   359 
   232     int *accumulator, int increment)
   360 
   233 {
   361 void
   234   int acc = *accumulator;
   362 vs_scanline_resample_linear_RGB (uint8_t * dest, uint8_t * src, int src_width,
   235   int i;
   363     int n, int *accumulator, int increment)
   236   int j;
   364 {
   237   int x;
   365   int acc = *accumulator;
   238 
   366   int i;
   239   for (i = 0; i < n; i++) {
   367   int j;
   240     j = acc >> 16;
   368   int x;
   241     x = acc & 0xffff;
   369 
   242     dest[i * 3 + 0] = (src[j * 3 + 0] * (65536 - x) + src[j * 3 + 3] * x) >> 16;
   370   for (i = 0; i < n; i++) {
   243     dest[i * 3 + 1] = (src[j * 3 + 1] * (65536 - x) + src[j * 3 + 4] * x) >> 16;
   371     j = acc >> 16;
   244     dest[i * 3 + 2] = (src[j * 3 + 2] * (65536 - x) + src[j * 3 + 5] * x) >> 16;
   372     x = acc & 0xffff;
       
   373 
       
   374     if (j + 1 < src_width) {
       
   375       dest[i * 3 + 0] =
       
   376           (src[j * 3 + 0] * (65536 - x) + src[j * 3 + 3] * x) >> 16;
       
   377       dest[i * 3 + 1] =
       
   378           (src[j * 3 + 1] * (65536 - x) + src[j * 3 + 4] * x) >> 16;
       
   379       dest[i * 3 + 2] =
       
   380           (src[j * 3 + 2] * (65536 - x) + src[j * 3 + 5] * x) >> 16;
       
   381     } else {
       
   382       dest[i * 3 + 0] = src[j * 3 + 0];
       
   383       dest[i * 3 + 1] = src[j * 3 + 1];
       
   384       dest[i * 3 + 2] = src[j * 3 + 2];
       
   385     }
   245 
   386 
   246     acc += increment;
   387     acc += increment;
   247   }
   388   }
   248 
   389 
   249   *accumulator = acc;
   390   *accumulator = acc;
   263 }
   404 }
   264 
   405 
   265 
   406 
   266 /* YUYV */
   407 /* YUYV */
   267 
   408 
   268 /* n is the number of bi-pixels */
   409 /* n is the number of pixels */
   269 /* increment is per Y pixel */
   410 /* increment is per Y pixel */
   270 #ifdef __SYMBIAN32__
   411 #ifdef __SYMBIAN32__
   271 EXPORT_C
   412 EXPORT_C
   272 #endif
   413 #endif
   273 
   414 
   288 EXPORT_C
   429 EXPORT_C
   289 #endif
   430 #endif
   290 
   431 
   291 
   432 
   292 void
   433 void
   293 vs_scanline_resample_nearest_YUYV (uint8_t * dest, uint8_t * src, int n,
   434 vs_scanline_resample_nearest_YUYV (uint8_t * dest, uint8_t * src, int src_width,
   294     int *accumulator, int increment)
   435     int n, int *accumulator, int increment)
   295 {
   436 {
   296   int acc = *accumulator;
   437   int acc = *accumulator;
   297   int i;
   438   int i;
   298   int j;
   439   int j;
   299   int x;
   440   int x;
   300 
   441   int quads = (n + 1) / 2;
   301   for (i = 0; i < n; i++) {
   442 
   302     j = acc >> 16;
   443   for (i = 0; i < quads; i++) {
   303     x = acc & 0xffff;
   444     j = acc >> 16;
   304     dest[i * 4 + 0] = (x < 32768) ? src[j * 2 + 0] : src[j * 2 + 2];
   445     x = acc & 0xffff;
       
   446     dest[i * 4 + 0] = (x < 32768
       
   447         || j + 1 >= src_width) ? src[j * 2 + 0] : src[j * 2 + 2];
   305 
   448 
   306     j = acc >> 17;
   449     j = acc >> 17;
   307     x = acc & 0x1ffff;
   450     x = acc & 0x1ffff;
   308     dest[i * 4 + 1] = (x < 65536) ? src[j * 4 + 1] : src[j * 4 + 5];
   451     dest[i * 4 + 1] = (x < 65536
   309     dest[i * 4 + 3] = (x < 65536) ? src[j * 4 + 3] : src[j * 4 + 7];
   452         || 2 * (j + 2) >= src_width) ? src[j * 4 + 1] : src[j * 4 + 5];
   310 
   453 
   311     acc += increment;
   454     if (2 * i + 1 < n && 2 * (j + 1) < src_width)
   312 
   455       dest[i * 4 + 3] = (x < 65536
   313     j = acc >> 16;
   456           || 2 * (j + 3) >= src_width) ? src[j * 4 + 3] : src[j * 4 + 7];
   314     x = acc & 0xffff;
   457 
   315     dest[i * 4 + 2] = (x < 32768) ? src[j * 2 + 0] : src[j * 2 + 2];
   458     acc += increment;
   316     acc += increment;
   459 
   317   }
   460     j = acc >> 16;
   318 
   461     x = acc & 0xffff;
   319   *accumulator = acc;
   462 
   320 }
   463     if (2 * i + 1 < n && j < src_width) {
   321 #ifdef __SYMBIAN32__
   464       dest[i * 4 + 2] = (x < 32768
   322 EXPORT_C
   465           || j + 1 >= src_width) ? src[j * 2 + 0] : src[j * 2 + 2];
   323 #endif
   466       acc += increment;
   324 
   467     }
   325 
   468   }
   326 void
   469 
   327 vs_scanline_resample_linear_YUYV (uint8_t * dest, uint8_t * src, int n,
   470   *accumulator = acc;
   328     int *accumulator, int increment)
   471 }
   329 {
   472 #ifdef __SYMBIAN32__
   330   int acc = *accumulator;
   473 EXPORT_C
   331   int i;
   474 #endif
   332   int j;
   475 
   333   int x;
   476 
   334 
   477 void
   335   for (i = 0; i < n; i++) {
   478 vs_scanline_resample_linear_YUYV (uint8_t * dest, uint8_t * src, int src_width,
   336     j = acc >> 16;
   479     int n, int *accumulator, int increment)
   337     x = acc & 0xffff;
   480 {
   338     dest[i * 4 + 0] = (src[j * 2 + 0] * (65536 - x) + src[j * 2 + 2] * x) >> 16;
   481   int acc = *accumulator;
       
   482   int i;
       
   483   int j;
       
   484   int x;
       
   485   int quads = (n + 1) / 2;
       
   486 
       
   487   for (i = 0; i < quads; i++) {
       
   488     j = acc >> 16;
       
   489     x = acc & 0xffff;
       
   490 
       
   491     if (j + 1 < src_width)
       
   492       dest[i * 4 + 0] =
       
   493           (src[j * 2 + 0] * (65536 - x) + src[j * 2 + 2] * x) >> 16;
       
   494     else
       
   495       dest[i * 4 + 0] = src[j * 2 + 0];
   339 
   496 
   340     j = acc >> 17;
   497     j = acc >> 17;
   341     x = acc & 0x1ffff;
   498     x = acc & 0x1ffff;
   342     dest[i * 4 + 1] =
   499 
   343         (src[j * 4 + 1] * (131072 - x) + src[j * 4 + 5] * x) >> 17;
   500     if (2 * (j + 2) < src_width)
   344     dest[i * 4 + 3] =
   501       dest[i * 4 + 1] =
   345         (src[j * 4 + 3] * (131072 - x) + src[j * 4 + 7] * x) >> 17;
   502           (src[j * 4 + 1] * (131072 - x) + src[j * 4 + 5] * x) >> 17;
   346 
   503     else
   347     acc += increment;
   504       dest[i * 4 + 1] = src[j * 4 + 1];
   348 
   505 
   349     j = acc >> 16;
   506     if (2 * i + 1 < n && 2 * (j + 1) < src_width) {
   350     x = acc & 0xffff;
   507       if (2 * (j + 3) < src_width)
   351     dest[i * 4 + 2] = (src[j * 2 + 0] * (65536 - x) + src[j * 2 + 2] * x) >> 16;
   508         dest[i * 4 + 3] =
   352     acc += increment;
   509             (src[j * 4 + 3] * (131072 - x) + src[j * 4 + 7] * x) >> 17;
   353   }
   510       else
       
   511         dest[i * 4 + 3] = src[j * 4 + 3];
       
   512     }
       
   513 
       
   514     acc += increment;
       
   515 
       
   516     j = acc >> 16;
       
   517     x = acc & 0xffff;
       
   518 
       
   519     if (2 * i + 1 < n && j < src_width) {
       
   520       if (j + 1 < src_width)
       
   521         dest[i * 4 + 2] =
       
   522             (src[j * 2 + 0] * (65536 - x) + src[j * 2 + 2] * x) >> 16;
       
   523       else
       
   524         dest[i * 4 + 2] = src[j * 2 + 0];
       
   525       acc += increment;
       
   526     }
       
   527   }
       
   528 
   354 
   529 
   355   *accumulator = acc;
   530   *accumulator = acc;
   356 }
   531 }
   357 #ifdef __SYMBIAN32__
   532 #ifdef __SYMBIAN32__
   358 EXPORT_C
   533 EXPORT_C
   362 void
   537 void
   363 vs_scanline_merge_linear_YUYV (uint8_t * dest, uint8_t * src1, uint8_t * src2,
   538 vs_scanline_merge_linear_YUYV (uint8_t * dest, uint8_t * src1, uint8_t * src2,
   364     int n, int x)
   539     int n, int x)
   365 {
   540 {
   366   int i;
   541   int i;
   367 
   542   int quads = (n + 1) / 2;
   368   for (i = 0; i < n; i++) {
   543 
       
   544   for (i = 0; i < quads; i++) {
   369     dest[i * 4 + 0] =
   545     dest[i * 4 + 0] =
   370         (src1[i * 4 + 0] * (65536 - x) + src2[i * 4 + 0] * x) >> 16;
   546         (src1[i * 4 + 0] * (65536 - x) + src2[i * 4 + 0] * x) >> 16;
   371     dest[i * 4 + 1] =
   547     dest[i * 4 + 1] =
   372         (src1[i * 4 + 1] * (65536 - x) + src2[i * 4 + 1] * x) >> 16;
   548         (src1[i * 4 + 1] * (65536 - x) + src2[i * 4 + 1] * x) >> 16;
   373     dest[i * 4 + 2] =
   549 
   374         (src1[i * 4 + 2] * (65536 - x) + src2[i * 4 + 2] * x) >> 16;
   550     if (2 * i + 1 < n) {
   375     dest[i * 4 + 3] =
   551       dest[i * 4 + 2] =
   376         (src1[i * 4 + 3] * (65536 - x) + src2[i * 4 + 3] * x) >> 16;
   552           (src1[i * 4 + 2] * (65536 - x) + src2[i * 4 + 2] * x) >> 16;
       
   553       dest[i * 4 + 3] =
       
   554           (src1[i * 4 + 3] * (65536 - x) + src2[i * 4 + 3] * x) >> 16;
       
   555     }
   377   }
   556   }
   378 }
   557 }
   379 
   558 
   380 
   559 
   381 /* UYVY */
   560 /* UYVY */
   403 EXPORT_C
   582 EXPORT_C
   404 #endif
   583 #endif
   405 
   584 
   406 
   585 
   407 void
   586 void
   408 vs_scanline_resample_nearest_UYVY (uint8_t * dest, uint8_t * src, int n,
   587 vs_scanline_resample_nearest_UYVY (uint8_t * dest, uint8_t * src, int src_width,
   409     int *accumulator, int increment)
   588     int n, int *accumulator, int increment)
   410 {
   589 {
   411   int acc = *accumulator;
   590   int acc = *accumulator;
   412   int i;
   591   int i;
   413   int j;
   592   int j;
   414   int x;
   593   int x;
   415 
   594   int quads = (n + 1) / 2;
   416   for (i = 0; i < n; i++) {
   595 
   417     j = acc >> 16;
   596   for (i = 0; i < quads; i++) {
   418     x = acc & 0xffff;
   597     j = acc >> 16;
   419     dest[i * 4 + 1] = (x < 32768) ? src[j * 2 + 1] : src[j * 2 + 3];
   598     x = acc & 0xffff;
       
   599 
       
   600     dest[i * 4 + 1] = (x < 32768
       
   601         || j + 1 >= src_width) ? src[j * 2 + 1] : src[j * 2 + 3];
   420 
   602 
   421     j = acc >> 17;
   603     j = acc >> 17;
   422     x = acc & 0x1ffff;
   604     x = acc & 0x1ffff;
   423     dest[i * 4 + 0] = (x < 65536) ? src[j * 4 + 0] : src[j * 4 + 4];
   605 
   424     dest[i * 4 + 2] = (x < 65536) ? src[j * 4 + 2] : src[j * 4 + 6];
   606     dest[i * 4 + 0] = (x < 65536
   425 
   607         || 2 * (j + 2) >= src_width) ? src[j * 4 + 0] : src[j * 4 + 4];
   426     acc += increment;
   608 
   427 
   609     if (2 * i + 1 < n && 2 * (j + 1) < src_width)
   428     j = acc >> 16;
   610       dest[i * 4 + 2] = (x < 65536
   429     x = acc & 0xffff;
   611           || 2 * (j + 3) >= src_width) ? src[j * 4 + 2] : src[j * 4 + 6];
   430     dest[i * 4 + 3] = (x < 32768) ? src[j * 2 + 1] : src[j * 2 + 3];
   612 
   431     acc += increment;
   613     acc += increment;
   432   }
   614 
   433 
   615     j = acc >> 16;
   434   *accumulator = acc;
   616     x = acc & 0xffff;
   435 }
   617 
   436 #ifdef __SYMBIAN32__
   618     if (2 * i + 1 < n && j < src_width) {
   437 EXPORT_C
   619       dest[i * 4 + 3] = (x < 32768
   438 #endif
   620           || j + 1 >= src_width) ? src[j * 2 + 1] : src[j * 2 + 3];
   439 
   621       acc += increment;
   440 
   622     }
   441 void
   623   }
   442 vs_scanline_resample_linear_UYVY (uint8_t * dest, uint8_t * src, int n,
   624 
   443     int *accumulator, int increment)
   625   *accumulator = acc;
   444 {
   626 }
   445   int acc = *accumulator;
   627 #ifdef __SYMBIAN32__
   446   int i;
   628 EXPORT_C
   447   int j;
   629 #endif
   448   int x;
   630 
   449 
   631 
   450   for (i = 0; i < n; i++) {
   632 void
   451     j = acc >> 16;
   633 vs_scanline_resample_linear_UYVY (uint8_t * dest, uint8_t * src, int src_width,
   452     x = acc & 0xffff;
   634     int n, int *accumulator, int increment)
   453     dest[i * 4 + 1] = (src[j * 2 + 1] * (65536 - x) + src[j * 2 + 3] * x) >> 16;
   635 {
       
   636   int acc = *accumulator;
       
   637   int i;
       
   638   int j;
       
   639   int x;
       
   640   int quads = (n + 1) / 2;
       
   641 
       
   642   for (i = 0; i < quads; i++) {
       
   643     j = acc >> 16;
       
   644     x = acc & 0xffff;
       
   645 
       
   646     if (j + 1 < src_width)
       
   647       dest[i * 4 + 1] =
       
   648           (src[j * 2 + 1] * (65536 - x) + src[j * 2 + 3] * x) >> 16;
       
   649     else
       
   650       dest[i * 4 + 1] = src[j * 2 + 1];
   454 
   651 
   455     j = acc >> 17;
   652     j = acc >> 17;
   456     x = acc & 0x1ffff;
   653     x = acc & 0x1ffff;
       
   654     if (2 * (j + 2) < src_width)
       
   655       dest[i * 4 + 0] =
       
   656           (src[j * 4 + 0] * (131072 - x) + src[j * 4 + 4] * x) >> 17;
       
   657     else
       
   658       dest[i * 4 + 0] = src[j * 4 + 0];
       
   659 
       
   660     if (i * 2 + 1 < n && 2 * (j + 1) < src_width) {
       
   661       if (2 * (j + 3) < src_width)
       
   662         dest[i * 4 + 2] =
       
   663             (src[j * 4 + 2] * (131072 - x) + src[j * 4 + 6] * x) >> 17;
       
   664       else
       
   665         dest[i * 4 + 2] = src[j * 4 + 2];
       
   666     }
       
   667 
       
   668     acc += increment;
       
   669 
       
   670     j = acc >> 16;
       
   671     x = acc & 0xffff;
       
   672 
       
   673     if (2 * i + 1 < n && j < src_width) {
       
   674       if (j + 1 < src_width)
       
   675         dest[i * 4 + 3] =
       
   676             (src[j * 2 + 1] * (65536 - x) + src[j * 2 + 3] * x) >> 16;
       
   677       else
       
   678         dest[i * 4 + 3] = src[j * 2 + 1];
       
   679       acc += increment;
       
   680     }
       
   681   }
       
   682 
       
   683   *accumulator = acc;
       
   684 }
       
   685 #ifdef __SYMBIAN32__
       
   686 EXPORT_C
       
   687 #endif
       
   688 
       
   689 
       
   690 void
       
   691 vs_scanline_merge_linear_UYVY (uint8_t * dest, uint8_t * src1,
       
   692     uint8_t * src2, int n, int x)
       
   693 {
       
   694   int i;
       
   695   int quads = (n + 1) / 2;
       
   696 
       
   697   for (i = 0; i < quads; i++) {
   457     dest[i * 4 + 0] =
   698     dest[i * 4 + 0] =
   458         (src[j * 4 + 0] * (131072 - x) + src[j * 4 + 4] * x) >> 17;
   699         (src1[i * 4 + 0] * (65536 - x) + src2[i * 4 + 0] * x) >> 16;
   459     dest[i * 4 + 2] =
   700     dest[i * 4 + 1] =
   460         (src[j * 4 + 2] * (131072 - x) + src[j * 4 + 6] * x) >> 17;
   701         (src1[i * 4 + 1] * (65536 - x) + src2[i * 4 + 1] * x) >> 16;
   461 
   702 
   462     acc += increment;
   703     if (2 * i + 1 < n) {
   463 
   704       dest[i * 4 + 2] =
   464     j = acc >> 16;
   705           (src1[i * 4 + 2] * (65536 - x) + src2[i * 4 + 2] * x) >> 16;
   465     x = acc & 0xffff;
   706       dest[i * 4 + 3] =
   466     dest[i * 4 + 3] = (src[j * 2 + 1] * (65536 - x) + src[j * 2 + 3] * x) >> 16;
   707           (src1[i * 4 + 3] * (65536 - x) + src2[i * 4 + 3] * x) >> 16;
   467     acc += increment;
   708     }
   468   }
   709   }
   469 
       
   470   *accumulator = acc;
       
   471 }
       
   472 #ifdef __SYMBIAN32__
       
   473 EXPORT_C
       
   474 #endif
       
   475 
       
   476 
       
   477 void
       
   478 vs_scanline_merge_linear_UYVY (uint8_t * dest, uint8_t * src1, uint8_t * src2,
       
   479     int n, int x)
       
   480 {
       
   481   uint32_t value = x >> 8;
       
   482 
       
   483   oil_merge_linear_argb ((uint32_t *) dest, (uint32_t *) src1,
       
   484       (uint32_t *) src2, &value, n);
       
   485 }
   710 }
   486 
   711 
   487 
   712 
   488 /* RGB565 */
   713 /* RGB565 */
   489 
   714 
   517 EXPORT_C
   742 EXPORT_C
   518 #endif
   743 #endif
   519 
   744 
   520 
   745 
   521 void
   746 void
   522 vs_scanline_resample_nearest_RGB565 (uint8_t * dest_u8, uint8_t * src_u8, int n,
   747 vs_scanline_resample_nearest_RGB565 (uint8_t * dest_u8, uint8_t * src_u8,
   523     int *accumulator, int increment)
   748     int src_width, int n, int *accumulator, int increment)
   524 {
   749 {
   525   uint16_t *dest = (uint16_t *) dest_u8;
   750   uint16_t *dest = (uint16_t *) dest_u8;
   526   uint16_t *src = (uint16_t *) src_u8;
   751   uint16_t *src = (uint16_t *) src_u8;
   527   int acc = *accumulator;
   752   int acc = *accumulator;
   528   int i;
   753   int i;
   530   int x;
   755   int x;
   531 
   756 
   532   for (i = 0; i < n; i++) {
   757   for (i = 0; i < n; i++) {
   533     j = acc >> 16;
   758     j = acc >> 16;
   534     x = acc & 0xffff;
   759     x = acc & 0xffff;
   535     dest[i] = (x < 32768) ? src[j] : src[j + 1];
   760     dest[i] = (x < 32768 || j + 1 >= src_width) ? src[j] : src[j + 1];
   536 
   761 
   537     acc += increment;
   762     acc += increment;
   538   }
   763   }
   539 
   764 
   540   *accumulator = acc;
   765   *accumulator = acc;
   541 }
   766 }
   542 #ifdef __SYMBIAN32__
   767 #ifdef __SYMBIAN32__
   543 EXPORT_C
   768 EXPORT_C
   544 #endif
   769 #endif
   545 
   770 
   546 
   771 
   547 void
   772 void
   548 vs_scanline_resample_linear_RGB565 (uint8_t * dest_u8, uint8_t * src_u8, int n,
   773 vs_scanline_resample_linear_RGB565 (uint8_t * dest_u8, uint8_t * src_u8,
   549     int *accumulator, int increment)
   774     int src_width, int n, int *accumulator, int increment)
   550 {
   775 {
   551   uint16_t *dest = (uint16_t *) dest_u8;
   776   uint16_t *dest = (uint16_t *) dest_u8;
   552   uint16_t *src = (uint16_t *) src_u8;
   777   uint16_t *src = (uint16_t *) src_u8;
   553   int acc = *accumulator;
   778   int acc = *accumulator;
   554   int i;
   779   int i;
   556   int x;
   781   int x;
   557 
   782 
   558   for (i = 0; i < n; i++) {
   783   for (i = 0; i < n; i++) {
   559     j = acc >> 16;
   784     j = acc >> 16;
   560     x = acc & 0xffff;
   785     x = acc & 0xffff;
   561     dest[i] = RGB565 (
   786 
   562         (RGB565_R (src[j]) * (65536 - x) + RGB565_R (src[j + 1]) * x) >> 16,
   787     if (j + 1 < src_width) {
   563         (RGB565_G (src[j]) * (65536 - x) + RGB565_G (src[j + 1]) * x) >> 16,
   788       dest[i] = RGB565 (
   564         (RGB565_B (src[j]) * (65536 - x) + RGB565_B (src[j + 1]) * x) >> 16);
   789           (RGB565_R (src[j]) * (65536 - x) + RGB565_R (src[j + 1]) * x) >> 16,
       
   790           (RGB565_G (src[j]) * (65536 - x) + RGB565_G (src[j + 1]) * x) >> 16,
       
   791           (RGB565_B (src[j]) * (65536 - x) + RGB565_B (src[j + 1]) * x) >> 16);
       
   792     } else {
       
   793       dest[i] = RGB565 (RGB565_R (src[j]),
       
   794           RGB565_G (src[j]), RGB565_B (src[j]));
       
   795     }
   565 
   796 
   566     acc += increment;
   797     acc += increment;
   567   }
   798   }
   568 
   799 
   569   *accumulator = acc;
   800   *accumulator = acc;
   623 EXPORT_C
   854 EXPORT_C
   624 #endif
   855 #endif
   625 
   856 
   626 
   857 
   627 void
   858 void
   628 vs_scanline_resample_nearest_RGB555 (uint8_t * dest_u8, uint8_t * src_u8, int n,
   859 vs_scanline_resample_nearest_RGB555 (uint8_t * dest_u8, uint8_t * src_u8,
   629     int *accumulator, int increment)
   860     int src_width, int n, int *accumulator, int increment)
   630 {
   861 {
   631   uint16_t *dest = (uint16_t *) dest_u8;
   862   uint16_t *dest = (uint16_t *) dest_u8;
   632   uint16_t *src = (uint16_t *) src_u8;
   863   uint16_t *src = (uint16_t *) src_u8;
   633   int acc = *accumulator;
   864   int acc = *accumulator;
   634   int i;
   865   int i;
   636   int x;
   867   int x;
   637 
   868 
   638   for (i = 0; i < n; i++) {
   869   for (i = 0; i < n; i++) {
   639     j = acc >> 16;
   870     j = acc >> 16;
   640     x = acc & 0xffff;
   871     x = acc & 0xffff;
   641     dest[i] = (x < 32768) ? src[j] : src[j + 1];
   872     dest[i] = (x < 32768 || j + 1 >= src_width) ? src[j] : src[j + 1];
   642 
   873 
   643     acc += increment;
   874     acc += increment;
   644   }
   875   }
   645 
   876 
   646   *accumulator = acc;
   877   *accumulator = acc;
   647 }
   878 }
   648 #ifdef __SYMBIAN32__
   879 #ifdef __SYMBIAN32__
   649 EXPORT_C
   880 EXPORT_C
   650 #endif
   881 #endif
   651 
   882 
   652 
   883 
   653 void
   884 void
   654 vs_scanline_resample_linear_RGB555 (uint8_t * dest_u8, uint8_t * src_u8, int n,
   885 vs_scanline_resample_linear_RGB555 (uint8_t * dest_u8, uint8_t * src_u8,
   655     int *accumulator, int increment)
   886     int src_width, int n, int *accumulator, int increment)
   656 {
   887 {
   657   uint16_t *dest = (uint16_t *) dest_u8;
   888   uint16_t *dest = (uint16_t *) dest_u8;
   658   uint16_t *src = (uint16_t *) src_u8;
   889   uint16_t *src = (uint16_t *) src_u8;
   659   int acc = *accumulator;
   890   int acc = *accumulator;
   660   int i;
   891   int i;
   662   int x;
   893   int x;
   663 
   894 
   664   for (i = 0; i < n; i++) {
   895   for (i = 0; i < n; i++) {
   665     j = acc >> 16;
   896     j = acc >> 16;
   666     x = acc & 0xffff;
   897     x = acc & 0xffff;
   667     dest[i] = RGB555 (
   898 
   668         (RGB555_R (src[j]) * (65536 - x) + RGB555_R (src[j + 1]) * x) >> 16,
   899     if (j + 1 < src_width) {
   669         (RGB555_G (src[j]) * (65536 - x) + RGB555_G (src[j + 1]) * x) >> 16,
   900       dest[i] = RGB555 (
   670         (RGB555_B (src[j]) * (65536 - x) + RGB555_B (src[j + 1]) * x) >> 16);
   901           (RGB555_R (src[j]) * (65536 - x) + RGB555_R (src[j + 1]) * x) >> 16,
       
   902           (RGB555_G (src[j]) * (65536 - x) + RGB555_G (src[j + 1]) * x) >> 16,
       
   903           (RGB555_B (src[j]) * (65536 - x) + RGB555_B (src[j + 1]) * x) >> 16);
       
   904     } else {
       
   905       dest[i] = RGB555 (RGB555_R (src[j]),
       
   906           RGB555_G (src[j]), RGB555_B (src[j]));
       
   907     }
   671 
   908 
   672     acc += increment;
   909     acc += increment;
   673   }
   910   }
   674 
   911 
   675   *accumulator = acc;
   912   *accumulator = acc;