| 1 | /* | 
|---|
| 2 | * Copyright (c) Chris Wohlgemuth 2002 | 
|---|
| 3 | * All rights reserved. | 
|---|
| 4 | * | 
|---|
| 5 | * http://www.geocities.com/SiliconValley/Sector/5785/ | 
|---|
| 6 | * http://www.os2world.com/cdwriting | 
|---|
| 7 | * | 
|---|
| 8 | * Redistribution and use in source and binary forms, with or without | 
|---|
| 9 | * modification, are permitted provided that the following conditions | 
|---|
| 10 | * are met: | 
|---|
| 11 | * 1. Redistributions of source code must retain the above copyright | 
|---|
| 12 | *    notice, this list of conditions and the following disclaimer. | 
|---|
| 13 | * 2. Redistributions in binary form must reproduce the above copyright | 
|---|
| 14 | *    notice, this list of conditions and the following disclaimer in the | 
|---|
| 15 | *    documentation and/or other materials provided with the distribution. | 
|---|
| 16 | * 3. The authors name may not be used to endorse or promote products | 
|---|
| 17 | *    derived from this software without specific prior written permission. | 
|---|
| 18 | * | 
|---|
| 19 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND | 
|---|
| 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
|---|
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 
|---|
| 22 | * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 
|---|
| 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
|---|
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 
|---|
| 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 
|---|
| 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 
|---|
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 
|---|
| 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 
|---|
| 29 | * SUCH DAMAGE. | 
|---|
| 30 | * | 
|---|
| 31 | */ | 
|---|
| 32 |  | 
|---|
| 33 | /************************************************************************/ | 
|---|
| 34 | /* Put all #defines here                                                */ | 
|---|
| 35 | /************************************************************************/ | 
|---|
| 36 |  | 
|---|
| 37 | #define INCL_32                         /* force 32 bit compile */ | 
|---|
| 38 | #define INCL_GPIBITMAPS | 
|---|
| 39 | #define INCL_DOSFILEMGR | 
|---|
| 40 | #define INCL_WIN | 
|---|
| 41 | #define INCL_GPI | 
|---|
| 42 | #define INCL_PM | 
|---|
| 43 |  | 
|---|
| 44 | #define MEMCHECK | 
|---|
| 45 |  | 
|---|
| 46 | /************************************************************************/ | 
|---|
| 47 | /* Put all #includes here                                               */ | 
|---|
| 48 | /************************************************************************/ | 
|---|
| 49 |  | 
|---|
| 50 | #include <os2.h> | 
|---|
| 51 | #include <stdio.h> | 
|---|
| 52 | #include <string.h> | 
|---|
| 53 | #include <stdlib.h> | 
|---|
| 54 | #include <stdarg.h> | 
|---|
| 55 | #include <io.h> | 
|---|
| 56 | #include <fcntl.h> | 
|---|
| 57 | #include <sys\stat.h> | 
|---|
| 58 | #include <os2medef.h> | 
|---|
| 59 | #include <mmioos2.h> | 
|---|
| 60 | #include "jpgproc.h" | 
|---|
| 61 |  | 
|---|
| 62 | //#define DEBUG | 
|---|
| 63 |  | 
|---|
| 64 | #ifdef DEBUG | 
|---|
| 65 | void writeLog(const char* chrFormat, ...) | 
|---|
| 66 | { | 
|---|
| 67 | char logNameLocal[CCHMAXPATH]; | 
|---|
| 68 | FILE *fHandle; | 
|---|
| 69 |  | 
|---|
| 70 | sprintf(logNameLocal,"d:\\jpgio.log"); | 
|---|
| 71 | fHandle=fopen(logNameLocal,"a"); | 
|---|
| 72 | if(fHandle) { | 
|---|
| 73 | va_list arg_ptr; | 
|---|
| 74 | void *tb; | 
|---|
| 75 |  | 
|---|
| 76 | va_start (arg_ptr, chrFormat); | 
|---|
| 77 | vfprintf(fHandle, chrFormat, arg_ptr); | 
|---|
| 78 | va_end (arg_ptr); | 
|---|
| 79 | fclose(fHandle); | 
|---|
| 80 | } | 
|---|
| 81 | } | 
|---|
| 82 | #endif | 
|---|
| 83 |  | 
|---|
| 84 | ULONG readImageData( PJPGFILESTATUS pJPGInfo) | 
|---|
| 85 | { | 
|---|
| 86 | GBM_ERR rcGBM; | 
|---|
| 87 | /******************************************************** | 
|---|
| 88 | * Determine total bytes in image | 
|---|
| 89 | ********************************************************/ | 
|---|
| 90 |  | 
|---|
| 91 | pJPGInfo->ulRGBTotalBytes =  ( ((pJPGInfo->gbm.w * pJPGInfo->gbm.bpp + 31)/32) * 4 ) | 
|---|
| 92 | * pJPGInfo->gbm.h; | 
|---|
| 93 |  | 
|---|
| 94 | pJPGInfo->ulImgTotalBytes = pJPGInfo->ulRGBTotalBytes; | 
|---|
| 95 |  | 
|---|
| 96 | /******************************************************** | 
|---|
| 97 | * Get space for full image buffer. | 
|---|
| 98 | * This will be retained until the file is closed. | 
|---|
| 99 | ********************************************************/ | 
|---|
| 100 | if (DosAllocMem ((PPVOID) &(pJPGInfo->lpRGBBuf), | 
|---|
| 101 | pJPGInfo->ulRGBTotalBytes, | 
|---|
| 102 | fALLOC)) | 
|---|
| 103 | { | 
|---|
| 104 | #ifdef DEBUG | 
|---|
| 105 | writeLog("readImagedata(): no memory for image data.\n"); | 
|---|
| 106 | #endif | 
|---|
| 107 | return (MMIO_ERROR); | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | #ifdef DEBUG | 
|---|
| 111 | writeLog("readImagedata(): allocated %d bytes for image data.\n", pJPGInfo->ulRGBTotalBytes); | 
|---|
| 112 | #endif | 
|---|
| 113 |  | 
|---|
| 114 | if ( (rcGBM = gbm_read_data(pJPGInfo->fHandleGBM, pJPGInfo->ft, | 
|---|
| 115 | &pJPGInfo->gbm, pJPGInfo->lpRGBBuf)) != GBM_ERR_OK ) | 
|---|
| 116 | { | 
|---|
| 117 | DosFreeMem ((PVOID) pJPGInfo->lpRGBBuf); | 
|---|
| 118 | #ifdef DEBUG | 
|---|
| 119 | writeLog("readImagedata(): can't read image data.\n"); | 
|---|
| 120 | #endif | 
|---|
| 121 | return (MMIO_ERROR); | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | /******************************************************** | 
|---|
| 125 | * RGB Buffer now full, set position pointers to the | 
|---|
| 126 | * beginning of the buffer. | 
|---|
| 127 | ********************************************************/ | 
|---|
| 128 | pJPGInfo->lImgBytePos =  0; | 
|---|
| 129 |  | 
|---|
| 130 | return MMIO_SUCCESS; | 
|---|
| 131 | } | 
|---|
| 132 |  | 
|---|
| 133 | static void expand_to_24bit(GBM *gbm, RGB2 *rgb2, byte **data) | 
|---|
| 134 | { | 
|---|
| 135 | int stride = ((gbm->w * gbm->bpp + 31)/32) * 4; | 
|---|
| 136 | int new_stride = ((gbm->w * 3 + 3) & ~3); | 
|---|
| 137 | int bytes, y; | 
|---|
| 138 | byte *new_data; | 
|---|
| 139 |  | 
|---|
| 140 | if ( gbm->bpp == 24 ) | 
|---|
| 141 | return; | 
|---|
| 142 |  | 
|---|
| 143 | if(!rgb2) | 
|---|
| 144 | return; | 
|---|
| 145 |  | 
|---|
| 146 | bytes = new_stride * gbm->h; | 
|---|
| 147 |  | 
|---|
| 148 | if(NO_ERROR!=DosAllocMem ((PPVOID) &new_data, | 
|---|
| 149 | bytes, | 
|---|
| 150 | fALLOC)) | 
|---|
| 151 | return; | 
|---|
| 152 |  | 
|---|
| 153 | for ( y = 0; y < gbm->h; y++ ) | 
|---|
| 154 | { | 
|---|
| 155 | byte      *src = *data + y * stride; | 
|---|
| 156 | byte      *dest = new_data + y * new_stride; | 
|---|
| 157 | int       x; | 
|---|
| 158 |  | 
|---|
| 159 | switch ( gbm->bpp ) | 
|---|
| 160 | { | 
|---|
| 161 | case 1: | 
|---|
| 162 | { | 
|---|
| 163 | byte        c; | 
|---|
| 164 |  | 
|---|
| 165 | for ( x = 0; x < gbm->w; x++ ) | 
|---|
| 166 | { | 
|---|
| 167 | if ( (x & 7) == 0 ) | 
|---|
| 168 | c = *src++; | 
|---|
| 169 | else | 
|---|
| 170 | c <<= 1; | 
|---|
| 171 |  | 
|---|
| 172 | *dest++ = rgb2[c >> 7].bBlue; | 
|---|
| 173 | *dest++ = rgb2[c >> 7].bGreen; | 
|---|
| 174 | *dest++ = rgb2[c >> 7].bRed; | 
|---|
| 175 | } | 
|---|
| 176 | } | 
|---|
| 177 | break; | 
|---|
| 178 | case 4: | 
|---|
| 179 | for ( x = 0; x + 1 < gbm->w; x += 2 ) | 
|---|
| 180 | { | 
|---|
| 181 | byte      c = *src++; | 
|---|
| 182 |  | 
|---|
| 183 | *dest++ = rgb2[c >> 4].bBlue; | 
|---|
| 184 | *dest++ = rgb2[c >> 4].bGreen; | 
|---|
| 185 | *dest++ = rgb2[c >> 4].bRed; | 
|---|
| 186 | *dest++ = rgb2[c & 15].bBlue; | 
|---|
| 187 | *dest++ = rgb2[c & 15].bGreen; | 
|---|
| 188 | *dest++ = rgb2[c & 15].bRed; | 
|---|
| 189 | } | 
|---|
| 190 |  | 
|---|
| 191 | if ( x < gbm->w ) | 
|---|
| 192 | { | 
|---|
| 193 | byte      c = *src; | 
|---|
| 194 |  | 
|---|
| 195 | *dest++ = rgb2[c >> 4].bBlue; | 
|---|
| 196 | *dest++ = rgb2[c >> 4].bGreen; | 
|---|
| 197 | *dest++ = rgb2[c >> 4].bRed; | 
|---|
| 198 | } | 
|---|
| 199 | break; | 
|---|
| 200 | case 8: | 
|---|
| 201 | for ( x = 0; x < gbm->w; x++ ) | 
|---|
| 202 | { | 
|---|
| 203 | byte      c = *src++; | 
|---|
| 204 | *dest++ = rgb2[c].bBlue; | 
|---|
| 205 | *dest++ = rgb2[c].bGreen; | 
|---|
| 206 | *dest++ = rgb2[c].bRed; | 
|---|
| 207 | } | 
|---|
| 208 | break; | 
|---|
| 209 | } | 
|---|
| 210 | } | 
|---|
| 211 | DosFreeMem(*data); | 
|---|
| 212 | *data = new_data; | 
|---|
| 213 | #ifdef DEBUG | 
|---|
| 214 | writeLog("Image data converted from %d bpp to 24 bpp.\n", gbm->bpp); | 
|---|
| 215 | #endif | 
|---|
| 216 |  | 
|---|
| 217 | gbm->bpp = 24; | 
|---|
| 218 | } | 
|---|
| 219 |  | 
|---|
| 220 | /************************************************************************/ | 
|---|
| 221 | /* JPEG IOProc                                                          */ | 
|---|
| 222 | /*                                                                      */ | 
|---|
| 223 | /* ARGUMENTS:                                                           */ | 
|---|
| 224 | /*                                                                      */ | 
|---|
| 225 | /*     PSZ pmmioStr - pointer to MMIOINFO block                         */ | 
|---|
| 226 | /*     USHORT usMsg - MMIO message being sent                           */ | 
|---|
| 227 | /*     LONG lParam1 - filename or other parameter depending on message  */ | 
|---|
| 228 | /*     LONG lParam2 - used with some messages as values                 */ | 
|---|
| 229 | /*                                                                      */ | 
|---|
| 230 | /*                                                                      */ | 
|---|
| 231 | /*  RETURN:                                                             */ | 
|---|
| 232 | /*                                                                      */ | 
|---|
| 233 | /*      MMIOM_OPEN                                                      */ | 
|---|
| 234 | /*          Success           - MMIO_SUCCESS     (0)                    */ | 
|---|
| 235 | /*          Failure           - MMIO_ERROR      (-1)                    */ | 
|---|
| 236 | /*                                                                      */ | 
|---|
| 237 | /*      MMIOM_READ                                                      */ | 
|---|
| 238 | /*          Success           - Returns the number of bytes actually    */ | 
|---|
| 239 | /*                              read.  Return 0L if no more bytes can   */ | 
|---|
| 240 | /*                              be read.                                */ | 
|---|
| 241 | /*          Failure           - MMIO_ERROR      (-1)                    */ | 
|---|
| 242 | /*                                                                      */ | 
|---|
| 243 | /*      MMIOM_WRITE                                                     */ | 
|---|
| 244 | /*          Success           - Returns the number of bytes actually    */ | 
|---|
| 245 | /*                              written.                                */ | 
|---|
| 246 | /*          Failure           - MMIO_ERROR      (-1)                    */ | 
|---|
| 247 | /*                                                                      */ | 
|---|
| 248 | /*      MMIOM_SEEK                                                      */ | 
|---|
| 249 | /*          Success           - Returns the new file position           */ | 
|---|
| 250 | /*          Failure           - MMIO_ERROR      (-1)                    */ | 
|---|
| 251 | /*                                                                      */ | 
|---|
| 252 | /*      MMIOM_CLOSE                                                     */ | 
|---|
| 253 | /*          Success           - MMIO_SUCCESS     (0)                    */ | 
|---|
| 254 | /*          Failure           - MMIO_ERROR      (-1)                    */ | 
|---|
| 255 | /*          Other             - MMIO_WARNING, file was closed but the   */ | 
|---|
| 256 | /*                              IOProc expected additional data         */ | 
|---|
| 257 | /*                                                                      */ | 
|---|
| 258 | /*      MMIOM_GETFORMATNAME                                             */ | 
|---|
| 259 | /*          Success           - Returns the number of bytes read into   */ | 
|---|
| 260 | /*                              the buffer (size of format name)        */ | 
|---|
| 261 | /*          Failure           - Return 0                                */ | 
|---|
| 262 | /*                                                                      */ | 
|---|
| 263 | /*      MMIOM_GETFORMATINFO                                             */ | 
|---|
| 264 | /*          Success           - MMIO_SUCCESS     (0)                    */ | 
|---|
| 265 | /*          Failure           - MMIO_ERROR      (-1)                    */ | 
|---|
| 266 | /*                                                                      */ | 
|---|
| 267 | /*      MMIOM_QUERYHEADERLENGTH                                         */ | 
|---|
| 268 | /*          Success           - Returns the size of the header in bytes */ | 
|---|
| 269 | /*          Failure           - Return 0                                */ | 
|---|
| 270 | /*                                                                      */ | 
|---|
| 271 | /*      MMIOM_IDENTIFYFILE                                              */ | 
|---|
| 272 | /*          Success           - MMIO_SUCCESS     (0)                    */ | 
|---|
| 273 | /*          Failure           - MMIO_ERROR      (-1)                    */ | 
|---|
| 274 | /*                                                                      */ | 
|---|
| 275 | /*      MMIOM_GETHEADER                                                 */ | 
|---|
| 276 | /*          Success           - Returns number of bytes copied into     */ | 
|---|
| 277 | /*                              the header structure.                   */ | 
|---|
| 278 | /*          Failure           - Return 0                                */ | 
|---|
| 279 | /*          Other             - If length passed in was not large       */ | 
|---|
| 280 | /*                              enough to hold header then,             */ | 
|---|
| 281 | /*                              MMIOERR_INVALID_BUFFER_LENGTH is set    */ | 
|---|
| 282 | /*                              in ulErrorRet.                          */ | 
|---|
| 283 | /*                            - If header is bad,                       */ | 
|---|
| 284 | /*                              MMIOERR_INVALID_STRUCTURE is set in     */ | 
|---|
| 285 | /*                              ulErrorRet                              */ | 
|---|
| 286 | /*                                                                      */ | 
|---|
| 287 | /*      MMIOM_SETHEADER                                                 */ | 
|---|
| 288 | /*          Success           - Returns number of bytes written         */ | 
|---|
| 289 | /*          Failure           - Return 0                                */ | 
|---|
| 290 | /*          Other             - If header is bad,                       */ | 
|---|
| 291 | /*                              MMIOERR_INVALID_STRUCTURE is set in     */ | 
|---|
| 292 | /*                              ulErrorRet                              */ | 
|---|
| 293 | /*                                                                      */ | 
|---|
| 294 | /*  DESCRIPTION:                                                        */ | 
|---|
| 295 | /*                                                                      */ | 
|---|
| 296 | /*      This routine will translate JPEG image data into                */ | 
|---|
| 297 | /*      OS/2 2.0 memory bitmap data and back again.                     */ | 
|---|
| 298 | /*                                                                      */ | 
|---|
| 299 | /*                                                                      */ | 
|---|
| 300 | /*  GLOBAL VARS REFERENCED:                                             */ | 
|---|
| 301 | /*                                                                      */ | 
|---|
| 302 | /*      None                                                            */ | 
|---|
| 303 | /*                                                                      */ | 
|---|
| 304 | /*  GLOBAL VARS MODIFIED:                                               */ | 
|---|
| 305 | /*                                                                      */ | 
|---|
| 306 | /*      None                                                            */ | 
|---|
| 307 | /*                                                                      */ | 
|---|
| 308 | /*  NOTES:                                                              */ | 
|---|
| 309 | /*                                                                      */ | 
|---|
| 310 | /*      None                                                            */ | 
|---|
| 311 | /*                                                                      */ | 
|---|
| 312 | /*  SIDE EFFECTS:                                                       */ | 
|---|
| 313 | /*                                                                      */ | 
|---|
| 314 | /*      None                                                            */ | 
|---|
| 315 | /*                                                                      */ | 
|---|
| 316 | /************************************************************************/ | 
|---|
| 317 |  | 
|---|
| 318 | LONG EXPENTRY IOProc_Entry (PVOID  pmmioStr, | 
|---|
| 319 | USHORT usMsg, | 
|---|
| 320 | LONG   lParam1, | 
|---|
| 321 | LONG   lParam2) | 
|---|
| 322 |  | 
|---|
| 323 | { | 
|---|
| 324 | PMMIOINFO   pmmioinfo;                      /* MMIOINFO block */ | 
|---|
| 325 |  | 
|---|
| 326 | pmmioinfo = (PMMIOINFO) pmmioStr; | 
|---|
| 327 |  | 
|---|
| 328 | #ifdef DEBUG | 
|---|
| 329 | writeLog("MSG: %d %x\n", usMsg,usMsg); | 
|---|
| 330 | #endif | 
|---|
| 331 |  | 
|---|
| 332 | switch (usMsg) | 
|---|
| 333 | { | 
|---|
| 334 | /*#############################################################* | 
|---|
| 335 | * When Closing the file, perform the following: | 
|---|
| 336 | * 1) Setup Variables | 
|---|
| 337 | * 2) Process the Image buffer | 
|---|
| 338 | * 3) Compress the Image to appropriate format | 
|---|
| 339 | *#############################################################*/ | 
|---|
| 340 | case MMIOM_CLOSE: | 
|---|
| 341 | { | 
|---|
| 342 | /************************************************************ | 
|---|
| 343 | * Declare local variables. | 
|---|
| 344 | ************************************************************/ | 
|---|
| 345 | PJPGFILESTATUS   pJPGInfo;         /* MMotionIOProc instance data */ | 
|---|
| 346 |  | 
|---|
| 347 | LONG            lRetCode; | 
|---|
| 348 | USHORT          rc; | 
|---|
| 349 |  | 
|---|
| 350 | #ifdef DEBUG | 
|---|
| 351 | writeLog("MMIO_CLOSE\n"); | 
|---|
| 352 | #endif | 
|---|
| 353 |  | 
|---|
| 354 | /*********************************************************** | 
|---|
| 355 | * Check for valid MMIOINFO block. | 
|---|
| 356 | ***********************************************************/ | 
|---|
| 357 | if (!pmmioinfo) | 
|---|
| 358 | return (MMIO_ERROR); | 
|---|
| 359 |  | 
|---|
| 360 | /*********************************************************** | 
|---|
| 361 | * Set up our working file status variable. | 
|---|
| 362 | ***********************************************************/ | 
|---|
| 363 | pJPGInfo = (PJPGFILESTATUS)pmmioinfo->pExtraInfoStruct; | 
|---|
| 364 |  | 
|---|
| 365 | /*********************************************************** | 
|---|
| 366 | * Assume success for the moment.... | 
|---|
| 367 | ***********************************************************/ | 
|---|
| 368 | lRetCode = MMIO_SUCCESS; | 
|---|
| 369 |  | 
|---|
| 370 | /************************************************************ | 
|---|
| 371 | * see if we are in Write mode and have a buffer to write out. | 
|---|
| 372 | *    We have no image buffer in UNTRANSLATED mode. | 
|---|
| 373 | ************************************************************/ | 
|---|
| 374 | if ((pmmioinfo->ulFlags & MMIO_WRITE) && (pJPGInfo->lpRGBBuf)) | 
|---|
| 375 | { | 
|---|
| 376 | int n_ft, ft; | 
|---|
| 377 | BOOL bValidJPG; | 
|---|
| 378 |  | 
|---|
| 379 | /* Write the buffer to disk */ | 
|---|
| 380 | #ifdef DEBUG | 
|---|
| 381 | writeLog("MMIO_CLOSE: pJPGInfo->gbm.w: %d, pJPGInfo->gbm.h: %d, pJPGInfo->gbm.bpp; %d\n", | 
|---|
| 382 | pJPGInfo->gbm.w, pJPGInfo->gbm.h, pJPGInfo->gbm.bpp); | 
|---|
| 383 | writeLog("MMIO_CLOSE: pJPGInfo->fHandleGBM: %d, pJPGInfo->ft: %d\n", | 
|---|
| 384 | pJPGInfo->fHandleGBM, pJPGInfo->ft); | 
|---|
| 385 |  | 
|---|
| 386 | #endif | 
|---|
| 387 | gbm_query_n_filetypes(&n_ft); | 
|---|
| 388 |  | 
|---|
| 389 | for ( ft = 0; ft < n_ft; ft++ ) | 
|---|
| 390 | { | 
|---|
| 391 | GBMFT gbmft; | 
|---|
| 392 | gbm_query_filetype(ft, &gbmft); | 
|---|
| 393 | if(!stricmp(gbmft.short_name, "JPEG")) { | 
|---|
| 394 | bValidJPG=TRUE; | 
|---|
| 395 | break; | 
|---|
| 396 | } | 
|---|
| 397 | } | 
|---|
| 398 |  | 
|---|
| 399 | if(bValidJPG) { | 
|---|
| 400 | if(pJPGInfo->gbm.bpp!=24) | 
|---|
| 401 | expand_to_24bit(&pJPGInfo->gbm, pJPGInfo->mmImgHdr.bmiColors, &pJPGInfo->lpRGBBuf); | 
|---|
| 402 |  | 
|---|
| 403 | if ( (rc = gbm_write("", pJPGInfo->fHandleGBM, ft, &pJPGInfo->gbm, | 
|---|
| 404 | NULL /*gbmrgb*/, pJPGInfo->lpRGBBuf, "")) != GBM_ERR_OK ) | 
|---|
| 405 | { | 
|---|
| 406 | #ifdef DEBUG | 
|---|
| 407 | writeLog("MMIO_CLOSE: can't write image data.\n"); | 
|---|
| 408 | #endif | 
|---|
| 409 | } | 
|---|
| 410 | } | 
|---|
| 411 | }  /* end IF WRITE & IMAGE BUFFER block */ | 
|---|
| 412 |  | 
|---|
| 413 | /*********************************************************** | 
|---|
| 414 | * Free the RGB buffer, if it exists, that was created | 
|---|
| 415 | * for the translated READ operations. | 
|---|
| 416 | ***********************************************************/ | 
|---|
| 417 | if (pJPGInfo->lpRGBBuf) | 
|---|
| 418 | { | 
|---|
| 419 | DosFreeMem ((PVOID) pJPGInfo->lpRGBBuf); | 
|---|
| 420 | } | 
|---|
| 421 |  | 
|---|
| 422 | /*********************************************************** | 
|---|
| 423 | * Close the file | 
|---|
| 424 | ***********************************************************/ | 
|---|
| 425 | gbm_io_close(pJPGInfo->fHandleGBM); | 
|---|
| 426 |  | 
|---|
| 427 | DosFreeMem ((PVOID) pJPGInfo); | 
|---|
| 428 |  | 
|---|
| 429 | return (lRetCode); | 
|---|
| 430 | }  /* end case of MMIOM_CLOSE */ | 
|---|
| 431 |  | 
|---|
| 432 | /*#############################################################* | 
|---|
| 433 | * Get the NLS format Information. | 
|---|
| 434 | *#############################################################*/ | 
|---|
| 435 | case MMIOM_GETFORMATINFO: | 
|---|
| 436 | { | 
|---|
| 437 | /*********************************************************** | 
|---|
| 438 | * Declare local variables. | 
|---|
| 439 | ***********************************************************/ | 
|---|
| 440 | PMMFORMATINFO       pmmformatinfo; | 
|---|
| 441 |  | 
|---|
| 442 | #ifdef DEBUG | 
|---|
| 443 | writeLog("MMIO_GETFORMATINFO\n"); | 
|---|
| 444 | #endif | 
|---|
| 445 |  | 
|---|
| 446 | /************************************************************ | 
|---|
| 447 | * Set pointer to MMFORMATINFO structure. | 
|---|
| 448 | ************************************************************/ | 
|---|
| 449 | pmmformatinfo = (PMMFORMATINFO) lParam1; | 
|---|
| 450 |  | 
|---|
| 451 | /************************************************************ | 
|---|
| 452 | * Fill in the values for the MMFORMATINFO structure. | 
|---|
| 453 | ************************************************************/ | 
|---|
| 454 | pmmformatinfo->ulStructLen  = sizeof (MMFORMATINFO); | 
|---|
| 455 | pmmformatinfo->fccIOProc    = FOURCC_JPG; | 
|---|
| 456 | pmmformatinfo->ulIOProcType = MMIO_IOPROC_FILEFORMAT; | 
|---|
| 457 | pmmformatinfo->ulMediaType  = MMIO_MEDIATYPE_IMAGE; | 
|---|
| 458 |  | 
|---|
| 459 | pmmformatinfo->ulFlags      = MMIO_CANREADTRANSLATED | | 
|---|
| 460 | MMIO_CANSEEKTRANSLATED        | | 
|---|
| 461 | MMIO_CANWRITETRANSLATED | 
|---|
| 462 | /* MMIO_CANREADUNTRANSLATED      | | 
|---|
| 463 | MMIO_CANWRITETRANSLATED       | | 
|---|
| 464 | MMIO_CANWRITEUNTRANSLATED     | | 
|---|
| 465 | MMIO_CANREADWRITEUNTRANSLATED | | 
|---|
| 466 |  | 
|---|
| 467 | MMIO_CANSEEKUNTRANSLATED */; | 
|---|
| 468 |  | 
|---|
| 469 | strcpy ((PSZ) pmmformatinfo->szDefaultFormatExt, pszJPGExt); | 
|---|
| 470 | if (GetNLSData( &pmmformatinfo->ulCodePage, | 
|---|
| 471 | &pmmformatinfo->ulLanguage )) | 
|---|
| 472 | { | 
|---|
| 473 | return( -1L ); | 
|---|
| 474 | } | 
|---|
| 475 |  | 
|---|
| 476 | if (GetFormatStringLength( FOURCC_JPG, | 
|---|
| 477 | &(pmmformatinfo->lNameLength) )) | 
|---|
| 478 | { | 
|---|
| 479 | return( -1L ); | 
|---|
| 480 | } | 
|---|
| 481 |  | 
|---|
| 482 |  | 
|---|
| 483 | /************************************************************ | 
|---|
| 484 | * Return success back to the application. | 
|---|
| 485 | ************************************************************/ | 
|---|
| 486 | return (MMIO_SUCCESS); | 
|---|
| 487 | } /* end case of MMIOM_GETFORMATINFO */ | 
|---|
| 488 |  | 
|---|
| 489 | /*#############################################################* | 
|---|
| 490 | * Get the NLS format name. | 
|---|
| 491 | *#############################################################*/ | 
|---|
| 492 | case MMIOM_GETFORMATNAME: | 
|---|
| 493 | { | 
|---|
| 494 | LONG lBytesCopied; | 
|---|
| 495 |  | 
|---|
| 496 | #ifdef DEBUG | 
|---|
| 497 | writeLog("MMIO_GETFORMATNAME\n"); | 
|---|
| 498 | #endif | 
|---|
| 499 |  | 
|---|
| 500 | /************************************************************ | 
|---|
| 501 | * Copy format string into buffer supplied by | 
|---|
| 502 | * lParam1.  Only put in the amount of my string up to the | 
|---|
| 503 | * allocated amount which is in lParam2.  Leave enough room | 
|---|
| 504 | * for the NULL termination. | 
|---|
| 505 | ************************************************************/ | 
|---|
| 506 | lBytesCopied = GetFormatString( FOURCC_JPG, | 
|---|
| 507 | (char *)lParam1, | 
|---|
| 508 | lParam2 ); | 
|---|
| 509 |  | 
|---|
| 510 | return (lBytesCopied); | 
|---|
| 511 | } /* end case of MMIOM_GETFORMATNAME */ | 
|---|
| 512 |  | 
|---|
| 513 | /*#############################################################* | 
|---|
| 514 | * Get the file header. | 
|---|
| 515 | *#############################################################*/ | 
|---|
| 516 | case MMIOM_GETHEADER: | 
|---|
| 517 | { | 
|---|
| 518 | /************************************************************ | 
|---|
| 519 | * Declare local variables. | 
|---|
| 520 | ************************************************************/ | 
|---|
| 521 | //  PMMFILESTATUS       pVidInfo; | 
|---|
| 522 | PJPGFILESTATUS       pJPGInfo; | 
|---|
| 523 | #ifdef DEBUG | 
|---|
| 524 | writeLog("MMIO_GETHEADER\n"); | 
|---|
| 525 | #endif | 
|---|
| 526 |  | 
|---|
| 527 | /************************************************************ | 
|---|
| 528 | * Check for valid MMIOINFO block. | 
|---|
| 529 | ************************************************************/ | 
|---|
| 530 | if (!pmmioinfo) | 
|---|
| 531 | return (0); | 
|---|
| 532 |  | 
|---|
| 533 | /************************************************************ | 
|---|
| 534 | * Set up our working file status variable. | 
|---|
| 535 | ************************************************************/ | 
|---|
| 536 | pJPGInfo = (PJPGFILESTATUS)pmmioinfo->pExtraInfoStruct; | 
|---|
| 537 |  | 
|---|
| 538 | /************************************************** | 
|---|
| 539 | * Getheader only valid in READ or READ/WRITE mode. | 
|---|
| 540 | * There is no header to get in WRITE mode.  We | 
|---|
| 541 | * must also have a valid file handle to read from | 
|---|
| 542 | **************************************************/ | 
|---|
| 543 | if ((pmmioinfo->ulFlags & MMIO_WRITE) || | 
|---|
| 544 | (!(pJPGInfo->fHandleGBM))) | 
|---|
| 545 | return (0); | 
|---|
| 546 |  | 
|---|
| 547 | /************************************************************ | 
|---|
| 548 | * Check for Translation mode. | 
|---|
| 549 | ************************************************************/ | 
|---|
| 550 | if (!(pmmioinfo->ulTranslate & MMIO_TRANSLATEHEADER)) | 
|---|
| 551 | { | 
|---|
| 552 | /******************************************************** | 
|---|
| 553 | * Translation is off. | 
|---|
| 554 | ********************************************************/ | 
|---|
| 555 | /* Unstranslatd headers are not supported !!! */ | 
|---|
| 556 | return 0; | 
|---|
| 557 | }   /* end IF NOT TRANSLATED block */ | 
|---|
| 558 |  | 
|---|
| 559 | /****************** | 
|---|
| 560 | * TRANSLATION IS ON | 
|---|
| 561 | ******************/ | 
|---|
| 562 | if (lParam2 < sizeof (MMIMAGEHEADER)) | 
|---|
| 563 | { | 
|---|
| 564 | pmmioinfo->ulErrorRet = MMIOERR_INVALID_BUFFER_LENGTH; | 
|---|
| 565 | return (0); | 
|---|
| 566 | } | 
|---|
| 567 |  | 
|---|
| 568 | if (!lParam1) | 
|---|
| 569 | { | 
|---|
| 570 | pmmioinfo->ulErrorRet = MMIOERR_INVALID_STRUCTURE; | 
|---|
| 571 | return (0); | 
|---|
| 572 | } | 
|---|
| 573 |  | 
|---|
| 574 | memcpy ((PVOID)lParam1, | 
|---|
| 575 | (PVOID)&pJPGInfo->mmImgHdr, | 
|---|
| 576 | sizeof (MMIMAGEHEADER)); | 
|---|
| 577 |  | 
|---|
| 578 | return (sizeof (MMIMAGEHEADER)); | 
|---|
| 579 | } /* end case of MMIOM_GETHEADER */ | 
|---|
| 580 |  | 
|---|
| 581 | /*#############################################################* | 
|---|
| 582 | * Identify whether this file can be processed. | 
|---|
| 583 | *#############################################################*/ | 
|---|
| 584 | case MMIOM_IDENTIFYFILE: | 
|---|
| 585 | { | 
|---|
| 586 |  | 
|---|
| 587 | /************************************************************ | 
|---|
| 588 | * Declare local variables. | 
|---|
| 589 | ************************************************************/ | 
|---|
| 590 | GBMFT gbmft; | 
|---|
| 591 | int ft, fd, n_ft; | 
|---|
| 592 | BOOL bValidJPG= FALSE; | 
|---|
| 593 |  | 
|---|
| 594 | ULONG           ulTempFlags = MMIO_READ | MMIO_DENYWRITE | | 
|---|
| 595 | MMIO_NOIDENTIFY; | 
|---|
| 596 | /* flags used for temp open  */ | 
|---|
| 597 | /* and close                 */ | 
|---|
| 598 | #ifdef DEBUG | 
|---|
| 599 | writeLog("MMIO_IDENTIFYFILE\n"); | 
|---|
| 600 | #endif | 
|---|
| 601 |  | 
|---|
| 602 | /************************************************************ | 
|---|
| 603 | * We need either a file name (lParam1) or file handle (lParam2) | 
|---|
| 604 | ************************************************************/ | 
|---|
| 605 | if (!lParam1 && !lParam2) | 
|---|
| 606 | return (MMIO_ERROR); | 
|---|
| 607 |  | 
|---|
| 608 | if ( gbm_init() != GBM_ERR_OK ) | 
|---|
| 609 | return MMIO_ERROR; | 
|---|
| 610 |  | 
|---|
| 611 | if ( (fd = gbm_io_open((PSZ) lParam1, O_RDONLY|O_BINARY)) == -1 ) | 
|---|
| 612 | { | 
|---|
| 613 | gbm_deinit(); | 
|---|
| 614 | return (MMIO_ERROR); | 
|---|
| 615 | } | 
|---|
| 616 |  | 
|---|
| 617 | gbm_query_n_filetypes(&n_ft); | 
|---|
| 618 |  | 
|---|
| 619 | for ( ft = 0; ft < n_ft; ft++ ) | 
|---|
| 620 | { | 
|---|
| 621 | GBM gbm; | 
|---|
| 622 |  | 
|---|
| 623 | if ( gbm_read_header((PSZ) lParam1, fd, ft, &gbm, "") == GBM_ERR_OK ) | 
|---|
| 624 | { | 
|---|
| 625 | gbm_query_filetype(ft, &gbmft); | 
|---|
| 626 | if(!stricmp(gbmft.short_name, "JPEG")) | 
|---|
| 627 | bValidJPG=TRUE; | 
|---|
| 628 | } | 
|---|
| 629 | } | 
|---|
| 630 |  | 
|---|
| 631 | gbm_io_close(fd); | 
|---|
| 632 | gbm_deinit(); | 
|---|
| 633 |  | 
|---|
| 634 | if(bValidJPG) { | 
|---|
| 635 | return (MMIO_SUCCESS); | 
|---|
| 636 | } | 
|---|
| 637 |  | 
|---|
| 638 | return (MMIO_ERROR); | 
|---|
| 639 |  | 
|---|
| 640 | } /* end case of MMIOM_IDENTIFYFILE */ | 
|---|
| 641 |  | 
|---|
| 642 | /*#############################################################*/ | 
|---|
| 643 | /*#############################################################*/ | 
|---|
| 644 | case MMIOM_OPEN: | 
|---|
| 645 | { | 
|---|
| 646 |  | 
|---|
| 647 | /************************************************************ | 
|---|
| 648 | * Declare local variables | 
|---|
| 649 | ************************************************************/ | 
|---|
| 650 |  | 
|---|
| 651 |  | 
|---|
| 652 | PJPGFILESTATUS   pJPGInfo;   /* pointer to a JPG file       */ | 
|---|
| 653 | /* status structure that we will*/ | 
|---|
| 654 | /* use for this file instance   */ | 
|---|
| 655 |  | 
|---|
| 656 | MMIMAGEHEADER   MMImgHdr; | 
|---|
| 657 | ULONG           ulWidth; | 
|---|
| 658 | ULONG           ulHeight; | 
|---|
| 659 | PBYTE           lpRGBBufPtr; | 
|---|
| 660 |  | 
|---|
| 661 | PSZ pszFileName = (CHAR *)lParam1;  /* get the filename from    */ | 
|---|
| 662 | /* parameter                */ | 
|---|
| 663 |  | 
|---|
| 664 | GBMFT gbmft; | 
|---|
| 665 | int ft, fd, n_ft, stride, bytes; | 
|---|
| 666 | BOOL bValidJPG= FALSE; | 
|---|
| 667 | int fOpenFlags; | 
|---|
| 668 | GBM_ERR     rc; | 
|---|
| 669 |  | 
|---|
| 670 | #ifdef DEBUG | 
|---|
| 671 | writeLog("MMIO_OPEN\n"); | 
|---|
| 672 | #endif | 
|---|
| 673 | /************************************************************ | 
|---|
| 674 | * Check for valid MMIOINFO block. | 
|---|
| 675 | ************************************************************/ | 
|---|
| 676 | if (!pmmioinfo) | 
|---|
| 677 | return (MMIO_ERROR); | 
|---|
| 678 |  | 
|---|
| 679 | /************************************************************ | 
|---|
| 680 | * If flags show read and write then send back an error.  We | 
|---|
| 681 | * only support reading or writing but not both at the same | 
|---|
| 682 | * time on the same file. | 
|---|
| 683 | ************************************************************/ | 
|---|
| 684 | if ((pmmioinfo->ulFlags & MMIO_READWRITE) && | 
|---|
| 685 | ((pmmioinfo->ulTranslate & MMIO_TRANSLATEDATA) || | 
|---|
| 686 | (pmmioinfo->ulTranslate & MMIO_TRANSLATEHEADER))) | 
|---|
| 687 | { | 
|---|
| 688 | #ifdef DEBUG | 
|---|
| 689 | writeLog("MMIO_OPEN, read/write not supported.\n"); | 
|---|
| 690 | #endif | 
|---|
| 691 | return (MMIO_ERROR); | 
|---|
| 692 | } | 
|---|
| 693 |  | 
|---|
| 694 | /* We can't read/write untranslated */ | 
|---|
| 695 | if ( ( !(pmmioinfo->ulTranslate & MMIO_TRANSLATEDATA) || | 
|---|
| 696 | !(pmmioinfo->ulTranslate & MMIO_TRANSLATEHEADER) ) ) | 
|---|
| 697 | { | 
|---|
| 698 | #ifdef DEBUG | 
|---|
| 699 | writeLog("MMIO_OPEN, untranslated not supported.\n"); | 
|---|
| 700 | #endif | 
|---|
| 701 | return (MMIO_ERROR); | 
|---|
| 702 | } | 
|---|
| 703 |  | 
|---|
| 704 |  | 
|---|
| 705 | /*!!!!!!!!!!!!!!!!!!!!!! FIXME !!!!!!!!!!!!!!!!!!!!!!!*/ | 
|---|
| 706 | /* To be honest we can almost nothing ;-) */ | 
|---|
| 707 | if (pmmioinfo->ulFlags & | 
|---|
| 708 | (MMIO_APPEND| | 
|---|
| 709 | MMIO_ALLOCBUF|MMIO_BUFSHARED | MMIO_VERTBAR )) | 
|---|
| 710 | { | 
|---|
| 711 | #ifdef DEBUG | 
|---|
| 712 | writeLog("MMIO_OPEN, unsupported flag in %x\n", pmmioinfo->ulFlags); | 
|---|
| 713 | #endif | 
|---|
| 714 | return (MMIO_ERROR); | 
|---|
| 715 | } | 
|---|
| 716 |  | 
|---|
| 717 | /* Caller requested a delete */ | 
|---|
| 718 | if(pmmioinfo->ulFlags & MMIO_DELETE) { | 
|---|
| 719 | #ifdef DEBUG | 
|---|
| 720 | writeLog("MMIO_OPEN: MMIO_DELETE set\n"); | 
|---|
| 721 | #endif | 
|---|
| 722 | if(remove((PSZ) lParam1)==-1) | 
|---|
| 723 | return (MMIO_ERROR); | 
|---|
| 724 | } | 
|---|
| 725 | /************************************************************ | 
|---|
| 726 | Allocate our private data structure | 
|---|
| 727 | ************************************************************/ | 
|---|
| 728 | if(NO_ERROR!=DosAllocMem ((PPVOID) &pJPGInfo, | 
|---|
| 729 | sizeof (JPGFILESTATUS), | 
|---|
| 730 | fALLOC)) | 
|---|
| 731 | return  MMIO_ERROR; | 
|---|
| 732 |  | 
|---|
| 733 | memset((PVOID)pJPGInfo,0, sizeof(JPGFILESTATUS)); | 
|---|
| 734 |  | 
|---|
| 735 | if ( gbm_init() != GBM_ERR_OK ) { | 
|---|
| 736 | DosFreeMem(pJPGInfo); | 
|---|
| 737 | return MMIO_ERROR; | 
|---|
| 738 | } | 
|---|
| 739 |  | 
|---|
| 740 | /************************************************************ | 
|---|
| 741 | * Store pointer to our JPGFILESTATUS structure in | 
|---|
| 742 | * pExtraInfoStruct field that is provided for our use. | 
|---|
| 743 | ************************************************************/ | 
|---|
| 744 | pmmioinfo->pExtraInfoStruct = (PVOID)pJPGInfo; | 
|---|
| 745 |  | 
|---|
| 746 | /************************************************************ | 
|---|
| 747 | MMIO_WRITE | 
|---|
| 748 | ************************************************************/ | 
|---|
| 749 | if (pmmioinfo->ulFlags & MMIO_WRITE) { | 
|---|
| 750 | /* It's a write so open the file */ | 
|---|
| 751 | #ifdef DEBUG | 
|---|
| 752 | writeLog("MMIO_OPEN: flag MMIO_WRITE set\n"); | 
|---|
| 753 | #endif | 
|---|
| 754 |  | 
|---|
| 755 | fOpenFlags=O_WRONLY|O_BINARY; | 
|---|
| 756 | if(pmmioinfo->ulFlags & MMIO_CREATE) { | 
|---|
| 757 | fOpenFlags|=O_CREAT|O_TRUNC; | 
|---|
| 758 | if ( (fd = gbm_io_create((PSZ) lParam1, O_WRONLY|O_BINARY)) == -1 ) | 
|---|
| 759 | { | 
|---|
| 760 | /* GBM can't create the file */ | 
|---|
| 761 | #ifdef DEBUG | 
|---|
| 762 | writeLog("MMIO_OPEN: create failed, flags: %x, file %s\n", | 
|---|
| 763 | fOpenFlags, (PSZ) lParam1); | 
|---|
| 764 | writeLog("MMIO_OPEN: errno: 0x%x, \n", | 
|---|
| 765 | errno); | 
|---|
| 766 | #endif | 
|---|
| 767 | gbm_deinit(); | 
|---|
| 768 | DosFreeMem(pJPGInfo); | 
|---|
| 769 | return (MMIO_ERROR); | 
|---|
| 770 | } | 
|---|
| 771 | } | 
|---|
| 772 | else { | 
|---|
| 773 | if ( (fd = gbm_io_open((PSZ) lParam1, /*fOpenFlags*/ O_BINARY|O_WRONLY)) == -1 ) | 
|---|
| 774 | { | 
|---|
| 775 | /* GBM can't open the file */ | 
|---|
| 776 | #ifdef DEBUG | 
|---|
| 777 | writeLog("MMIO_OPEN: \n"); | 
|---|
| 778 | writeLog("MMIO_OPEN: open failed, flags: %x, file %s\n", | 
|---|
| 779 | fOpenFlags, (PSZ) lParam1); | 
|---|
| 780 | writeLog("MMIO_OPEN: errno: 0x%x, \n", | 
|---|
| 781 | errno); | 
|---|
| 782 | #endif | 
|---|
| 783 | gbm_deinit(); | 
|---|
| 784 | DosFreeMem(pJPGInfo); | 
|---|
| 785 | return (MMIO_ERROR); | 
|---|
| 786 | } | 
|---|
| 787 | }/* else */ | 
|---|
| 788 |  | 
|---|
| 789 | pJPGInfo->fHandleGBM=fd; | 
|---|
| 790 | return (MMIO_SUCCESS); | 
|---|
| 791 | } | 
|---|
| 792 |  | 
|---|
| 793 | /* Since we can't write and we are here, this is a read. The read flag isn't | 
|---|
| 794 | necessarily set... | 
|---|
| 795 | */ | 
|---|
| 796 |  | 
|---|
| 797 | /* | 
|---|
| 798 | First get some infos from GBM. | 
|---|
| 799 | */ | 
|---|
| 800 | if(pmmioinfo->ulFlags & MMIO_WRITE) | 
|---|
| 801 | fOpenFlags=O_WRONLY; | 
|---|
| 802 | else if(pmmioinfo->ulFlags & MMIO_READWRITE) | 
|---|
| 803 | fOpenFlags=O_RDWR; | 
|---|
| 804 | else | 
|---|
| 805 | fOpenFlags=O_RDONLY; | 
|---|
| 806 |  | 
|---|
| 807 | fOpenFlags|=O_BINARY; | 
|---|
| 808 |  | 
|---|
| 809 | if ( (fd = gbm_io_open((PSZ) lParam1, fOpenFlags)) == -1 ) | 
|---|
| 810 | { | 
|---|
| 811 | gbm_deinit(); | 
|---|
| 812 | DosFreeMem(pJPGInfo); | 
|---|
| 813 | return (MMIO_ERROR); | 
|---|
| 814 | } | 
|---|
| 815 |  | 
|---|
| 816 | gbm_query_n_filetypes(&n_ft); | 
|---|
| 817 |  | 
|---|
| 818 | for ( ft = 0; ft < n_ft; ft++ ) | 
|---|
| 819 | { | 
|---|
| 820 | if ( gbm_read_header((PSZ) lParam1, fd, ft, &pJPGInfo->gbm, "") == GBM_ERR_OK ) | 
|---|
| 821 | { | 
|---|
| 822 | gbm_query_filetype(ft, &gbmft); | 
|---|
| 823 | if(!stricmp(gbmft.short_name, "JPEG")) { | 
|---|
| 824 | bValidJPG=TRUE; | 
|---|
| 825 | pJPGInfo->ft=ft; | 
|---|
| 826 | #ifdef DEBUG | 
|---|
| 827 | writeLog("MMIO_OPEN, JPEG proc found ft: %d\n", ft); | 
|---|
| 828 | #endif | 
|---|
| 829 | break; | 
|---|
| 830 | } | 
|---|
| 831 | } | 
|---|
| 832 | } | 
|---|
| 833 |  | 
|---|
| 834 | if(!bValidJPG) { | 
|---|
| 835 | #ifdef DEBUG | 
|---|
| 836 | writeLog("MMIO_OPEN, file isn't a valid JPEG file\n"); | 
|---|
| 837 | #endif | 
|---|
| 838 | DosFreeMem(pJPGInfo); | 
|---|
| 839 | gbm_io_close(fd); | 
|---|
| 840 | gbm_deinit(); | 
|---|
| 841 | return (MMIO_ERROR); | 
|---|
| 842 | } | 
|---|
| 843 |  | 
|---|
| 844 | pJPGInfo->fHandleGBM=fd; | 
|---|
| 845 |  | 
|---|
| 846 | if(pJPGInfo->gbm.bpp==8) { | 
|---|
| 847 | GBMRGB gbmrgb[0x100]; | 
|---|
| 848 | RGB2 *rgb2; | 
|---|
| 849 | int a; | 
|---|
| 850 |  | 
|---|
| 851 | #ifdef DEBUG | 
|---|
| 852 | writeLog("MMIO_OPEN, reading palette for 8bpp JPG.\n"); | 
|---|
| 853 | #endif | 
|---|
| 854 |  | 
|---|
| 855 | /* Get palette for 8Bit JPGs (grey) */ | 
|---|
| 856 | if ( (rc = gbm_read_palette(fd, pJPGInfo->ft, &pJPGInfo->gbm, gbmrgb)) != GBM_ERR_OK ) | 
|---|
| 857 | { | 
|---|
| 858 | #ifdef DEBUG | 
|---|
| 859 | writeLog("MMIO_OPEN, can't get palette for 8bpp JPG.\n"); | 
|---|
| 860 | #endif | 
|---|
| 861 | DosFreeMem(pJPGInfo); | 
|---|
| 862 | gbm_io_close(fd); | 
|---|
| 863 | gbm_deinit(); | 
|---|
| 864 | return (MMIO_ERROR); | 
|---|
| 865 | } | 
|---|
| 866 | rgb2=MMImgHdr.bmiColors; | 
|---|
| 867 | for(a=0;a<256;a++){ | 
|---|
| 868 | rgb2[a].bBlue=gbmrgb[a].b; | 
|---|
| 869 | rgb2[a].bGreen=gbmrgb[a].g; | 
|---|
| 870 | rgb2[a].bRed=gbmrgb[a].r; | 
|---|
| 871 | } | 
|---|
| 872 |  | 
|---|
| 873 |  | 
|---|
| 874 | } | 
|---|
| 875 | /************************************************************ | 
|---|
| 876 | * If the app intends to read in translation mode, we must | 
|---|
| 877 | * allocate and set-up the buffer that will contain the RGB data | 
|---|
| 878 | * | 
|---|
| 879 | * We must also read in the data to insure that the first | 
|---|
| 880 | * read, seek, or get-header operation will have data | 
|---|
| 881 | * to use.  This is ONLY NECESSARY FOR TRANSLATED MODE | 
|---|
| 882 | * operations, since we must process reads/writes pretending | 
|---|
| 883 | * the image is stored from the Bottom-up. | 
|---|
| 884 | * | 
|---|
| 885 | ************************************************************ | 
|---|
| 886 | ************************************************************ | 
|---|
| 887 | * Fill out the MMIMAGEHEADER structure. | 
|---|
| 888 | ************************************************************/ | 
|---|
| 889 | #if 0 | 
|---|
| 890 | MMImgHdr.ulHeaderLength = sizeof (MMIMAGEHEADER); | 
|---|
| 891 | MMImgHdr.ulContentType  = MMIO_IMAGE_PHOTO; | 
|---|
| 892 | MMImgHdr.ulMediaType    = MMIO_MEDIATYPE_IMAGE; | 
|---|
| 893 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cbFix = | 
|---|
| 894 | sizeof (BITMAPINFOHEADER2); | 
|---|
| 895 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cx              = pJPGInfo->gbm.w; | 
|---|
| 896 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cy              = pJPGInfo->gbm.h; | 
|---|
| 897 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cPlanes         = 1; | 
|---|
| 898 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount       = pJPGInfo->gbm.bpp; | 
|---|
| 899 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.ulCompression   = | 
|---|
| 900 | BCA_UNCOMP; | 
|---|
| 901 | if(pJPGInfo->gbm.bpp==8) { | 
|---|
| 902 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cbImage         = | 
|---|
| 903 | ulWidth * ulHeight; | 
|---|
| 904 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cclrUsed        = 256L; | 
|---|
| 905 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cclrImportant        = 256L; | 
|---|
| 906 | } | 
|---|
| 907 | else | 
|---|
| 908 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cbImage         = | 
|---|
| 909 | ulWidth * ulHeight * 3; | 
|---|
| 910 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cxResolution    = 0L; | 
|---|
| 911 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cyResolution    = 0L; | 
|---|
| 912 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cclrUsed        = 0L; | 
|---|
| 913 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cclrImportant   = 0L; | 
|---|
| 914 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.usUnits         = 0L; | 
|---|
| 915 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.usReserved      = 0L; | 
|---|
| 916 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.usRecording     = | 
|---|
| 917 | BRA_BOTTOMUP; | 
|---|
| 918 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.usRendering     = | 
|---|
| 919 | BRH_NOTHALFTONED; | 
|---|
| 920 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cSize1          = 0L; | 
|---|
| 921 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cSize2          = 0L; | 
|---|
| 922 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.ulColorEncoding = 0L; | 
|---|
| 923 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.ulIdentifier    = 0L; | 
|---|
| 924 | #endif | 
|---|
| 925 |  | 
|---|
| 926 | MMImgHdr.ulHeaderLength = sizeof (MMIMAGEHEADER); | 
|---|
| 927 | MMImgHdr.ulContentType  = 0;                         //MMIO_IMAGE_PHOTO; | 
|---|
| 928 | MMImgHdr.ulMediaType    = MMIO_MEDIATYPE_IMAGE; | 
|---|
| 929 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cbFix = | 
|---|
| 930 | sizeof (BITMAPINFOHEADER2); | 
|---|
| 931 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cx              = pJPGInfo->gbm.w; | 
|---|
| 932 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cy              = pJPGInfo->gbm.h; | 
|---|
| 933 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cPlanes         = 1; | 
|---|
| 934 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount       = pJPGInfo->gbm.bpp; | 
|---|
| 935 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.ulCompression   = | 
|---|
| 936 | BCA_UNCOMP; | 
|---|
| 937 | if(pJPGInfo->gbm.bpp==8) { | 
|---|
| 938 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cbImage         = | 
|---|
| 939 | ulWidth * ulHeight; | 
|---|
| 940 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cclrUsed        = 256L; | 
|---|
| 941 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cclrImportant   = 256L; | 
|---|
| 942 | } | 
|---|
| 943 | else | 
|---|
| 944 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cbImage         = | 
|---|
| 945 | ulWidth * ulHeight * 3; | 
|---|
| 946 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cxResolution    = 0L; | 
|---|
| 947 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cyResolution    = 0L; | 
|---|
| 948 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cclrUsed        = 0L; | 
|---|
| 949 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cclrImportant   = 0L; | 
|---|
| 950 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.usUnits         = 0L; | 
|---|
| 951 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.usReserved      = 0L; | 
|---|
| 952 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.usRecording     = | 
|---|
| 953 | BRA_BOTTOMUP; | 
|---|
| 954 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.usRendering     = | 
|---|
| 955 | BRH_NOTHALFTONED; | 
|---|
| 956 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cSize1          = 0L; | 
|---|
| 957 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cSize2          = 0L; | 
|---|
| 958 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.ulColorEncoding = 0L; | 
|---|
| 959 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.ulIdentifier    = 0L; | 
|---|
| 960 |  | 
|---|
| 961 | #ifdef DEBUG | 
|---|
| 962 | writeLog("MMIO_OPEN, procname is: %s\n", gbmft.short_name); | 
|---|
| 963 | writeLog("MMIO_OPEN: pJPGInfo->gbm.w: %d, pJPGInfo->gbm.h: %d, pJPGInfo->gbm.bpp; %d\n", | 
|---|
| 964 | pJPGInfo->gbm.w, pJPGInfo->gbm.h, pJPGInfo->gbm.bpp); | 
|---|
| 965 | writeLog("MMIO_OPEN: pJPGInfo->fHandleGBM: %d, pJPGInfo->ft: %d\n", | 
|---|
| 966 | pJPGInfo->fHandleGBM, pJPGInfo->ft); | 
|---|
| 967 | #endif | 
|---|
| 968 | /******************************************************** | 
|---|
| 969 | * Determine total bytes in image | 
|---|
| 970 | ********************************************************/ | 
|---|
| 971 |  | 
|---|
| 972 | stride = ( ((pJPGInfo->gbm.w * pJPGInfo->gbm.bpp + 31)/32) * 4 ); | 
|---|
| 973 | bytes = stride * pJPGInfo->gbm.h; | 
|---|
| 974 |  | 
|---|
| 975 | pJPGInfo->ulRGBTotalBytes = bytes; | 
|---|
| 976 | pJPGInfo->ulImgTotalBytes = pJPGInfo->ulRGBTotalBytes; | 
|---|
| 977 |  | 
|---|
| 978 | MMImgHdr.mmXDIBHeader.BMPInfoHeader2.cbImage=pJPGInfo->ulRGBTotalBytes; | 
|---|
| 979 | //               MMImgHdr.mmXDIBHeader.XDIBHeaderPrefix.ulMemSize=pJPGInfo->ulRGBTotalBytes; | 
|---|
| 980 | //               MMImgHdr.mmXDIBHeader.XDIBHeaderPrefix.ulPelFormat=mmioFOURCC('p','a','l','b'); | 
|---|
| 981 |  | 
|---|
| 982 | /************************************************************ | 
|---|
| 983 | * Copy the image header into private area for later use. | 
|---|
| 984 | * This will be returned on a mmioGetHeader () call | 
|---|
| 985 | ************************************************************/ | 
|---|
| 986 | pJPGInfo->mmImgHdr = MMImgHdr; | 
|---|
| 987 |  | 
|---|
| 988 | return MMIO_SUCCESS; | 
|---|
| 989 |  | 
|---|
| 990 | } /* end case of MMIOM_OPEN */ | 
|---|
| 991 |  | 
|---|
| 992 | /*#############################################################*/ | 
|---|
| 993 | /*#############################################################*/ | 
|---|
| 994 | case MMIOM_QUERYHEADERLENGTH: | 
|---|
| 995 | { | 
|---|
| 996 | #ifdef DEBUG | 
|---|
| 997 | writeLog("MMIO_QUERYHEADERLENGTH\n"); | 
|---|
| 998 | #endif | 
|---|
| 999 | /************************************************************ | 
|---|
| 1000 | * If there is no MMIOINFO block then return an error. | 
|---|
| 1001 | ************************************************************/ | 
|---|
| 1002 | if (!pmmioinfo) | 
|---|
| 1003 | return (0); | 
|---|
| 1004 |  | 
|---|
| 1005 | /************************************************************ | 
|---|
| 1006 | * If header is in translated mode then return the media | 
|---|
| 1007 | * type specific structure size. | 
|---|
| 1008 | ************************************************************/ | 
|---|
| 1009 | if (pmmioinfo->ulTranslate & MMIO_TRANSLATEHEADER) | 
|---|
| 1010 | return (sizeof (MMIMAGEHEADER)); | 
|---|
| 1011 | else | 
|---|
| 1012 | /******************************************************** | 
|---|
| 1013 | * Header is not in translated mode so return the size | 
|---|
| 1014 | * of the MMotion header. | 
|---|
| 1015 | ********************************************************/ | 
|---|
| 1016 | /* Unstranslated headers not supported */ | 
|---|
| 1017 | /*!!!!!!!!!!!!!! FIXME !!!!!!!!!!!!!!!*/ | 
|---|
| 1018 | return 0; | 
|---|
| 1019 | } /* end case of MMIOM_QUERYHEADERLENGTH */ | 
|---|
| 1020 |  | 
|---|
| 1021 | /*#############################################################*/ | 
|---|
| 1022 | /*#############################################################*/ | 
|---|
| 1023 | case MMIOM_READ: | 
|---|
| 1024 | { | 
|---|
| 1025 |  | 
|---|
| 1026 | /************************************************************ | 
|---|
| 1027 | * Declare Local Variables | 
|---|
| 1028 | ************************************************************/ | 
|---|
| 1029 | PJPGFILESTATUS   pJPGInfo; | 
|---|
| 1030 | LONG            rc; | 
|---|
| 1031 | LONG            lBytesToRead; | 
|---|
| 1032 | GBM_ERR     rcGBM; | 
|---|
| 1033 |  | 
|---|
| 1034 | #ifdef DEBUG | 
|---|
| 1035 | writeLog("MMIO_READ\n"); | 
|---|
| 1036 | #endif | 
|---|
| 1037 |  | 
|---|
| 1038 | /************************************************************ | 
|---|
| 1039 | * Check for valid MMIOINFO block. | 
|---|
| 1040 | ************************************************************/ | 
|---|
| 1041 | if (!pmmioinfo) | 
|---|
| 1042 | return (MMIO_ERROR); | 
|---|
| 1043 |  | 
|---|
| 1044 | /************************************************************ | 
|---|
| 1045 | * Set up our working file status variable. | 
|---|
| 1046 | ************************************************************/ | 
|---|
| 1047 | pJPGInfo = (PJPGFILESTATUS)pmmioinfo->pExtraInfoStruct; | 
|---|
| 1048 |  | 
|---|
| 1049 | /************************************************************ | 
|---|
| 1050 | * Is Translate Data off? | 
|---|
| 1051 | ************************************************************/ | 
|---|
| 1052 | if (!(pmmioinfo->ulTranslate & MMIO_TRANSLATEDATA)) | 
|---|
| 1053 | { | 
|---|
| 1054 | int rc; | 
|---|
| 1055 | /******************************************************** | 
|---|
| 1056 | * Since no translation, provide exact number of bytes req | 
|---|
| 1057 | ********************************************************/ | 
|---|
| 1058 | if (!lParam1) | 
|---|
| 1059 | return (MMIO_ERROR); | 
|---|
| 1060 |  | 
|---|
| 1061 | /* I don't know the header size of JPEG files so I can't skip | 
|---|
| 1062 | to the image data in MMIO_SEEK. If I can't find the image data | 
|---|
| 1063 | I can't read untranslated... */ | 
|---|
| 1064 | return (MMIO_ERROR); | 
|---|
| 1065 | #if 0 | 
|---|
| 1066 | rc=gbm_io_read(pJPGInfo->fHandleGBM,(PVOID) lParam1, (ULONG) lParam2); | 
|---|
| 1067 |  | 
|---|
| 1068 | if(rc==-1) | 
|---|
| 1069 | return (MMIO_ERROR); | 
|---|
| 1070 |  | 
|---|
| 1071 | return (rc); | 
|---|
| 1072 | #endif | 
|---|
| 1073 | } | 
|---|
| 1074 |  | 
|---|
| 1075 | /************************************************************ | 
|---|
| 1076 | * Otherwise, Translate Data is on... | 
|---|
| 1077 | ************************************************************/ | 
|---|
| 1078 |  | 
|---|
| 1079 | /* Check if we already have read in the image data */ | 
|---|
| 1080 | if(!pJPGInfo->lpRGBBuf) { | 
|---|
| 1081 | /* No, so read the image now */ | 
|---|
| 1082 |  | 
|---|
| 1083 | #ifdef DEBUG | 
|---|
| 1084 | writeLog("MMIO_READ: reading image data.\n"); | 
|---|
| 1085 | #endif | 
|---|
| 1086 | if(readImageData(pJPGInfo)==MMIO_ERROR) | 
|---|
| 1087 | return MMIO_ERROR; | 
|---|
| 1088 | } | 
|---|
| 1089 |  | 
|---|
| 1090 | /************************************************************ | 
|---|
| 1091 | * Ensure we do NOT write more data out than is remaining | 
|---|
| 1092 | *    in the buffer.  The length of read was requested in | 
|---|
| 1093 | *    image bytes, so confirm that there are that many of | 
|---|
| 1094 | *    virtual bytes remaining. | 
|---|
| 1095 | ************************************************************/ | 
|---|
| 1096 | if ((ULONG)(pJPGInfo->lImgBytePos + lParam2) > | 
|---|
| 1097 | pJPGInfo->ulImgTotalBytes) | 
|---|
| 1098 | lBytesToRead = | 
|---|
| 1099 | pJPGInfo->ulImgTotalBytes - pJPGInfo->lImgBytePos; | 
|---|
| 1100 | else | 
|---|
| 1101 | lBytesToRead = (ULONG)lParam2; | 
|---|
| 1102 |  | 
|---|
| 1103 | /************************************************************ | 
|---|
| 1104 | * Perform this block on ALL reads.  The image data should | 
|---|
| 1105 | * be in the RGB buffer at this point, and can be handed | 
|---|
| 1106 | * to the application. | 
|---|
| 1107 | * | 
|---|
| 1108 | * Conveniently, the virtual image position is the same | 
|---|
| 1109 | *    as the RGB buffer position, since both are 24 bit-RGB | 
|---|
| 1110 | ************************************************************/ | 
|---|
| 1111 | memcpy ((PVOID)lParam1, | 
|---|
| 1112 | &(pJPGInfo->lpRGBBuf[pJPGInfo->lImgBytePos]), | 
|---|
| 1113 | lBytesToRead); | 
|---|
| 1114 |  | 
|---|
| 1115 | /************************************************************ | 
|---|
| 1116 | * Move RGB Buffer pointer forward by number of bytes read. | 
|---|
| 1117 | * The Img buffer pos is identical, since both are 24 bits | 
|---|
| 1118 | ************************************************************/ | 
|---|
| 1119 | pJPGInfo->lImgBytePos += lBytesToRead; | 
|---|
| 1120 |  | 
|---|
| 1121 | #ifdef DEBUG | 
|---|
| 1122 | writeLog("MMIO_READ: read %d bytes.\n", lBytesToRead); | 
|---|
| 1123 | #endif | 
|---|
| 1124 |  | 
|---|
| 1125 | return (lBytesToRead); | 
|---|
| 1126 | }   /* end case  of MMIOM_READ */ | 
|---|
| 1127 |  | 
|---|
| 1128 | /*#############################################################*/ | 
|---|
| 1129 | /*#############################################################*/ | 
|---|
| 1130 | case MMIOM_SEEK: | 
|---|
| 1131 | { | 
|---|
| 1132 |  | 
|---|
| 1133 | /************************************************************ | 
|---|
| 1134 | * Set up locals. | 
|---|
| 1135 | ************************************************************/ | 
|---|
| 1136 | PJPGFILESTATUS   pJPGInfo; | 
|---|
| 1137 | LONG            lNewFilePosition; | 
|---|
| 1138 | LONG            lPosDesired; | 
|---|
| 1139 | SHORT           sSeekMode; | 
|---|
| 1140 |  | 
|---|
| 1141 | #ifdef DEBUG | 
|---|
| 1142 | writeLog("MMIO_SEEK\n"); | 
|---|
| 1143 | #endif | 
|---|
| 1144 |  | 
|---|
| 1145 | /************************************************************ | 
|---|
| 1146 | * Check to make sure MMIOINFO block is valid. | 
|---|
| 1147 | ************************************************************/ | 
|---|
| 1148 | if (!pmmioinfo) | 
|---|
| 1149 | return (MMIO_ERROR); | 
|---|
| 1150 |  | 
|---|
| 1151 | /************************************************************ | 
|---|
| 1152 | * Set up our working file status variable. | 
|---|
| 1153 | ************************************************************/ | 
|---|
| 1154 | pJPGInfo = (PJPGFILESTATUS)pmmioinfo->pExtraInfoStruct; | 
|---|
| 1155 |  | 
|---|
| 1156 | lPosDesired = lParam1; | 
|---|
| 1157 | sSeekMode = (SHORT)lParam2; | 
|---|
| 1158 |  | 
|---|
| 1159 | /************************************************************ | 
|---|
| 1160 | * Is Translate Data on? | 
|---|
| 1161 | ************************************************************/ | 
|---|
| 1162 | if (pmmioinfo->ulTranslate & MMIO_TRANSLATEDATA) | 
|---|
| 1163 | { | 
|---|
| 1164 | /* Image data already read?? */ | 
|---|
| 1165 | if(!pJPGInfo->lpRGBBuf) { | 
|---|
| 1166 | /* No, so read the image now */ | 
|---|
| 1167 |  | 
|---|
| 1168 | #ifdef DEBUG | 
|---|
| 1169 | writeLog("MMIO_SEEK: reading image data.\n"); | 
|---|
| 1170 | #endif | 
|---|
| 1171 |  | 
|---|
| 1172 | if(readImageData(pJPGInfo)==MMIO_ERROR) | 
|---|
| 1173 | return MMIO_ERROR; | 
|---|
| 1174 | } | 
|---|
| 1175 |  | 
|---|
| 1176 | /******************************************************** | 
|---|
| 1177 | * Attempt to move the Image buffer pointer to the | 
|---|
| 1178 | *    desired location.  App sends SEEK requests in | 
|---|
| 1179 | *    positions relative to the image planes & bits/pel | 
|---|
| 1180 | * We must also convert this to RGB positions | 
|---|
| 1181 | ********************************************************/ | 
|---|
| 1182 | switch (sSeekMode) | 
|---|
| 1183 | { | 
|---|
| 1184 | case SEEK_SET: | 
|---|
| 1185 | { | 
|---|
| 1186 | lNewFilePosition = lPosDesired; | 
|---|
| 1187 | break; | 
|---|
| 1188 | } | 
|---|
| 1189 | case SEEK_CUR: | 
|---|
| 1190 | { | 
|---|
| 1191 | lNewFilePosition = pJPGInfo->lImgBytePos + lPosDesired; | 
|---|
| 1192 | break; | 
|---|
| 1193 | } | 
|---|
| 1194 | case SEEK_END: | 
|---|
| 1195 | { | 
|---|
| 1196 |  | 
|---|
| 1197 | lNewFilePosition = | 
|---|
| 1198 | pJPGInfo->ulImgTotalBytes += lPosDesired; | 
|---|
| 1199 | break; | 
|---|
| 1200 | } | 
|---|
| 1201 | default : | 
|---|
| 1202 | return (MMIO_ERROR); | 
|---|
| 1203 | } | 
|---|
| 1204 |  | 
|---|
| 1205 | /******************************************************** | 
|---|
| 1206 | * Make sure seek did not go before start of file. | 
|---|
| 1207 | * If so, then don't change anything, just return an error | 
|---|
| 1208 | ********************************************************/ | 
|---|
| 1209 | if (lNewFilePosition < 0) | 
|---|
| 1210 | { | 
|---|
| 1211 | return (MMIO_ERROR); | 
|---|
| 1212 | } | 
|---|
| 1213 |  | 
|---|
| 1214 | /******************************************************** | 
|---|
| 1215 | * Make sure seek did not go past the end of file. | 
|---|
| 1216 | ********************************************************/ | 
|---|
| 1217 | if (lNewFilePosition > (LONG)pJPGInfo->ulImgTotalBytes) | 
|---|
| 1218 | lNewFilePosition = pJPGInfo->ulImgTotalBytes; | 
|---|
| 1219 |  | 
|---|
| 1220 | pJPGInfo->lImgBytePos = lNewFilePosition; | 
|---|
| 1221 |  | 
|---|
| 1222 | return (pJPGInfo->lImgBytePos); | 
|---|
| 1223 | } | 
|---|
| 1224 |  | 
|---|
| 1225 | return (MMIO_ERROR); | 
|---|
| 1226 | }  /* end case of MMIOM_SEEK */ | 
|---|
| 1227 |  | 
|---|
| 1228 | /*#############################################################*/ | 
|---|
| 1229 | /*#############################################################*/ | 
|---|
| 1230 | case MMIOM_SETHEADER: | 
|---|
| 1231 | { | 
|---|
| 1232 | /************************************************************ | 
|---|
| 1233 | * Declare local variables. | 
|---|
| 1234 | ************************************************************/ | 
|---|
| 1235 | PMMIMAGEHEADER          pMMImgHdr; | 
|---|
| 1236 | PJPGFILESTATUS           pJPGInfo; | 
|---|
| 1237 | USHORT                  usNumColors; | 
|---|
| 1238 | ULONG                   ulImgBitsPerLine; | 
|---|
| 1239 | ULONG                   ulImgBytesPerLine; | 
|---|
| 1240 | ULONG                   ulBytesWritten; | 
|---|
| 1241 | ULONG                   ulWidth; | 
|---|
| 1242 | ULONG                   ul4PelWidth; | 
|---|
| 1243 | ULONG                   ulHeight; | 
|---|
| 1244 | USHORT                  usPlanes; | 
|---|
| 1245 | USHORT                  usBitCount; | 
|---|
| 1246 | USHORT                  usPadBytes; | 
|---|
| 1247 |  | 
|---|
| 1248 |  | 
|---|
| 1249 | #ifdef DEBUG | 
|---|
| 1250 | writeLog("MMIO_SETHEADER\n"); | 
|---|
| 1251 | #endif | 
|---|
| 1252 |  | 
|---|
| 1253 | /************************************************************ | 
|---|
| 1254 | * Check for valid MMIOINFO block. | 
|---|
| 1255 | ************************************************************/ | 
|---|
| 1256 | if (!pmmioinfo) | 
|---|
| 1257 | return (MMIO_ERROR); | 
|---|
| 1258 |  | 
|---|
| 1259 | /************************************************************ | 
|---|
| 1260 | * Set up our working variable MMFILESTATUS. | 
|---|
| 1261 | ************************************************************/ | 
|---|
| 1262 | pJPGInfo = (PJPGFILESTATUS) pmmioinfo->pExtraInfoStruct; | 
|---|
| 1263 |  | 
|---|
| 1264 |  | 
|---|
| 1265 | /************************************************************ | 
|---|
| 1266 | * Only allow this function if we are in WRITE mode | 
|---|
| 1267 | * And only if we have not already set the header | 
|---|
| 1268 | ************************************************************/ | 
|---|
| 1269 | if ((!(pmmioinfo->ulFlags & MMIO_WRITE)) || | 
|---|
| 1270 | (pJPGInfo->bSetHeader)) | 
|---|
| 1271 | return (0); | 
|---|
| 1272 |  | 
|---|
| 1273 | /******************************************************** | 
|---|
| 1274 | * Make sure lParam1 is a valid pointer | 
|---|
| 1275 | ********************************************************/ | 
|---|
| 1276 | if (!lParam1) | 
|---|
| 1277 | { | 
|---|
| 1278 | pmmioinfo->ulErrorRet = MMIOERR_INVALID_STRUCTURE; | 
|---|
| 1279 | return (0); | 
|---|
| 1280 | } | 
|---|
| 1281 |  | 
|---|
| 1282 | /************************************************************ | 
|---|
| 1283 | * Header is not in translated mode. | 
|---|
| 1284 | ************************************************************/ | 
|---|
| 1285 | if (!(pmmioinfo->ulTranslate & MMIO_TRANSLATEHEADER)) | 
|---|
| 1286 | { | 
|---|
| 1287 |  | 
|---|
| 1288 | /* We don't do untranslated writes */ | 
|---|
| 1289 | return (0);   /* 0 indicates error */ | 
|---|
| 1290 |  | 
|---|
| 1291 | }  /* end IF NOT TRANSLATED block */ | 
|---|
| 1292 |  | 
|---|
| 1293 | /************************************************************ | 
|---|
| 1294 | * Header is translated. | 
|---|
| 1295 | ************************************************************/ | 
|---|
| 1296 |  | 
|---|
| 1297 | /************************************************************ | 
|---|
| 1298 | * Create local pointer media specific structure. | 
|---|
| 1299 | ************************************************************/ | 
|---|
| 1300 | pMMImgHdr = (PMMIMAGEHEADER) lParam1; | 
|---|
| 1301 |  | 
|---|
| 1302 | /************************************************************ | 
|---|
| 1303 | * Check for validity of header contents supplied | 
|---|
| 1304 | ************************************************************ | 
|---|
| 1305 | *  --  Length must be that of the standard header | 
|---|
| 1306 | *  --  NO Compression | 
|---|
| 1307 | *      1 plane | 
|---|
| 1308 | *      24, 8, 4 or 1 bpp | 
|---|
| 1309 | ************************************************************/ | 
|---|
| 1310 | usBitCount = pMMImgHdr->mmXDIBHeader.BMPInfoHeader2.cBitCount; | 
|---|
| 1311 | if ((pMMImgHdr->mmXDIBHeader.BMPInfoHeader2.ulCompression != | 
|---|
| 1312 | BCA_UNCOMP) || | 
|---|
| 1313 | (pMMImgHdr->mmXDIBHeader.BMPInfoHeader2.cPlanes != 1) || | 
|---|
| 1314 | (! ((usBitCount == 24) || (usBitCount == 8) /*|| | 
|---|
| 1315 | (usBitCount == 4) || (usBitCount == 1)*/ )) /* JPEGs don't have 1 or 4 bpp */ | 
|---|
| 1316 | ) | 
|---|
| 1317 | { | 
|---|
| 1318 | pmmioinfo->ulErrorRet = MMIOERR_INVALID_STRUCTURE; | 
|---|
| 1319 | return (0); | 
|---|
| 1320 | } | 
|---|
| 1321 |  | 
|---|
| 1322 | if (lParam2 != sizeof (MMIMAGEHEADER)) | 
|---|
| 1323 | { | 
|---|
| 1324 | pmmioinfo->ulErrorRet = MMIOERR_INVALID_BUFFER_LENGTH; | 
|---|
| 1325 | return (0); | 
|---|
| 1326 | } | 
|---|
| 1327 |  | 
|---|
| 1328 | ulWidth  = pMMImgHdr->mmXDIBHeader.BMPInfoHeader2.cx; | 
|---|
| 1329 | ulHeight = pMMImgHdr->mmXDIBHeader.BMPInfoHeader2.cy; | 
|---|
| 1330 |  | 
|---|
| 1331 | /************************************************************ | 
|---|
| 1332 | * Complete GBM structure. | 
|---|
| 1333 | ************************************************************/ | 
|---|
| 1334 | pJPGInfo->gbm.w=ulWidth; | 
|---|
| 1335 | pJPGInfo->gbm.h=ulHeight; | 
|---|
| 1336 | pJPGInfo->gbm.bpp=usBitCount; | 
|---|
| 1337 |  | 
|---|
| 1338 | /* Discard any image buffer already allocated. But..., where should it | 
|---|
| 1339 | come from?!?? */ | 
|---|
| 1340 | if(pJPGInfo->lpRGBBuf) { | 
|---|
| 1341 | DosFreeMem(pJPGInfo->lpRGBBuf); | 
|---|
| 1342 | pJPGInfo->lpRGBBuf=NULLHANDLE; | 
|---|
| 1343 | } | 
|---|
| 1344 |  | 
|---|
| 1345 | pJPGInfo->ulRGBTotalBytes = ( ((pJPGInfo->gbm.w * pJPGInfo->gbm.bpp + 31)/32) * 4 ) | 
|---|
| 1346 | * pJPGInfo->gbm.h; | 
|---|
| 1347 | pJPGInfo->ulImgTotalBytes = pJPGInfo->ulRGBTotalBytes; | 
|---|
| 1348 |  | 
|---|
| 1349 | /******************************************************** | 
|---|
| 1350 | * Get space for full image buffer. | 
|---|
| 1351 | * This will be retained until the file is closed. | 
|---|
| 1352 | ********************************************************/ | 
|---|
| 1353 | if (DosAllocMem ((PPVOID) &(pJPGInfo->lpRGBBuf), | 
|---|
| 1354 | pJPGInfo->ulRGBTotalBytes, | 
|---|
| 1355 | fALLOC)) | 
|---|
| 1356 | { | 
|---|
| 1357 | #ifdef DEBUG | 
|---|
| 1358 | writeLog("MMIO_SETHEADER: no memory for image data.\n"); | 
|---|
| 1359 | #endif | 
|---|
| 1360 | return (MMIO_ERROR); | 
|---|
| 1361 | } | 
|---|
| 1362 |  | 
|---|
| 1363 | /************************************************************ | 
|---|
| 1364 | * Flag that MMIOM_SETHEADER has been done.  It can only | 
|---|
| 1365 | *    be done ONCE for a file.  All future attempts will | 
|---|
| 1366 | *    be flagged as errors. | 
|---|
| 1367 | ************************************************************/ | 
|---|
| 1368 | pJPGInfo->bSetHeader = TRUE; | 
|---|
| 1369 |  | 
|---|
| 1370 | /************************************************************ | 
|---|
| 1371 | * Create copy of MMIMAGEHEADER for future use. | 
|---|
| 1372 | ************************************************************/ | 
|---|
| 1373 | pJPGInfo->mmImgHdr = *pMMImgHdr; | 
|---|
| 1374 |  | 
|---|
| 1375 | /******************************************************** | 
|---|
| 1376 | * Set up initial pointer value within RGB buffer & image | 
|---|
| 1377 | ********************************************************/ | 
|---|
| 1378 | pJPGInfo->lImgBytePos = 0; | 
|---|
| 1379 |  | 
|---|
| 1380 | #ifdef DEBUG | 
|---|
| 1381 | writeLog("MMIO_SETHEADER done\n"); | 
|---|
| 1382 | #endif | 
|---|
| 1383 |  | 
|---|
| 1384 | return (sizeof (MMIMAGEHEADER)); | 
|---|
| 1385 | }  /* end case of MMIOM_SETHEADER */ | 
|---|
| 1386 |  | 
|---|
| 1387 | /*#############################################################*/ | 
|---|
| 1388 | /*#############################################################*/ | 
|---|
| 1389 | case MMIOM_WRITE: | 
|---|
| 1390 | { | 
|---|
| 1391 |  | 
|---|
| 1392 | /************************************************************ | 
|---|
| 1393 | * Declare Local Variables. | 
|---|
| 1394 | ************************************************************/ | 
|---|
| 1395 | PJPGFILESTATUS       pJPGInfo; | 
|---|
| 1396 | USHORT              usBitCount; | 
|---|
| 1397 | LONG                lBytesWritten; | 
|---|
| 1398 | ULONG               ulImgBytesToWrite; | 
|---|
| 1399 |  | 
|---|
| 1400 | #ifdef DEBUG | 
|---|
| 1401 | writeLog("MMIO_WRITE\n"); | 
|---|
| 1402 | #endif | 
|---|
| 1403 |  | 
|---|
| 1404 | /************************************************************ | 
|---|
| 1405 | * Check for valid MMIOINFO block. | 
|---|
| 1406 | ************************************************************/ | 
|---|
| 1407 | if (!pmmioinfo) | 
|---|
| 1408 | return (MMIO_ERROR); | 
|---|
| 1409 |  | 
|---|
| 1410 | /************************************************************ | 
|---|
| 1411 | * Set up our working variable JPGFILESTATUS. | 
|---|
| 1412 | ************************************************************/ | 
|---|
| 1413 | pJPGInfo = (PJPGFILESTATUS) pmmioinfo->pExtraInfoStruct; | 
|---|
| 1414 |  | 
|---|
| 1415 | /************************************************************ | 
|---|
| 1416 | * See if a SetHeader has been done on this file. | 
|---|
| 1417 | ************************************************************/ | 
|---|
| 1418 | if ((!pJPGInfo) || (!pJPGInfo->bSetHeader)) | 
|---|
| 1419 | { | 
|---|
| 1420 | return (MMIO_ERROR); | 
|---|
| 1421 | } | 
|---|
| 1422 |  | 
|---|
| 1423 | if (!(pmmioinfo->ulTranslate & MMIO_TRANSLATEDATA)) | 
|---|
| 1424 | { | 
|---|
| 1425 | /******************************************************** | 
|---|
| 1426 | * Translation is off, take amount of bytes sent and | 
|---|
| 1427 | * write to the file. | 
|---|
| 1428 | ******************************************************** | 
|---|
| 1429 | * Ensure that there is a data buffer to write from | 
|---|
| 1430 | ********************************************************/ | 
|---|
| 1431 | if (!lParam1) | 
|---|
| 1432 | return (MMIO_ERROR); | 
|---|
| 1433 |  | 
|---|
| 1434 | /* We don't do untranslated writes. We shouldn't come here because | 
|---|
| 1435 | the MMIO_OPEN call must fail because of the TRANSLATE flag */ | 
|---|
| 1436 | return (MMIO_ERROR); | 
|---|
| 1437 | #if 0 | 
|---|
| 1438 | lBytesWritten = mmioWrite (pVidInfo->hmmioSS, | 
|---|
| 1439 | (PVOID) lParam1, | 
|---|
| 1440 | (ULONG) lParam2); | 
|---|
| 1441 |  | 
|---|
| 1442 | return (lBytesWritten); | 
|---|
| 1443 | #endif | 
|---|
| 1444 | } | 
|---|
| 1445 |  | 
|---|
| 1446 | /************************************************************ | 
|---|
| 1447 | * Translation is on. | 
|---|
| 1448 | *************************************************************/ | 
|---|
| 1449 |  | 
|---|
| 1450 | #ifdef DEBUG | 
|---|
| 1451 | writeLog("MMIO_WRITE: pJPGInfo->lImgBytePos %d lParam2 %d pJPGInfo->ulImgTotalBytes: %d bytes\n", | 
|---|
| 1452 | pJPGInfo->lImgBytePos, lParam2, pJPGInfo->ulImgTotalBytes); | 
|---|
| 1453 | #endif | 
|---|
| 1454 |  | 
|---|
| 1455 | /************************************************************ | 
|---|
| 1456 | * Ensure we do not attempt to write past the end of the | 
|---|
| 1457 | *    buffer... | 
|---|
| 1458 | ************************************************************/ | 
|---|
| 1459 | if ((ULONG)(pJPGInfo->lImgBytePos + lParam2) > | 
|---|
| 1460 | pJPGInfo->ulImgTotalBytes) | 
|---|
| 1461 | ulImgBytesToWrite = | 
|---|
| 1462 | pJPGInfo->ulImgTotalBytes - pJPGInfo->lImgBytePos; | 
|---|
| 1463 | else { | 
|---|
| 1464 | ulImgBytesToWrite = (ULONG)lParam2; | 
|---|
| 1465 | } | 
|---|
| 1466 |  | 
|---|
| 1467 | #ifdef DEBUG | 
|---|
| 1468 | writeLog("MMIO_WRITE: ulImgBytesToWrite %d \n", ulImgBytesToWrite); | 
|---|
| 1469 | #endif | 
|---|
| 1470 |  | 
|---|
| 1471 | /************************************************************ | 
|---|
| 1472 | * Write the data into the image buffer.  It will be converted | 
|---|
| 1473 | *  when the file is closed.  This allows the | 
|---|
| 1474 | *   application to seek to arbitrary  positions within the | 
|---|
| 1475 | *   image in terms of the bits/pel, etc they are writing. | 
|---|
| 1476 | ************************************************************/ | 
|---|
| 1477 | memcpy (&(pJPGInfo->lpRGBBuf[pJPGInfo->lImgBytePos]), | 
|---|
| 1478 | (PVOID)lParam1, | 
|---|
| 1479 | ulImgBytesToWrite); | 
|---|
| 1480 |  | 
|---|
| 1481 | /* Update current position in the image buffer */ | 
|---|
| 1482 | pJPGInfo->lImgBytePos += ulImgBytesToWrite; | 
|---|
| 1483 | #ifdef DEBUG | 
|---|
| 1484 | writeLog("MMIO_WRITE: written %d bytes\n", ulImgBytesToWrite); | 
|---|
| 1485 | #endif | 
|---|
| 1486 | return (ulImgBytesToWrite); | 
|---|
| 1487 | }   /* end case of MMIOM_WRITE */ | 
|---|
| 1488 |  | 
|---|
| 1489 | /* | 
|---|
| 1490 | * If the IOProc has a child IOProc, then pass the message on to the Child, otherwise | 
|---|
| 1491 | * return Unsupported Message | 
|---|
| 1492 | */ | 
|---|
| 1493 | default: | 
|---|
| 1494 | { | 
|---|
| 1495 | /* | 
|---|
| 1496 | * Declare Local Variables. | 
|---|
| 1497 | */ | 
|---|
| 1498 | //             PMMFILESTATUS       pVidInfo; | 
|---|
| 1499 | LONG                lRC; | 
|---|
| 1500 |  | 
|---|
| 1501 | /************************************************************ | 
|---|
| 1502 | * Check for valid MMIOINFO block. | 
|---|
| 1503 | ************************************************************/ | 
|---|
| 1504 | if (!pmmioinfo) | 
|---|
| 1505 | return (MMIO_ERROR); | 
|---|
| 1506 |  | 
|---|
| 1507 | /* !!!!!!!!!!!! FIXME !!!!!!!!!!!!!*/ | 
|---|
| 1508 | return (MMIOERR_UNSUPPORTED_MESSAGE); | 
|---|
| 1509 | #if 0 | 
|---|
| 1510 | /************************************************************ | 
|---|
| 1511 | * Set up our working variable MMFILESTATUS. | 
|---|
| 1512 | ************************************************************/ | 
|---|
| 1513 | pVidInfo = (PMMFILESTATUS) pmmioinfo->pExtraInfoStruct; | 
|---|
| 1514 |  | 
|---|
| 1515 | if (pVidInfo != NULL && pVidInfo->hmmioSS) | 
|---|
| 1516 | { | 
|---|
| 1517 | lRC = mmioSendMessage (pVidInfo->hmmioSS, | 
|---|
| 1518 | usMsg, | 
|---|
| 1519 | lParam1, | 
|---|
| 1520 | lParam2); | 
|---|
| 1521 | if (!lRC) | 
|---|
| 1522 | pmmioinfo->ulErrorRet = mmioGetLastError (pVidInfo->hmmioSS); | 
|---|
| 1523 | return (lRC); | 
|---|
| 1524 | } | 
|---|
| 1525 | else | 
|---|
| 1526 | { | 
|---|
| 1527 | if (pmmioinfo != NULL) | 
|---|
| 1528 | pmmioinfo->ulErrorRet = MMIOERR_UNSUPPORTED_MESSAGE; | 
|---|
| 1529 | return (MMIOERR_UNSUPPORTED_MESSAGE); | 
|---|
| 1530 | } | 
|---|
| 1531 | #endif | 
|---|
| 1532 | }   /* end case of Default */ | 
|---|
| 1533 |  | 
|---|
| 1534 | } /* end SWITCH statement for MMIO messages */ | 
|---|
| 1535 |  | 
|---|
| 1536 | return (0); | 
|---|
| 1537 | }      /* end of window procedure */ | 
|---|