예제 #1
0
template <typename T> TomoImage<T>::TomoImage(const char* filename)
{
  unsigned char header[16];
  std::ifstream fp;

  /* open file and check for errors */
  fp.open(filename, std::ios::in | std::ios::binary);
  if (fp.bad() || fp.fail())
  {
    POST_ERR("Error opening file '" << filename << "' -- b,f: " << fp.bad() << "," << fp.fail());
    exit(-1);
  }

  /* read header and check for errors */
  fp.read((char*)(&header), sizeof(header));
  if (fp.eof())
  {
    POST_ERR("Early EOF on file '" << filename << "'");
    fp.close();
    exit(-1);
  }
  // should really check for other errors here...

  /* put msl and lsb together to get true values */
  this->cols = (header[2] << 8) | header[3];
  this->rows = (header[4] << 8) | header[5];
  this->positions = (header[6] << 8) | header[7];
  this->colors = (header[8] << 8) | header[9];
  this->size = this->cols*this->rows*this->colors*this->positions;

  this->image = new T[this->size];

  /* read image data and check for errors */
  fp.read((char*)(this->image), this->size);
  // check for errors here?

  fp.close();
  // check for close errors?
} 
예제 #2
0
POST_ERROR Post_set_next_destination_buffer(unsigned int AddrY, unsigned int AddrCb, unsigned int AddrCr)
{
    POST_ERROR error = POST_SUCCESS;

    POST_MSG((_T("[POST]++Post_set_next_destination_buffer(0x%08x, 0x%08x, 0x%08x)\n\r"), AddrY, AddrCb, AddrCr));

    if (g_PostConfig.DstType == POST_DST_FIFO_RGB888 || g_PostConfig.DstType == POST_DST_FIFO_YUV444)
    {
        POST_ERR((_T("[POST:ERR] Post_set_next_destination_buffer() : FIFO Mode does Not use DMA\n\r")));
        error = POST_ERROR_ILLEGAL_PARAMETER;
    }
    else
    {
        error = Post_set_dma_address(POST_NEXT_DST_ADDRESS, AddrY, AddrCb, AddrCr);
    }

    POST_MSG((_T("[POST]--Post_set_next_destination_buffer() : %d\n\r"), error));

    return error;
}
예제 #3
0
POST_ERROR Post_initialize_register_address(void *pPostReg)
{
    POST_ERROR error = POST_SUCCESS;

    POST_MSG((_T("[POST]++Post_initialize_register_address(0x%08x)\n\r"), pPostReg));

    if (pPostReg == NULL)
    {
        POST_ERR((_T("[POST:ERR] Post_initialize_register_address() : NULL pointer parameter\n\r")));
        error = POST_ERROR_NULL_PARAMETER;
    }
    else
    {
        g_pPostReg = (S3C6410_POST_REG *)pPostReg;
        POST_INF((_T("[POST:INF] g_pPostReg = 0x%08x\n\r"), g_pPostReg));
    }

    memset((void *)(&g_PostConfig), 0x0, sizeof(tPostConfig));

    POST_MSG((_T("[POST]--Post_initialize_register_address() : %d\n\r"), error));

    return error;
}
예제 #4
0
static POST_ERROR Post_get_prescaler_shiftvalue(unsigned int *MainShift, unsigned int SrcValue, unsigned int DstValue )
{
    POST_ERROR error = POST_SUCCESS;

    if (SrcValue >= 64*DstValue)
    {
        POST_ERR((_T("[POST:ERR] Post_get_prescaler_shiftvalue() : Out of Range\r\n")));
        error = POST_ERROR_PRESCALER_OUT_OF_SCALE_RANGE;
    }
    else if (SrcValue >= 32*DstValue)
    {
        *MainShift = 5;
    }
    else if (SrcValue >= 16*DstValue)
    {
        *MainShift = 4;
    }
    else if (SrcValue >= 8*DstValue)
    {
        *MainShift = 3;
    }
    else if (SrcValue >= 4*DstValue)
    {
        *MainShift = 2;
    }
    else if (SrcValue >= 2*DstValue)
    {
        *MainShift = 1;
    }
    else
    {
        *MainShift = 0;
    }

    return error;
}
예제 #5
0
static POST_ERROR Post_set_dma_address(POST_DMA_ADDRESS DMA, unsigned int AddrY, unsigned int AddrCb, unsigned int AddrCr)
{
    POST_ERROR error = POST_SUCCESS;

    unsigned int AddrStart_Y=0, AddrStart_Cb=0, AddrStart_Cr=0;
    unsigned int AddrEnd_Y=0, AddrEnd_Cb=0, AddrEnd_Cr=0;
    unsigned int Offset_Y=0, Offset_Cb=0, Offset_Cr=0;

    POST_MSG((_T("[POST]++Post_set_dma_address(%d, 0x%08x, 0x%08x, 0x%08x)\n\r"), DMA, AddrY, AddrCb, AddrCr));

    if (DMA == POST_SRC_ADDRESS || DMA == POST_NEXT_SRC_ADDRESS)
    {
        switch(g_PostConfig.SrcType)
        {
        case POST_SRC_RGB16:
        case POST_SRC_YUV422_YCBYCR:
        case POST_SRC_YUV422_CBYCRY:
        case POST_SRC_YUV422_YCRYCB:
        case POST_SRC_YUV422_CRYCBY:
            Offset_Y = (g_PostConfig.SrcBaseWidth - g_PostConfig.SrcWidth)*2;
            AddrStart_Y = AddrY+(g_PostConfig.SrcBaseWidth*g_PostConfig.SrcOffsetY)*2 + g_PostConfig.SrcOffsetX*2;
            AddrEnd_Y = AddrStart_Y+(g_PostConfig.SrcWidth*g_PostConfig.SrcHeight)*2 + (g_PostConfig.SrcHeight-1)*Offset_Y;
            break;
        case POST_SRC_RGB24:
            Offset_Y = (g_PostConfig.SrcBaseWidth - g_PostConfig.SrcWidth)*4;
            AddrStart_Y = AddrY+(g_PostConfig.SrcBaseWidth*g_PostConfig.SrcOffsetY)*4 + g_PostConfig.SrcOffsetX*4;
            AddrEnd_Y = AddrStart_Y+(g_PostConfig.SrcWidth*g_PostConfig.SrcHeight)*4 + (g_PostConfig.SrcHeight-1)*Offset_Y;
            break;
        case POST_SRC_YUV420:
            Offset_Y = (g_PostConfig.SrcBaseWidth - g_PostConfig.SrcWidth);
            Offset_Cb = Offset_Y/2;
            Offset_Cr = Offset_Y/2;
            AddrStart_Y = AddrY+(g_PostConfig.SrcBaseWidth*g_PostConfig.SrcOffsetY) + g_PostConfig.SrcOffsetX;
            AddrEnd_Y = AddrStart_Y+(g_PostConfig.SrcWidth*g_PostConfig.SrcHeight) + (g_PostConfig.SrcHeight-1)*Offset_Y;
            AddrStart_Cb = AddrCb+(g_PostConfig.SrcBaseWidth/2)*(g_PostConfig.SrcOffsetY/2) + g_PostConfig.SrcOffsetX/2;
            AddrEnd_Cb = AddrStart_Cb+(g_PostConfig.SrcWidth/2)*(g_PostConfig.SrcHeight/2) + (g_PostConfig.SrcHeight/2-1)*Offset_Cb;
            AddrStart_Cr = AddrCr+(g_PostConfig.SrcBaseWidth/2)*(g_PostConfig.SrcOffsetY/2) + g_PostConfig.SrcOffsetX/2;
            AddrEnd_Cr = AddrStart_Cr+(g_PostConfig.SrcWidth/2)*(g_PostConfig.SrcHeight/2) + (g_PostConfig.SrcHeight/2-1)*Offset_Cr;
            break;
        default:
            POST_ERR((_T("[POST:ERR] Post_set_dma_address() : Unknown Format %d\r\n"), g_PostConfig.SrcType));
            return POST_ERROR_ILLEGAL_PARAMETER;
        }
    }
    else if (DMA == POST_DST_ADDRESS || DMA == POST_NEXT_DST_ADDRESS)
    {
        switch(g_PostConfig.DstType)
        {
        case POST_DST_RGB16:
        case POST_DST_YUV422_YCBYCR:
        case POST_DST_YUV422_CBYCRY:
        case POST_DST_YUV422_YCRYCB:
        case POST_DST_YUV422_CRYCBY:
            Offset_Y = (g_PostConfig.DstBaseWidth - g_PostConfig.DstWidth)*2;
            AddrStart_Y = AddrY+(g_PostConfig.DstBaseWidth*g_PostConfig.DstOffsetY)*2 + g_PostConfig.DstOffsetX*2;
            AddrEnd_Y = AddrStart_Y+(g_PostConfig.DstWidth*g_PostConfig.DstHeight)*2 + (g_PostConfig.DstHeight-1)*Offset_Y;
            break;
        case POST_DST_RGB24:
            Offset_Y = (g_PostConfig.DstBaseWidth - g_PostConfig.DstWidth)*4;
            AddrStart_Y = AddrY+(g_PostConfig.DstBaseWidth*g_PostConfig.DstOffsetY)*4 + g_PostConfig.DstOffsetX*4;
            AddrEnd_Y = AddrStart_Y+(g_PostConfig.DstWidth*g_PostConfig.DstHeight)*4 + (g_PostConfig.DstHeight-1)*Offset_Y;
            break;
        case POST_DST_YUV420:
            Offset_Y = (g_PostConfig.DstBaseWidth - g_PostConfig.DstWidth);
            Offset_Cb = Offset_Y/2;
            Offset_Cr = Offset_Y/2;
            AddrStart_Y = AddrY+(g_PostConfig.DstBaseWidth*g_PostConfig.DstOffsetY) + g_PostConfig.DstOffsetX;
            AddrEnd_Y = AddrStart_Y+(g_PostConfig.DstWidth*g_PostConfig.DstHeight) + (g_PostConfig.DstHeight-1)*Offset_Y;
            AddrStart_Cb = AddrCb+(g_PostConfig.DstBaseWidth/2)*(g_PostConfig.DstOffsetY/2) + g_PostConfig.DstOffsetX/2;
            AddrEnd_Cb = AddrStart_Cb+(g_PostConfig.DstWidth/2)*(g_PostConfig.DstHeight/2) + (g_PostConfig.DstHeight/2-1)*Offset_Cb;
            AddrStart_Cr = AddrCr+(g_PostConfig.DstBaseWidth/2)*(g_PostConfig.DstOffsetY/2) + g_PostConfig.DstOffsetX/2;
            AddrEnd_Cr = AddrStart_Cr+(g_PostConfig.DstWidth/2)*(g_PostConfig.DstHeight/2) + (g_PostConfig.DstHeight/2-1)*Offset_Cr;
            break;
        default:
            POST_ERR((_T("[POST:ERR] Post_set_dma_address() : Unknown Format %d\r\n"), g_PostConfig.DstType));
            return POST_ERROR_ILLEGAL_PARAMETER;
        }
    }
    else
    {
        POST_ERR((_T("[POST:ERR] Post_set_dma_address() : Unknown DMA address %d\r\n"), DMA));
        return POST_ERROR_ILLEGAL_PARAMETER;
    }

    switch(DMA)
    {
    case POST_SRC_ADDRESS:
        g_pPostReg->ADDRStart_Y = AddrStart_Y;
        g_pPostReg->ADDREnd_Y = AddrEnd_Y;
        g_pPostReg->ADDRStart_Cb = AddrStart_Cb;
        g_pPostReg->ADDREnd_Cb = AddrEnd_Cb;
        g_pPostReg->ADDRStart_Cr = AddrStart_Cr;
        g_pPostReg->ADDREnd_Cr = AddrEnd_Cr;
        g_pPostReg->Offset_Y= Offset_Y;
        g_pPostReg->Offset_Cb= Offset_Cb;
        g_pPostReg->Offset_Cr= Offset_Cr;
        break;
    case POST_NEXT_SRC_ADDRESS:
        g_pPostReg->MODE_2 |= ADDR_CHANGE_DISABLE;    // To prevent address from changing still in register setting
        g_pPostReg->NxtADDRStart_Y = AddrStart_Y;
        g_pPostReg->NxtADDREnd_Y = AddrEnd_Y;
        g_pPostReg->NxtADDRStart_Cb = AddrStart_Cb;
        g_pPostReg->NxtADDREnd_Cb = AddrEnd_Cb;
        g_pPostReg->NxtADDRStart_Cr = AddrStart_Cr;
        g_pPostReg->NxtADDREnd_Cr = AddrEnd_Cr;
        g_pPostReg->MODE_2 &= ~ADDR_CHANGE_DISABLE;    // Now, address can change
        break;
    case POST_DST_ADDRESS:
        g_pPostReg->ADDRStart_RGB = AddrStart_Y;
        g_pPostReg->ADDREnd_RGB = AddrEnd_Y;
        g_pPostReg->ADDRStart_oCb = AddrStart_Cb;
        g_pPostReg->ADDREnd_oCb = AddrEnd_Cb;
        g_pPostReg->ADDRStart_oCr = AddrStart_Cr;
        g_pPostReg->ADDREnd_oCr = AddrEnd_Cr;
        g_pPostReg->Offset_RGB= Offset_Y;
        g_pPostReg->Offset_oCb= Offset_Cb;
        g_pPostReg->Offset_oCr= Offset_Cr;
        break;
    case POST_NEXT_DST_ADDRESS:
        g_pPostReg->MODE_2 |= ADDR_CHANGE_DISABLE;    // To prevent address from changing still in register setting
        g_pPostReg->NxtADDRStart_RGB = AddrStart_Y;
        g_pPostReg->NxtADDREnd_RGB = AddrEnd_Y;
        g_pPostReg->NxtADDRStart_oCb = AddrStart_Cb;
        g_pPostReg->NxtADDREnd_oCb = AddrEnd_Cb;
        g_pPostReg->NxtADDRStart_oCr = AddrStart_Cr;
        g_pPostReg->NxtADDREnd_oCr = AddrEnd_Cr;
        g_pPostReg->MODE_2 &= ~ADDR_CHANGE_DISABLE;    // Now, address can change
        break;
    default:
        return POST_ERROR_ILLEGAL_PARAMETER;
    }

    POST_MSG((_T("[POST]--Post_set_dma_address() : %d\n\r"), error));

    return error;
}
예제 #6
0
static POST_ERROR Post_set_mode(POST_OP_MODE Mode, POST_SCAN_MODE Scan, POST_SRC_TYPE SrcType, POST_DST_TYPE DstType)
{
    POST_ERROR error = POST_SUCCESS;

    POST_MSG((_T("[POST]++Post_set_mode(%d, %d, %d, %d)\n\r"), Mode, Scan, SrcType, DstType));

    g_PostConfig.Mode = Mode;
    g_PostConfig.Scan = Scan;
    g_PostConfig.SrcType = SrcType;
    g_PostConfig.DstType = DstType;

    // For some application PostProcessor May be need to faster CLK
    // setting for faster CLK : CLKVALUP_ALWAYS | CLKVAL_F(0) | CLKDIR_DIRECT | CLKSEL_F_HCLK | CSC_R2Y_WIDE | CSC_Y2R_WIDE | IRQ_LEVEL
    g_pPostReg->MODE = CLKVALUP_ALWAYS | CLKVAL_F(2) | CLKDIR_DIVIDED | CLKSEL_F_HCLK | CSC_R2Y_NARROW | CSC_Y2R_NARROW | IRQ_LEVEL;    // Clock = HCLK/2

    if (g_PostConfig.bIntEnable)
    {
        g_pPostReg->MODE |= POSTINT_ENABLE;
    }

    if (Mode == POST_PER_FRAME_MODE)
    {
        g_pPostReg->MODE |= AUTOLOAD_DISABLE;
    }
    else if (Mode == POST_FREE_RUN_MODE)
    {
        g_pPostReg->MODE |= AUTOLOAD_ENABLE;
    }
    else
    {
        POST_ERR((_T("[POST:ERR] Post_set_mode() : Unknown Operation Mode %d)\n\r"), Mode));
        return POST_ERROR_ILLEGAL_PARAMETER;
    }

    if (Scan == POST_PROGRESSIVE)
    {
        g_pPostReg->MODE |= PROGRESSIVE;
    }
    else if (Mode == POST_INTERLACE)
    {
        g_pPostReg->MODE |= INTERLACE;
    }
    else
    {
        POST_ERR((_T("[POST:ERR] Post_set_mode() : Unknown Scan Mode %d)\n\r"), Scan));
        return POST_ERROR_ILLEGAL_PARAMETER;
    }

    switch(SrcType)
    {
    case POST_SRC_RGB16:
        g_pPostReg->MODE |= SRCFMT_RGB | SRCRGB_RGB565 | SRCYUV_YUV422 | SRC_INTERLEAVE;
        break;
    case POST_SRC_RGB24:
        g_pPostReg->MODE |= SRCFMT_RGB | SRCRGB_RGB24 | SRCYUV_YUV422 | SRC_INTERLEAVE;
        break;
    case POST_SRC_YUV420:
        g_pPostReg->MODE |= SRCFMT_YUV | SRCRGB_RGB24 | SRCYUV_YUV420 | SRC_NOT_INTERLEAVE;
        break;
    case POST_SRC_YUV422_YCBYCR:
        g_pPostReg->MODE |= SRCFMT_YUV | SRCRGB_RGB24 | SRCYUV_YUV422 | SRC_INTERLEAVE | SRCYUV_YCBYCR;
        break;
    case POST_SRC_YUV422_CBYCRY:
        g_pPostReg->MODE |= SRCFMT_YUV | SRCRGB_RGB24 | SRCYUV_YUV422 | SRC_INTERLEAVE | SRCYUV_CBYCRY;
        break;
    case POST_SRC_YUV422_YCRYCB:
        g_pPostReg->MODE |= SRCFMT_YUV | SRCRGB_RGB24 | SRCYUV_YUV422 | SRC_INTERLEAVE | SRCYUV_YCRYCB;
        break;
    case POST_SRC_YUV422_CRYCBY:
        g_pPostReg->MODE |= SRCFMT_YUV | SRCRGB_RGB24 | SRCYUV_YUV422 | SRC_INTERLEAVE | SRCYUV_CRYCBY;
        break;
    default:
        POST_ERR((_T("[POST:ERR] Post_set_mode() : Unknown Source Type %d)\n\r"), SrcType));
        return POST_ERROR_ILLEGAL_PARAMETER;
        break;
    }

    switch(DstType)
    {
    case POST_DST_RGB16:
        g_pPostReg->MODE |= OUTFMT_RGB | OUTRGB_RGB565;
        break;
    case POST_DST_RGB24:
        g_pPostReg->MODE |= OUTFMT_RGB | OUTRGB_RGB24;
        break;
    case POST_DST_YUV420:
        g_pPostReg->MODE |= OUTFMT_YUV | OUTYUV_YUV420;
        break;
    case POST_DST_YUV422_YCBYCR:
        g_pPostReg->MODE |= OUTFMT_YUV | OUTYUV_YUV422 | OUTYUV_YCBYCR;
        break;
    case POST_DST_YUV422_CBYCRY:
        g_pPostReg->MODE |= OUTFMT_YUV | OUTYUV_YUV422 | OUTYUV_CBYCRY;
        break;
    case POST_DST_YUV422_YCRYCB:
        g_pPostReg->MODE |= OUTFMT_YUV | OUTYUV_YUV422 | OUTYUV_YCRYCB;
        break;
    case POST_DST_YUV422_CRYCBY:
        g_pPostReg->MODE |= OUTFMT_YUV | OUTYUV_YUV422 | OUTYUV_CRYCBY;
        break;
    case POST_DST_FIFO_YUV444:
        g_pPostReg->MODE |= OUTFMT_YUV | FIFO_OUT_ENABLE;
        break;
    case POST_DST_FIFO_RGB888:
        g_pPostReg->MODE |= OUTFMT_RGB | FIFO_OUT_ENABLE;
        break;
    default:
        POST_ERR((_T("[POST:ERR] Post_set_mode() : Unknown Destination Type %d)\n\r"), DstType));
        return POST_ERROR_ILLEGAL_PARAMETER;
        break;
    }

    POST_MSG((_T("[POST]--Post_set_mode() : %d\n\r"), error));

    return error;
}