2015-07-19 54 views
0

我在玄武岩平台上使用Pebble SDK 3.0编写Pebble Time Watch应用程序,需要文本显示为颠倒。翻转卵石屏幕问题

的逻辑是: -

  1. 写入屏幕
  2. 捕获屏幕缓冲器
  3. 翻转屏幕缓冲器(使用常规flipHV,见下文)
  4. 推出缓冲器。

经过大量的实验后,我已经在时尚之后工作,但(黑色)文本有什么似乎是随机的垂直白线通过它(见下图),我怀疑是要做的事情随着位移动。

Upsidedown text

我使用的子程序: -

void flipHV(GBitmap *bitMap) { 
    GRect fbb = gbitmap_get_bounds(bitMap); 
    int Width = 72; // fbb.size.w; 
    int Height = 84; // fbb.size.h; 
    uint32_t *pBase = (uint32_t *)gbitmap_get_data(bitMap); 
    uint32_t *pTopRemainingPixel = pBase; 
    uint32_t *pBottomRemainingPixel = pBase + (Height * Width); 

    while (pTopRemainingPixel < pBottomRemainingPixel) { 
    uint32_t TopPixel = *pTopRemainingPixel; 
    uint32_t BottomPixel = *pBottomRemainingPixel; 
    TopPixel = (TopPixel << 16) | (TopPixel >> 16); 
    *pBottomRemainingPixel = TopPixel; 
    BottomPixel = (BottomPixel << 16) | (BottomPixel >> 16); 
    *pTopRemainingPixel = BottomPixel; 

    pTopRemainingPixel++; 
    pBottomRemainingPixel--; 
    } 
} 

,其目的是,虽然屏幕缓冲区以第一像素,并与最后一个,第二个和交换工作交换它与第二个最后一个等等等

因为每个32位“字节”保存2个像素,我也需要通过16位旋转它。

我怀疑这是问题所在。

有人可以看看我的代码,看看他们是否可以看到发生了什么问题,并把我的权利。我应该说我既是C和Pebble SDK的新手,也请给孩子解释一切!

回答

1

事实证明,我需要用uint8_t替换所有的uint32_t,并消除这种转换。

2

你的作业就像

TopPixel = (TopPixel << 16) | (TopPixel >> 16) 

交换像素成对

+--+--+ +--+--+ 
|ab|cd| => |cd|ab| 
+--+--+ +--+--+ 

你想,而不是什么是一个完整的交换:

+--+--+ +--+--+ 
|ab|cd| => |dc|ba| 
+--+--+ +--+--+ 

,可以与更多位来实现 - 弄脏,例如

TopPixel = ((TopPixel << 24)    | // move d from 0..7 to 24..31 
      ((TopPixel << 8) & 0x00ff0000) | // move c from 8..15 to 16..23 
      ((TopPixel >> 8) & 0x0000ff00) | // move b from 16..23 to 8..15 
      ((TopPixel >> 24)    | // move a from 24..31 to 0..7 

或 - 的方式更具可读性 - 通过使用GColor8代替uint32_t和循环每个像素的基础上(!):

// only loop to half of the distance to avoid swapping twice 
for (int16_t y = 0; y <= max_y/2; y++) { 
    for (int16_t x = 0; x <= max_x/2; x++) { 
    GColor8 *value_1 = gbitmap_get_bytes_per_row(bmp) * y + x; 
    GColor8 *value_2 = gbitmap_get_bytes_per_row(bmp) * (max_y - y) + (max_x - x); 
    // swapping the two pixel values, could be simplified with a SWAP(a,b) macro 
    GColor8 tmp = *value_1; 
    *value_1 = *value_2; 
    *value_2 = tmp; 
    } 
} 

免责声明:我还没有编译此代码。可能还需要将gbitmap_get_byes_per_row()...表达式转换为GColor8*。如果你看到这是一个性能瓶颈,整个指针算术可以被调整。

+0

谢谢,我会试试看。 –

+0

我已经通过将所有内容声明为uint8_t来解决此问题。但是,主要的问题是图像宽度和图像宽度之间的字节差异(对于除GBitmapFormat8Bit以外的任何其他内容)并不相同,并且需要额外的处理来考虑未使用的字节。答案可以在http://forums.getpebble.com/discussion/27862/puzzling-gbitmap-get-data-behaviour#latest找到。 –