1 /* 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include <stdlib.h> 12 13 #include "vp9/common/vp9_textblit.h" 14 15 static const int font[] = { 16 0x0, 0x5C00, 0x8020, 0xAFABEA, 0xD7EC0, 0x1111111, 0x1855740, 0x18000, 17 0x45C0, 0x74400, 0x51140, 0x23880, 0xC4000, 0x21080, 0x80000, 0x111110, 18 0xE9D72E, 0x87E40, 0x12AD732, 0xAAD62A, 0x4F94C4, 0x4D6B7, 0x456AA, 19 0x3E8423, 0xAAD6AA, 0xAAD6A2, 0x2800, 0x2A00, 0x8A880, 0x52940, 0x22A20, 20 0x15422, 0x6AD62E, 0x1E4A53E, 0xAAD6BF, 0x8C62E, 0xE8C63F, 0x118D6BF, 21 0x1094BF, 0xCAC62E, 0x1F2109F, 0x118FE31, 0xF8C628, 0x8A89F, 0x108421F, 22 0x1F1105F, 0x1F4105F, 0xE8C62E, 0x2294BF, 0x164C62E, 0x12694BF, 0x8AD6A2, 23 0x10FC21, 0x1F8421F, 0x744107, 0xF8220F, 0x1151151, 0x117041, 0x119D731, 24 0x47E0, 0x1041041, 0xFC400, 0x10440, 0x1084210, 0x820 25 }; 26 27 static void plot(int x, int y, unsigned char *image, int pitch) { 28 image[x + y * pitch] ^= 255; 29 } 30 31 void vp9_blit_text(const char *msg, unsigned char *address, const int pitch) { 32 int letter_bitmap; 33 unsigned char *output_pos = address; 34 int colpos = 0; 35 36 while (msg[colpos] != 0) { 37 char letter = msg[colpos]; 38 int fontcol, fontrow; 39 40 if (letter <= 'Z' && letter >= ' ') 41 letter_bitmap = font[letter - ' ']; 42 else if (letter <= 'z' && letter >= 'a') 43 letter_bitmap = font[letter - 'a' + 'A' - ' ']; 44 else 45 letter_bitmap = font[0]; 46 47 for (fontcol = 6; fontcol >= 0; fontcol--) 48 for (fontrow = 0; fontrow < 5; fontrow++) 49 output_pos[fontrow * pitch + fontcol] = 50 ((letter_bitmap >> (fontcol * 5)) & (1 << fontrow) ? 255 : 0); 51 52 output_pos += 7; 53 colpos++; 54 } 55 } 56 57 58 59 /* Bresenham line algorithm */ 60 void vp9_blit_line(int x0, int x1, int y0, int y1, unsigned char *image, 61 int pitch) { 62 int steep = abs(y1 - y0) > abs(x1 - x0); 63 int deltax, deltay; 64 int error, ystep, y, x; 65 66 if (steep) { 67 int t; 68 t = x0; 69 x0 = y0; 70 y0 = t; 71 72 t = x1; 73 x1 = y1; 74 y1 = t; 75 } 76 77 if (x0 > x1) { 78 int t; 79 t = x0; 80 x0 = x1; 81 x1 = t; 82 83 t = y0; 84 y0 = y1; 85 y1 = t; 86 } 87 88 deltax = x1 - x0; 89 deltay = abs(y1 - y0); 90 error = deltax / 2; 91 92 y = y0; 93 94 if (y0 < y1) 95 ystep = 1; 96 else 97 ystep = -1; 98 99 if (steep) { 100 for (x = x0; x <= x1; x++) { 101 plot(y, x, image, pitch); 102 103 error = error - deltay; 104 if (error < 0) { 105 y = y + ystep; 106 error = error + deltax; 107 } 108 } 109 } else { 110 for (x = x0; x <= x1; x++) { 111 plot(x, y, image, pitch); 112 113 error = error - deltay; 114 if (error < 0) { 115 y = y + ystep; 116 error = error + deltax; 117 } 118 } 119 } 120 } 121