source: trunk/JPGPROC/source/gbmsrc/gbmcvp.c@ 2

Last change on this file since 2 was 2, checked in by stevenhl, 8 years ago

Import sources from cwmm-full.zip dated 2005-03-21

File size: 2.7 KB
Line 
1/*
2
3gbmcvp.c - Portrait
4
5*/
6
7/*...sincludes:0:*/
8#include <stdio.h>
9#include <ctype.h>
10#include <stddef.h>
11#include <stdlib.h>
12#include <string.h>
13#include "gbm.h"
14#include "gbmhelp.h"
15
16/*...vgbm\46\h:0:*/
17/*...vgbmhelp\46\h:0:*/
18/*...e*/
19
20static GBMFT cvp_gbmft =
21 {
22 "Portrait",
23 "Portrait",
24 "CVP",
25 GBM_FT_R24|
26 GBM_FT_W24,
27 };
28
29#define GBM_ERR_CVP_FSIZE ((GBM_ERR) 1800)
30#define GBM_ERR_CVP_SIZE ((GBM_ERR) 1801)
31
32/*...scvp_qft:0:*/
33GBM_ERR cvp_qft(GBMFT *gbmft)
34 {
35 *gbmft = cvp_gbmft;
36 return GBM_ERR_OK;
37 }
38/*...e*/
39/*...scvp_rhdr:0:*/
40GBM_ERR cvp_rhdr(const char *fn, int fd, GBM *gbm, const char *opt)
41 {
42 long length;
43
44 fn=fn; fd=fd; opt=opt; /* Suppress 'unref arg' compiler warnings */
45
46 length = gbm_file_lseek(fd, 0L, SEEK_END);
47 gbm_file_lseek(fd, 0L, SEEK_SET);
48
49 if ( length != 512*512*3 )
50 return GBM_ERR_CVP_FSIZE;
51
52 gbm->w = 512;
53 gbm->h = 512;
54 gbm->bpp = 24;
55
56 return GBM_ERR_OK;
57 }
58/*...e*/
59/*...scvp_rpal:0:*/
60GBM_ERR cvp_rpal(int fd, GBM *gbm, GBMRGB *gbmrgb)
61 {
62 fd=fd; gbm=gbm; gbmrgb=gbmrgb; /* Suppress 'unref arg' compiler warnings */
63
64 return GBM_ERR_OK;
65 }
66/*...e*/
67/*...scvp_rdata:0:*/
68GBM_ERR cvp_rdata(int fd, GBM *gbm, byte *data)
69 {
70 int p, stride = ((gbm->w*3+3)&~3);
71 byte *line;
72 if ( (line = malloc((size_t) gbm->w)) == NULL )
73 return GBM_ERR_MEM;
74 for ( p = 2; p >= 0; p-- )
75 {
76 int y;
77 byte *ptr = data + ( (stride * (gbm->h-1)) + p );
78 for ( y = 0; y < gbm->h; y++, ptr-=stride )
79 {
80 int x;
81 if ( gbm_file_read(fd, line, gbm->w) != gbm->w )
82 {
83 free(line);
84 return GBM_ERR_READ;
85 }
86 for ( x = 0; x < gbm->w; x++ )
87 ptr[x*3] = line[gbm->w-1-x];
88 }
89 }
90 free(line);
91 return GBM_ERR_OK;
92 }
93/*...e*/
94/*...scvp_w:0:*/
95GBM_ERR cvp_w(const char *fn, int fd, const GBM *gbm, const GBMRGB *gbmrgb, const byte *data, const char *opt)
96 {
97 int p, stride = ((gbm->w*3+3)&~3);
98 byte *line;
99
100 fn=fn; gbmrgb=gbmrgb; opt=opt; /* Suppress 'unref arg' compiler warning */
101
102 if ( gbm->bpp != 24 )
103 return GBM_ERR_NOT_SUPP;
104
105 if ( gbm->w != 512 || gbm->h != 512 )
106 return GBM_ERR_CVP_SIZE;
107
108 if ( (line = malloc((size_t) gbm->w)) == NULL )
109 return GBM_ERR_MEM;
110
111 for ( p = 2; p >= 0; p-- )
112 {
113 int y;
114 const byte *ptr = data + ( (stride * (gbm->h-1)) + p );
115 for ( y = 0; y < gbm->h; y++, ptr-=stride )
116 {
117 int x;
118 for ( x = 0; x < gbm->w; x++ )
119 line[gbm->w-1-x] = ptr[x*3];
120 if ( gbm_file_write(fd, line, gbm->w) != gbm->w )
121 {
122 free(line);
123 return GBM_ERR_WRITE;
124 }
125 }
126 }
127 free(line);
128 return GBM_ERR_OK;
129 }
130/*...e*/
131/*...scvp_err:0:*/
132const char *cvp_err(GBM_ERR rc)
133 {
134 switch ( (int) rc )
135 {
136 case GBM_ERR_CVP_FSIZE:
137 return "file is not correct size";
138 case GBM_ERR_CVP_SIZE:
139 return "portrait files can only hold 512x512 images";
140 }
141 return NULL;
142 }
143/*...e*/
Note: See TracBrowser for help on using the repository browser.