⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpeg2ktopam.c

📁 linux下将各类格式图片转换工具
💻 C
📖 第 1 页 / 共 2 页
字号:
        strcpy(outpamP->tuple_type, PAM_PPM_TUPLETYPE);        break;    default:        outpamP->format = PAM_FORMAT;        outpamP->depth = jas_image_numcmpts(jasperP);        {            unsigned int plane;            MALLOCARRAY_NOFAIL(jasperCmptNo, outpamP->depth);            for (plane = 0; plane < outpamP->depth; ++plane)                jasperCmptNo[plane] = plane;        }        strcpy(outpamP->tuple_type, "");        if (jas_image_cmptsgnd(jasperP, 0))             pm_message("Warning: Input image has signed sample values.  "                       "They will be represented in the PAM output in "                       "two's complement.");    }    outpamP->plainformat = FALSE;	outpamP->width = jas_image_cmptwidth(jasperP, 0);	outpamP->height = jas_image_cmptheight(jasperP, 0);    validateComponentsAlike(jasperP);    {        unsigned int const maxPrecision = maxJasperComponentPrecision(jasperP);        outpamP->maxval = pm_bitstomaxval(maxPrecision);                outpamP->bytes_per_sample = (maxPrecision + 7)/8;    }    *jasperCmptNoP = jasperCmptNo;}static voidcreateMatrices(struct pam * const outpamP, jas_matrix_t *** matrixP) {    jas_matrix_t ** matrix;     unsigned int plane;    matrix = malloc(outpamP->depth * sizeof(jas_matrix_t *));    if (matrix == NULL)        pm_error("Out of memory");    for (plane = 0; plane < outpamP->depth; ++plane) {        matrix[plane] = jas_matrix_create(1, outpamP->width);        if (matrix[plane] == NULL)            pm_error("Unable to create matrix for plane %u.  "                     "jas_matrix_create() failed.", plane);    }       *matrixP = matrix;}static voiddestroyMatrices(struct pam *    const outpamP,                 jas_matrix_t ** const matrix ) {    unsigned int plane;    for (plane = 0; plane < outpamP->depth; ++plane)        jas_matrix_destroy(matrix[plane]);    free(matrix);}    static voidcomputeComponentMaxval(struct pam *  const outpamP,                       jas_image_t * const jasperP,                       int           const jasperCmpt[],                       sample **     const jasperMaxvalP,                       bool *        const singleMaxvalP) {        sample * jasperMaxval;    unsigned int plane;    jasperMaxval = malloc(outpamP->depth * sizeof(int *));    if (jasperMaxval == NULL)        pm_error("Out of memory");    *singleMaxvalP = TRUE;  /* initial assumption */    for (plane = 0; plane < outpamP->depth; ++plane) {        jasperMaxval[plane] =             pm_bitstomaxval(jas_image_cmptprec(jasperP, jasperCmpt[plane]));        if (jasperMaxval[plane] != jasperMaxval[0])            *singleMaxvalP = FALSE;    }    *jasperMaxvalP = jasperMaxval;}                       static voidcopyRowSingleMaxval(jas_seqent_t ** const jasperRow,                    tuple *         const tuplerow,                    struct pam *    const outpamP) {/*----------------------------------------------------------------------------   Copy row from Jasper library representation to Netpbm library   representation, assuming all Jasper components have the same precision,   which corresponds to the maxval of the output PAM, which means we don't   have to do any maxval scaling.   This is significantly faster than copyRowAnyMaxval().-----------------------------------------------------------------------------*/    unsigned int col;        for (col = 0; col < outpamP->width; ++col) {        unsigned int plane;        for (plane = 0; plane < outpamP->depth; ++plane)             tuplerow[col][plane] = jasperRow[plane][col];    }}static voidcopyRowAnyMaxval(jas_seqent_t ** const jasperRow,                 tuple *         const tuplerow,                 struct pam *    const outpamP,                 sample          const jasperMaxval[]) {/*----------------------------------------------------------------------------   Copy row from Jasper library representation to Netpbm library   representation, allowing for each Jasper library component to have a   different precision (number of bits) and for those precisions to be   unrelated to the PAM maxval.   This is significantly slower than copyRowSingleMaxval().-----------------------------------------------------------------------------*/    unsigned int col;                for (col = 0; col < outpamP->width; ++col) {        unsigned int plane;        for (plane = 0; plane < outpamP->depth; ++plane)             tuplerow[col][plane] =                 jasperRow[plane][col] *                 outpamP->maxval / jasperMaxval[plane];    }}static voidconvertToPamPnm(struct pam *  const outpamP,                jas_image_t * const jasperP,                int           const jasperCmptNo[]) {    jas_matrix_t ** matrix;  /* malloc'ed */        /* matrix[X] is the data for Plane X of the current row */    sample * jasperMaxval;    unsigned int row;    tuple * tuplerow;    jas_seqent_t ** jasperRow;   /* malloc'ed */       /* A row of a plane of the raster from the Jasper library           This is an array of pointers into the 'matrix' data structures.       */    bool singleMaxval;    createMatrices(outpamP, &matrix);    computeComponentMaxval(outpamP, jasperP, jasperCmptNo,                           &jasperMaxval, &singleMaxval);    MALLOCARRAY(jasperRow, outpamP->depth);    if (jasperRow == NULL)        pm_error("Out of memory");    tuplerow = pnm_allocpamrow(outpamP);    for (row = 0; row < outpamP->height; ++row) {        unsigned int plane;        for (plane = 0; plane < outpamP->depth; ++plane) {            int rc;            rc = jas_image_readcmpt(jasperP, jasperCmptNo[plane], 0, row,                                    outpamP->width, 1,                                    matrix[plane]);            if (rc != 0)                pm_error("jas_image_readcmpt() of row %u plane %u "                         "failed.",                          row, plane);            jasperRow[plane] = jas_matrix_getref(matrix[plane], 0, 0);        }        if (singleMaxval)             copyRowSingleMaxval(jasperRow, tuplerow, outpamP);        else            copyRowAnyMaxval(jasperRow, tuplerow, outpamP, jasperMaxval);        pnm_writepamrow(outpamP, tuplerow);    }    pnm_freepamrow(tuplerow);    destroyMatrices(outpamP, matrix);    free(jasperRow);    free(jasperMaxval);}intmain(int argc, char **argv){    struct cmdlineInfo cmdline;    struct pam outpam;    int * jasperCmpt;  /* malloc'ed */       /* jaspercmpt[P] is the component number for use with the          Jasper library that corresponds to Plane P of the PAM.         */    jas_image_t * jasperP;    pnm_init(&argc, argv);        parseCommandLine(argc, argv, &cmdline);        {         int rc;                rc = jas_init();        if ( rc != 0 )            pm_error("Failed to initialize Jasper library.  "                     "jas_init() returns rc %d", rc );    }        jas_setdbglevel(cmdline.debuglevel);        readJpc(cmdline.inputFilename, &jasperP);    outpam.file = stdout;    outpam.size = sizeof(outpam);    outpam.len  = PAM_STRUCT_SIZE(tuple_type);    computeOutputParm(jasperP, &outpam, &jasperCmpt);    pnm_writepaminit(&outpam);        convertToPamPnm(&outpam, jasperP, jasperCmpt);        free(jasperCmpt);	jas_image_destroy(jasperP);    pm_close(stdout);        return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -